-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport.ir_spec.html
1442 lines (1259 loc) · 90.7 KB
/
export.ir_spec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>torch.export IR Specification — PyTorch 2.7 documentation</title>
<link rel="canonical" href="https://pytorch.org/docs/stable/export.ir_spec.html"/>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!-- <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> -->
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="_static/katex-math.css" type="text/css" />
<link rel="stylesheet" href="_static/sphinx-dropdown.css" type="text/css" />
<link rel="stylesheet" href="_static/panels-bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="_static/css/jit.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Writing Graph Transformations on ATen IR" href="torch.compiler_transformations.html" />
<link rel="prev" title="torch.export Programming Model" href="export.programming_model.html" />
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-T8XT4PS');</script>
<!-- End Google Tag Manager -->
<script src="_static/js/modernizr.min.js"></script>
<!-- Preload the theme fonts -->
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<!-- Preload the katex fonts -->
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.2/css/all.css" integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu" crossorigin="anonymous">
</head>
<div class="container-fluid header-holder tutorials-header" id="header-holder">
<div class="container">
<div class="header-container">
<a class="header-logo" href="https://pytorch.org/" aria-label="PyTorch"></a>
<div class="main-menu">
<ul>
<li class="main-menu-item">
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="with-down-arrow">
Learn
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/get-started">
<span class=dropdown-title>Get Started</span>
<p>Run PyTorch locally or get started quickly with one of the supported cloud platforms</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/tutorials">
<span class="dropdown-title">Tutorials</span>
<p>Whats new in PyTorch tutorials</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/tutorials/beginner/basics/intro.html">
<span class="dropdown-title">Learn the Basics</span>
<p>Familiarize yourself with PyTorch concepts and modules</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/tutorials/recipes/recipes_index.html">
<span class="dropdown-title">PyTorch Recipes</span>
<p>Bite-size, ready-to-deploy PyTorch code examples</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/tutorials/beginner/introyt.html">
<span class="dropdown-title">Intro to PyTorch - YouTube Series</span>
<p>Master PyTorch basics with our engaging YouTube tutorial series</p>
</a>
</div>
</div>
</li>
<li>
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="with-down-arrow">
Ecosystem
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/ecosystem">
<span class="dropdown-title">Tools</span>
<p>Learn about the tools and frameworks in the PyTorch Ecosystem</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/#community-module">
<span class=dropdown-title>Community</span>
<p>Join the PyTorch developer community to contribute, learn, and get your questions answered</p>
</a>
<a class="nav-dropdown-item" href="https://discuss.pytorch.org/" target="_blank">
<span class=dropdown-title>Forums</span>
<p>A place to discuss PyTorch code, issues, install, research</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/resources">
<span class=dropdown-title>Developer Resources</span>
<p>Find resources and get questions answered</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/ecosystem/contributor-awards-2024">
<span class="dropdown-title">Contributor Awards - 2024</span>
<p>Award winners announced at this year's PyTorch Conference</p>
</a>
</div>
</div>
</li>
<li>
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="with-down-arrow">
Edge
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/edge">
<span class="dropdown-title">About PyTorch Edge</span>
<p>Build innovative and privacy-aware AI experiences for edge devices</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/executorch-overview">
<span class="dropdown-title">ExecuTorch</span>
<p>End-to-end solution for enabling on-device inference capabilities across mobile and edge devices</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/executorch/stable/index.html">
<span class="dropdown-title">ExecuTorch Docs</span>
</a>
</div>
</div>
</li>
<li class="main-menu-item">
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="with-down-arrow">
Docs
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/docs/stable/index.html">
<span class="dropdown-title">PyTorch</span>
<p>Explore the documentation for comprehensive guidance on how to use PyTorch</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/pytorch-domains">
<span class="dropdown-title">PyTorch Domains</span>
<p>Read the PyTorch Domains documentation to learn more about domain-specific libraries</p>
</a>
</div>
</div>
</li>
<li>
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="with-down-arrow">
Blogs & News
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/blog/">
<span class="dropdown-title">PyTorch Blog</span>
<p>Catch up on the latest technical news and happenings</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/community-blog">
<span class="dropdown-title">Community Blog</span>
<p>Stories from the PyTorch ecosystem</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/videos">
<span class="dropdown-title">Videos</span>
<p>Learn about the latest PyTorch tutorials, new, and more </p>
<a class="nav-dropdown-item" href="https://pytorch.org/community-stories">
<span class="dropdown-title">Community Stories</span>
<p>Learn how our community solves real, everyday machine learning problems with PyTorch</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/events">
<span class="dropdown-title">Events</span>
<p>Find events, webinars, and podcasts</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/newsletter">
<span class="dropdown-title">Newsletter</span>
<p>Stay up-to-date with the latest updates</p>
</a>
</div>
</li>
<li>
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="with-down-arrow">
About
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/foundation">
<span class="dropdown-title">PyTorch Foundation</span>
<p>Learn more about the PyTorch Foundation</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/governing-board">
<span class="dropdown-title">Governing Board</span>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/credits">
<span class="dropdown-title">Cloud Credit Program</span>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/tac">
<span class="dropdown-title">Technical Advisory Council</span>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/staff">
<span class="dropdown-title">Staff</span>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/contact-us">
<span class="dropdown-title">Contact Us</span>
</a>
</div>
</div>
</li>
<li class="main-menu-item">
<div class="no-dropdown">
<a href="https://pytorch.org/join" data-cta="join">
Become a Member
</a>
</div>
</li>
<li>
<div class="main-menu-item">
<a href="https://github.com/pytorch/pytorch" class="github-icon">
</a>
</div>
</li>
<!--- TODO: This block adds the search icon to the nav bar. We will enable it later.
<li>
<div class="main-menu-item">
<a href="https://github.com/pytorch/pytorch" class="search-icon">
</a>
</div>
</li>
--->
</ul>
</div>
<a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a>
</div>
</div>
</div>
<body class="pytorch-body">
<div class="table-of-contents-link-wrapper">
<span>Table of Contents</span>
<a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
</div>
<nav data-toggle="wy-nav-shift" class="pytorch-left-menu" id="pytorch-left-menu">
<div class="pytorch-side-scroll">
<div class="pytorch-menu pytorch-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<div class="pytorch-left-menu-search">
<div class="version">
<a href='https://pytorch.org/docs/versions.html'>2.7 ▼</a>
</div>
<div id="searchBox">
<div class="searchbox" id="googleSearchBox">
<script async src="https://cse.google.com/cse.js?cx=e65585f8c3ea1440e"></script>
<div class="gcse-search"></div>
</div>
<div id="sphinxSearchBox" style="display: none;">
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search Docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
<form id="searchForm">
<label style="margin-bottom: 1rem">
<input type="radio" name="searchType" value="google" checked>
Google Search
</label>
<label style="margin-bottom: 1rem">
<input type="radio" name="searchType" value="sphinx">
Classic Search
</label>
</form>
<script>
document.addEventListener('DOMContentLoaded', function() {
const searchForm = document.getElementById('searchForm');
const googleSearchBox = document.getElementById('googleSearchBox');
const sphinxSearchBox = document.getElementById('sphinxSearchBox');
// Function to toggle search box visibility
function toggleSearchBox(searchType) {
googleSearchBox.style.display = searchType === 'google' ? 'block' : 'none';
sphinxSearchBox.style.display = searchType === 'sphinx' ? 'block' : 'none';
}
// Determine the default search type
let defaultSearchType;
const currentUrl = window.location.href;
if (currentUrl.startsWith('https://pytorch.org/docs/stable')) {
// For the stable documentation, default to Google
defaultSearchType = localStorage.getItem('searchType') || 'google';
} else {
// For any other version, including docs-preview, default to Sphinx
defaultSearchType = 'sphinx';
}
// Set the default search type
document.querySelector(`input[name="searchType"][value="${defaultSearchType}"]`).checked = true;
toggleSearchBox(defaultSearchType);
// Event listener for changes in search type
searchForm.addEventListener('change', function(event) {
const selectedSearchType = event.target.value;
localStorage.setItem('searchType', selectedSearchType);
toggleSearchBox(selectedSearchType);
});
// Set placeholder text for Google search box
window.onload = function() {
var placeholderText = "Search Docs";
var googleSearchboxText = document.querySelector("#gsc-i-id1");
if (googleSearchboxText) {
googleSearchboxText.placeholder = placeholderText;
googleSearchboxText.style.fontFamily = 'FreightSans';
googleSearchboxText.style.fontSize = "1.2rem";
googleSearchboxText.style.color = '#262626';
}
};
});
</script>
</div>
<p class="caption" role="heading"><span class="caption-text">Community</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="community/build_ci_governance.html">PyTorch Governance | Build + CI</a></li>
<li class="toctree-l1"><a class="reference internal" href="community/contribution_guide.html">PyTorch Contribution Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="community/design.html">PyTorch Design Philosophy</a></li>
<li class="toctree-l1"><a class="reference internal" href="community/governance.html">PyTorch Governance | Mechanics</a></li>
<li class="toctree-l1"><a class="reference internal" href="community/persons_of_interest.html">PyTorch Governance | Maintainers</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Developer Notes</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="notes/amp_examples.html">Automatic Mixed Precision examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/autograd.html">Autograd mechanics</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/broadcasting.html">Broadcasting semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/cpu_threading_torchscript_inference.html">CPU threading and TorchScript inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/cuda.html">CUDA semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/custom_operators.html">PyTorch Custom Operators Landing Page</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/ddp.html">Distributed Data Parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/extending.html">Extending PyTorch</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/extending.func.html">Extending torch.func with autograd.Function</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/fsdp.html">FSDP Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/get_start_xpu.html">Getting Started on Intel GPU</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/gradcheck.html">Gradcheck mechanics</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/hip.html">HIP (ROCm) semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/large_scale_deployments.html">Features for large-scale deployments</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/libtorch_stable_abi.html">LibTorch Stable ABI</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/modules.html">Modules</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/mps.html">MPS backend</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/multiprocessing.html">Multiprocessing best practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/numerical_accuracy.html">Numerical accuracy</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/randomness.html">Reproducibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/serialization.html">Serialization semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="notes/windows.html">Windows FAQ</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Language Bindings</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="cpp_index.html">C++</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/javadoc/">Javadoc</a></li>
<li class="toctree-l1"><a class="reference internal" href="deploy.html">torch::deploy</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="torch.html">torch</a></li>
<li class="toctree-l1"><a class="reference internal" href="nn.html">torch.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="nn.functional.html">torch.nn.functional</a></li>
<li class="toctree-l1"><a class="reference internal" href="tensors.html">torch.Tensor</a></li>
<li class="toctree-l1"><a class="reference internal" href="tensor_attributes.html">Tensor Attributes</a></li>
<li class="toctree-l1"><a class="reference internal" href="tensor_view.html">Tensor Views</a></li>
<li class="toctree-l1"><a class="reference internal" href="amp.html">torch.amp</a></li>
<li class="toctree-l1"><a class="reference internal" href="autograd.html">torch.autograd</a></li>
<li class="toctree-l1"><a class="reference internal" href="library.html">torch.library</a></li>
<li class="toctree-l1"><a class="reference internal" href="accelerator.html">torch.accelerator</a></li>
<li class="toctree-l1"><a class="reference internal" href="cpu.html">torch.cpu</a></li>
<li class="toctree-l1"><a class="reference internal" href="cuda.html">torch.cuda</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_cuda_memory.html">Understanding CUDA Memory Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_cuda_memory.html#generating-a-snapshot">Generating a Snapshot</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_cuda_memory.html#using-the-visualizer">Using the visualizer</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_cuda_memory.html#snapshot-api-reference">Snapshot API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="mps.html">torch.mps</a></li>
<li class="toctree-l1"><a class="reference internal" href="xpu.html">torch.xpu</a></li>
<li class="toctree-l1"><a class="reference internal" href="mtia.html">torch.mtia</a></li>
<li class="toctree-l1"><a class="reference internal" href="mtia.memory.html">torch.mtia.memory</a></li>
<li class="toctree-l1"><a class="reference internal" href="meta.html">Meta device</a></li>
<li class="toctree-l1"><a class="reference internal" href="backends.html">torch.backends</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="export.html">torch.export</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.html">torch.distributed</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.tensor.html">torch.distributed.tensor</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.algorithms.join.html">torch.distributed.algorithms.join</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.elastic.html">torch.distributed.elastic</a></li>
<li class="toctree-l1"><a class="reference internal" href="fsdp.html">torch.distributed.fsdp</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.fsdp.fully_shard.html">torch.distributed.fsdp.fully_shard</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.tensor.parallel.html">torch.distributed.tensor.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.optim.html">torch.distributed.optim</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.pipelining.html">torch.distributed.pipelining</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.checkpoint.html">torch.distributed.checkpoint</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributions.html">torch.distributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch.compiler.html">torch.compiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="fft.html">torch.fft</a></li>
<li class="toctree-l1"><a class="reference internal" href="func.html">torch.func</a></li>
<li class="toctree-l1"><a class="reference internal" href="futures.html">torch.futures</a></li>
<li class="toctree-l1"><a class="reference internal" href="fx.html">torch.fx</a></li>
<li class="toctree-l1"><a class="reference internal" href="fx.experimental.html">torch.fx.experimental</a></li>
<li class="toctree-l1"><a class="reference internal" href="hub.html">torch.hub</a></li>
<li class="toctree-l1"><a class="reference internal" href="jit.html">torch.jit</a></li>
<li class="toctree-l1"><a class="reference internal" href="linalg.html">torch.linalg</a></li>
<li class="toctree-l1"><a class="reference internal" href="monitor.html">torch.monitor</a></li>
<li class="toctree-l1"><a class="reference internal" href="signal.html">torch.signal</a></li>
<li class="toctree-l1"><a class="reference internal" href="special.html">torch.special</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch.overrides.html">torch.overrides</a></li>
<li class="toctree-l1"><a class="reference internal" href="package.html">torch.package</a></li>
<li class="toctree-l1"><a class="reference internal" href="profiler.html">torch.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="nn.init.html">torch.nn.init</a></li>
<li class="toctree-l1"><a class="reference internal" href="nn.attention.html">torch.nn.attention</a></li>
<li class="toctree-l1"><a class="reference internal" href="onnx.html">torch.onnx</a></li>
<li class="toctree-l1"><a class="reference internal" href="optim.html">torch.optim</a></li>
<li class="toctree-l1"><a class="reference internal" href="complex_numbers.html">Complex Numbers</a></li>
<li class="toctree-l1"><a class="reference internal" href="ddp_comm_hooks.html">DDP Communication Hooks</a></li>
<li class="toctree-l1"><a class="reference internal" href="quantization.html">Quantization</a></li>
<li class="toctree-l1"><a class="reference internal" href="rpc.html">Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="random.html">torch.random</a></li>
<li class="toctree-l1"><a class="reference internal" href="masked.html">torch.masked</a></li>
<li class="toctree-l1"><a class="reference internal" href="nested.html">torch.nested</a></li>
<li class="toctree-l1"><a class="reference internal" href="size.html">torch.Size</a></li>
<li class="toctree-l1"><a class="reference internal" href="sparse.html">torch.sparse</a></li>
<li class="toctree-l1"><a class="reference internal" href="storage.html">torch.Storage</a></li>
<li class="toctree-l1"><a class="reference internal" href="testing.html">torch.testing</a></li>
<li class="toctree-l1"><a class="reference internal" href="utils.html">torch.utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmark_utils.html">torch.utils.benchmark</a></li>
<li class="toctree-l1"><a class="reference internal" href="bottleneck.html">torch.utils.bottleneck</a></li>
<li class="toctree-l1"><a class="reference internal" href="checkpoint.html">torch.utils.checkpoint</a></li>
<li class="toctree-l1"><a class="reference internal" href="cpp_extension.html">torch.utils.cpp_extension</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">torch.utils.data</a></li>
<li class="toctree-l1"><a class="reference internal" href="deterministic.html">torch.utils.deterministic</a></li>
<li class="toctree-l1"><a class="reference internal" href="jit_utils.html">torch.utils.jit</a></li>
<li class="toctree-l1"><a class="reference internal" href="dlpack.html">torch.utils.dlpack</a></li>
<li class="toctree-l1"><a class="reference internal" href="mobile_optimizer.html">torch.utils.mobile_optimizer</a></li>
<li class="toctree-l1"><a class="reference internal" href="model_zoo.html">torch.utils.model_zoo</a></li>
<li class="toctree-l1"><a class="reference internal" href="tensorboard.html">torch.utils.tensorboard</a></li>
<li class="toctree-l1"><a class="reference internal" href="module_tracker.html">torch.utils.module_tracker</a></li>
<li class="toctree-l1"><a class="reference internal" href="type_info.html">Type Info</a></li>
<li class="toctree-l1"><a class="reference internal" href="named_tensor.html">Named Tensors</a></li>
<li class="toctree-l1"><a class="reference internal" href="name_inference.html">Named Tensors operator coverage</a></li>
<li class="toctree-l1"><a class="reference internal" href="config_mod.html">torch.__config__</a></li>
<li class="toctree-l1"><a class="reference internal" href="future_mod.html">torch.__future__</a></li>
<li class="toctree-l1"><a class="reference internal" href="logging.html">torch._logging</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_environment_variables.html">Torch Environment Variables</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Libraries</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/audio/stable">torchaudio</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/data">TorchData</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/torchrec">TorchRec</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/serve">TorchServe</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/text/stable">torchtext</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/vision/stable">torchvision</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/xla/">PyTorch on XLA Devices</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/ao">torchao</a></li>
</ul>
</div>
</div>
</nav>
<div class="pytorch-container">
<div class="pytorch-page-level-bar" id="pytorch-page-level-bar">
<div class="pytorch-breadcrumbs-wrapper">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="pytorch-breadcrumbs">
<li>
<a href="index.html">
Docs
</a> >
</li>
<li><a href="export.html">torch.export</a> ></li>
<li>torch.export IR Specification</li>
<li class="pytorch-breadcrumbs-aside">
<a href="_sources/export.ir_spec.rst.txt" rel="nofollow"><img src="_static/images/view-page-source-icon.svg"></a>
</li>
</ul>
</div>
</div>
<div class="pytorch-shortcuts-wrapper" id="pytorch-shortcuts-wrapper">
Shortcuts
</div>
</div>
<section data-toggle="wy-nav-shift" id="pytorch-content-wrap" class="pytorch-content-wrap">
<div class="pytorch-content-left">
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T8XT4PS"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<div class="rst-content">
<div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
<article itemprop="articleBody" id="pytorch-article" class="pytorch-article">
<div class="section" id="torch-export-ir-specification">
<span id="export-ir-spec"></span><h1>torch.export IR Specification<a class="headerlink" href="#torch-export-ir-specification" title="Permalink to this heading">¶</a></h1>
<p>Export IR is an intermediate representation (IR) for compilers, which bears
similarities to MLIR and TorchScript. It is specifically designed to express the
semantics of PyTorch programs. Export IR primarily represents computation in a
streamlined list of operations, with limited support for dynamism such as
control flows.</p>
<p>To create an Export IR graph, a frontend can be used that soundly captures a
PyTorch program via a trace-specializing mechanism. The resulting Export IR can
then be optimized and executed by a backend. This can be done today through
<a class="reference internal" href="export.html#torch.export.export" title="torch.export.export"><code class="xref py py-func docutils literal notranslate"><span class="pre">torch.export.export()</span></code></a>.</p>
<p>The key concepts that will be covered in this document include:</p>
<ul class="simple">
<li><p>ExportedProgram: the data structure containing the Export IR program</p></li>
<li><p>Graph: which consists of a list of nodes.</p></li>
<li><p>Nodes: which represents operations, control flow, and metadata stored on this node.</p></li>
<li><p>Values are produced and consumed by nodes.</p></li>
<li><p>Types are associated with values and nodes.</p></li>
<li><p>The size and memory layout of values are also defined.</p></li>
</ul>
<div class="section" id="assumptions">
<h2>Assumptions<a class="headerlink" href="#assumptions" title="Permalink to this heading">¶</a></h2>
<p>This doc assumes that the audience is sufficiently familiar with PyTorch,
specifically with <a class="reference internal" href="fx.html#module-torch.fx" title="torch.fx"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx</span></code></a> and its related toolings. Thus it will stop
describing contents present in <a class="reference internal" href="fx.html#module-torch.fx" title="torch.fx"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx</span></code></a> documentation and paper.</p>
</div>
<div class="section" id="what-is-export-ir">
<h2>What is Export IR<a class="headerlink" href="#what-is-export-ir" title="Permalink to this heading">¶</a></h2>
<p>Export IR is a graph-based intermediate representation IR of PyTorch programs.
Export IR is realized on top of <a class="reference internal" href="fx.html#torch.fx.Graph" title="torch.fx.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.Graph</span></code></a>. In other words, <strong>all
Export IR graphs are also valid FX graphs</strong>, and if interpreted using standard
FX semantics, Export IR can be interpreted soundly. One implication is that an
exported graph can be converted to a valid Python program via standard FX
codegen.</p>
<p>This documentation will primarily focus on highlighting areas where Export IR
differs from FX in terms of its strictness, while skipping parts where it shares
similarities with FX.</p>
</div>
<div class="section" id="exportedprogram">
<h2>ExportedProgram<a class="headerlink" href="#exportedprogram" title="Permalink to this heading">¶</a></h2>
<p>The top-level Export IR construct is an <a class="reference internal" href="export.html#torch.export.ExportedProgram" title="torch.export.ExportedProgram"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.export.ExportedProgram</span></code></a>
class. It bundles the computational graph of a PyTorch model (which is usually a
<a class="reference internal" href="generated/torch.nn.Module.html#torch.nn.Module" title="torch.nn.Module"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Module</span></code></a>) with the parameters or weights that this model
consumes.</p>
<p>Some notable attributes of the <a class="reference internal" href="export.html#torch.export.ExportedProgram" title="torch.export.ExportedProgram"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.export.ExportedProgram</span></code></a> class are:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">graph_module</span></code> (<a class="reference internal" href="fx.html#torch.fx.GraphModule" title="torch.fx.GraphModule"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.GraphModule</span></code></a>): Data structure containing
the flattened computational graph of the PyTorch model. The graph can be
directly accessed through <cite>ExportedProgram.graph</cite>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">graph_signature</span></code> (<a class="reference internal" href="export.html#torch.export.ExportGraphSignature" title="torch.export.ExportGraphSignature"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.export.ExportGraphSignature</span></code></a>): The graph
signature, which specifies the parameters and buffer names used and mutated
within the graph. Instead of storing parameters and buffers as attributes of
the graph, they are lifted as inputs to the graph. The graph_signature is
utilized to keep track of additional information on these parameters and
buffers.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">state_dict</span></code> (<code class="docutils literal notranslate"><span class="pre">Dict[str,</span> <span class="pre">Union[torch.Tensor,</span> <span class="pre">torch.nn.Parameter]]</span></code>): Data
structure containing the parameters and buffers.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">range_constraints</span></code> (<code class="docutils literal notranslate"><span class="pre">Dict[sympy.Symbol,</span> <span class="pre">RangeConstraint]</span></code>): For programs
that are exported with data dependent behavior, the metadata on each node will
contain symbolic shapes (which look like <code class="docutils literal notranslate"><span class="pre">s0</span></code>, <code class="docutils literal notranslate"><span class="pre">i0</span></code>). This attribute maps
the symbolic shapes to their lower/upper ranges.</p></li>
</ul>
</div>
<div class="section" id="graph">
<h2>Graph<a class="headerlink" href="#graph" title="Permalink to this heading">¶</a></h2>
<p>An Export IR Graph is a PyTorch program represented in the form of a DAG
(directed acyclic graph). Each node in this graph represents a particular
computation or operation, and edges of this graph consist of references between
nodes.</p>
<p>We can view Graph having this schema:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Graph</span><span class="p">:</span>
<span class="n">nodes</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span>
</pre></div>
</div>
<p>In practice, Export IR’s graph is realized as <a class="reference internal" href="fx.html#torch.fx.Graph" title="torch.fx.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.Graph</span></code></a> Python class.</p>
<p>An Export IR graph contains the following nodes (Nodes will be described in more
details in the next section):</p>
<ul class="simple">
<li><p>0 or more nodes of op type <code class="docutils literal notranslate"><span class="pre">placeholder</span></code></p></li>
<li><p>0 or more nodes of op type <code class="docutils literal notranslate"><span class="pre">call_function</span></code></p></li>
<li><p>exactly 1 node of op type <code class="docutils literal notranslate"><span class="pre">output</span></code></p></li>
</ul>
<p><strong>Collorary:</strong> The smallest valid Graph will be of one node. i.e. nodes is never empty.</p>
<p><strong>Definition:</strong>
The set of <code class="docutils literal notranslate"><span class="pre">placeholder</span></code> nodes of a Graph represents the <strong>inputs</strong> of the
Graph of GraphModule. The <cite>output</cite> node of a Graph represents the <strong>outputs</strong>
of the Graph of GraphModule.</p>
<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">torch</span>
<span class="kn">from</span> <span class="nn">torch</span> <span class="kn">import</span> <span class="n">nn</span>
<span class="k">class</span> <span class="nc">MyModule</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
<span class="k">return</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span>
<span class="n">example_args</span> <span class="o">=</span> <span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">torch</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="n">mod</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">export</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="n">MyModule</span><span class="p">(),</span> <span class="n">example_args</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">mod</span><span class="o">.</span><span class="n">graph</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span><span class="p">():</span>
<span class="o">%</span><span class="n">x</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">placeholder</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">x</span><span class="p">]</span>
<span class="o">%</span><span class="n">y</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">placeholder</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">y</span><span class="p">]</span>
<span class="o">%</span><span class="n">add</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">call_function</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">aten</span><span class="o">.</span><span class="n">add</span><span class="o">.</span><span class="n">Tensor</span><span class="p">](</span><span class="n">args</span> <span class="o">=</span> <span class="p">(</span><span class="o">%</span><span class="n">x</span><span class="p">,</span> <span class="o">%</span><span class="n">y</span><span class="p">),</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{})</span>
<span class="k">return</span> <span class="p">(</span><span class="n">add</span><span class="p">,)</span>
</pre></div>
</div>
<p>The above is the textual representation of a Graph, with each line being a node.</p>
</div>
<div class="section" id="node">
<h2>Node<a class="headerlink" href="#node" title="Permalink to this heading">¶</a></h2>
<p>A Node represents a particular computation or operation and is represented in
Python using the <a class="reference internal" href="fx.html#torch.fx.Node" title="torch.fx.Node"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.Node</span></code></a> class. Edges between nodes are
represented as direct references to other nodes via the <code class="docutils literal notranslate"><span class="pre">args</span></code> property of the
Node class. Using the same FX machinery, we can represent the following
operations that a computational graph typically needs, such as operator calls,
placeholders (aka inputs), conditionals, and loops.</p>
<p>The Node has the following schema:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Node</span><span class="p">:</span>
<span class="n">name</span><span class="p">:</span> <span class="nb">str</span> <span class="c1"># name of node</span>
<span class="n">op_name</span><span class="p">:</span> <span class="nb">str</span> <span class="c1"># type of operation</span>
<span class="c1"># interpretation of the fields below depends on op_name</span>
<span class="n">target</span><span class="p">:</span> <span class="p">[</span><span class="nb">str</span><span class="o">|</span><span class="n">Callable</span><span class="p">]</span>
<span class="n">args</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">object</span><span class="p">]</span>
<span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">object</span><span class="p">]</span>
<span class="n">meta</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">object</span><span class="p">]</span>
</pre></div>
</div>
<p><strong>FX Text Format</strong></p>
<p>As in the example above, notice that each line has this format:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>%<name>:[...] = <op_name>[target=<target>](args = (%arg1, %arg2, arg3, arg4, …)), kwargs = {"keyword": arg5})
</pre></div>
</div>
<p>This format captures everything present in the Node class, with the exception of
<code class="docutils literal notranslate"><span class="pre">meta</span></code>, in a compact format.</p>
<p>Concretely:</p>
<ul class="simple">
<li><p><strong><name></strong> is the name of the node as it would appear in <code class="docutils literal notranslate"><span class="pre">node.name</span></code>.</p></li>
<li><p><strong><op_name></strong> is the <code class="docutils literal notranslate"><span class="pre">node.op</span></code> field, which must be one of these:
<cite><call_function></cite>, <cite><placeholder></cite>,
<cite><get_attr></cite>, or <cite><output></cite>.</p></li>
<li><p><strong><target></strong> is the target of the node as <code class="docutils literal notranslate"><span class="pre">node.target</span></code>. The meaning of this
field depends on <code class="docutils literal notranslate"><span class="pre">op_name</span></code>.</p></li>
<li><p><strong>args1, … args 4…</strong> are what is listed in the <code class="docutils literal notranslate"><span class="pre">node.args</span></code> tuple. If a
value in the list is an <a class="reference internal" href="fx.html#torch.fx.Node" title="torch.fx.Node"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.Node</span></code></a>, then it will be especially
indicated with a leading <strong>%.</strong></p></li>
</ul>
<p>For example, a call to the add operator would appear as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">%</span><span class="n">add1</span> <span class="o">=</span> <span class="n">call_function</span><span class="p">[</span><span class="n">target</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">op</span><span class="o">.</span><span class="n">aten</span><span class="o">.</span><span class="n">add</span><span class="o">.</span><span class="n">Tensor</span><span class="p">](</span><span class="n">args</span> <span class="o">=</span> <span class="p">(</span><span class="o">%</span><span class="n">x</span><span class="p">,</span> <span class="o">%</span><span class="n">y</span><span class="p">),</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{})</span>
</pre></div>
</div>
<p>Where <code class="docutils literal notranslate"><span class="pre">%x</span></code>, <code class="docutils literal notranslate"><span class="pre">%y</span></code> are two other Nodes that have names x and y. Worth noting
that the string <code class="docutils literal notranslate"><span class="pre">torch.op.aten.add.Tensor</span></code> represents the callable object that
is actually stored in the target field, not merely its string name.</p>
<p>The final line of this text format is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">return</span> <span class="p">[</span><span class="n">add</span><span class="p">]</span>
</pre></div>
</div>
<p>which is a Node with <code class="docutils literal notranslate"><span class="pre">op_name</span> <span class="pre">=</span> <span class="pre">output</span></code>, indicating that we are returning this
one element.</p>
<div class="section" id="call-function">
<h3>call_function<a class="headerlink" href="#call-function" title="Permalink to this heading">¶</a></h3>
<p>A <code class="docutils literal notranslate"><span class="pre">call_function</span></code> node represents a call to an operator.</p>
<p><strong>Definitions</strong></p>
<ul class="simple">
<li><p><strong>Functional:</strong> We say a callable is “functional” if it satisfies all the
following requirements:</p>
<ul>
<li><p>Non-mutating: The operator does not mutate the value of its input (for
tensors, this includes both metadata and data).</p></li>
<li><p>No side effects: The operator does not mutate states that are visible
from outside, like changing values of module parameters.</p></li>
</ul>
</li>
<li><p><strong>Operator:</strong> is a functional callable with a predefined schema. Examples of
such operators include functional ATen operators.</p></li>
</ul>
<p><strong>Representation in FX</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>%name = call_function[target = operator](args = (%x, %y, …), kwargs = {})
</pre></div>
</div>
<p><strong>Differences from vanilla FX call_function</strong></p>
<ol class="arabic simple">
<li><p>In FX graph, a call_function can refer to any callable, in Export IR, we
restrict it to only a select subset of ATen operators, custom operators, and
control flow operators.</p></li>
<li><p>In Export IR, constant arguments will be embedded within the graph.</p></li>
<li><p>In FX graph, a get_attr node can represent reading any attribute stored in
the graph module. However, in Export IR this is restricted to reading only
submodules as all parameters/buffers will be passed in as inputs to the graph
module.</p></li>
</ol>
<div class="section" id="metadata">
<h4>Metadata<a class="headerlink" href="#metadata" title="Permalink to this heading">¶</a></h4>
<p><code class="docutils literal notranslate"><span class="pre">Node.meta</span></code> is a dict attached to every FX node. However, the FX spec does not
specify what metadata can or will be there. Export IR provides a stronger
contract, specifically all <code class="docutils literal notranslate"><span class="pre">call_function</span></code> nodes will guarantee having and
only having the following metadata fields:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">node.meta["stack_trace"]</span></code> is a string containing the Python stack trace
referencing the original Python source code. An example stack trace looks
like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">File</span> <span class="s2">"my_module.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">19</span><span class="p">,</span> <span class="ow">in</span> <span class="n">forward</span>
<span class="k">return</span> <span class="n">x</span> <span class="o">+</span> <span class="n">dummy_helper</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="n">File</span> <span class="s2">"helper_utility.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">89</span><span class="p">,</span> <span class="ow">in</span> <span class="n">dummy_helper</span>
<span class="k">return</span> <span class="n">y</span> <span class="o">+</span> <span class="mi">1</span>
</pre></div>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">node.meta["val"]</span></code> describes the output of running the operation. It can be
of type <cite><symint></cite>, <cite><FakeTensor></cite>, a
<code class="docutils literal notranslate"><span class="pre">List[Union[FakeTensor,</span> <span class="pre">SymInt]]</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">node.meta["nn_module_stack"]</span></code> describes the “stacktrace” of the
<a class="reference internal" href="generated/torch.nn.Module.html#torch.nn.Module" title="torch.nn.Module"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Module</span></code></a> from which the node came, if it was from a
<a class="reference internal" href="generated/torch.nn.Module.html#torch.nn.Module" title="torch.nn.Module"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Module</span></code></a> call. For example, if a node containing the <code class="docutils literal notranslate"><span class="pre">addmm</span></code>
op called from a <a class="reference internal" href="generated/torch.nn.Linear.html#torch.nn.Linear" title="torch.nn.Linear"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Linear</span></code></a> module inside of a
<a class="reference internal" href="generated/torch.nn.Sequential.html#torch.nn.Sequential" title="torch.nn.Sequential"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code></a> module, the <code class="docutils literal notranslate"><span class="pre">nn_module_stack</span></code> would look
something like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>{'self_linear': ('self.linear', <class 'torch.nn.Linear'>), 'self_sequential': ('self.sequential', <class 'torch.nn.Sequential'>)}
</pre></div>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">node.meta["source_fn_stack"]</span></code> contains the torch function or the leaf
<a class="reference internal" href="generated/torch.nn.Module.html#torch.nn.Module" title="torch.nn.Module"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Module</span></code></a> class this node was called from before decomposition.
For example, a node containing the <code class="docutils literal notranslate"><span class="pre">addmm</span></code> op from a
<a class="reference internal" href="generated/torch.nn.Linear.html#torch.nn.Linear" title="torch.nn.Linear"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Linear</span></code></a> module call would contain <a class="reference internal" href="generated/torch.nn.Linear.html#torch.nn.Linear" title="torch.nn.Linear"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.Linear</span></code></a> in
their <code class="docutils literal notranslate"><span class="pre">source_fn</span></code>, and a node containing the <code class="docutils literal notranslate"><span class="pre">addmm</span></code> op from a
<code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.functional.Linear</span></code> module call would contain
<code class="xref py py-class docutils literal notranslate"><span class="pre">torch.nn.functional.Linear</span></code> in their <code class="docutils literal notranslate"><span class="pre">source_fn</span></code>.</p></li>
</ul>
</div>
</div>
<div class="section" id="placeholder">
<h3>placeholder<a class="headerlink" href="#placeholder" title="Permalink to this heading">¶</a></h3>
<p>Placeholder represents an input to a graph. Its semantics are exactly the same as in FX.
Placeholder nodes must be the first N nodes in the nodes list of a graph. N can be zero.</p>
<p><strong>Representation in FX</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="o">%</span><span class="n">name</span> <span class="o">=</span> <span class="n">placeholder</span><span class="p">[</span><span class="n">target</span> <span class="o">=</span> <span class="n">name</span><span class="p">](</span><span class="n">args</span> <span class="o">=</span> <span class="p">())</span>
</pre></div>
</div>
<p>The target field is a string which is the name of input.</p>
<p><code class="docutils literal notranslate"><span class="pre">args</span></code>, if non-empty, should be of size 1 representing the default value of this input.</p>
<p><strong>Metadata</strong></p>
<p>Placeholder nodes also have <code class="docutils literal notranslate"><span class="pre">meta[‘val’]</span></code>, like <code class="docutils literal notranslate"><span class="pre">call_function</span></code> nodes. The
<code class="docutils literal notranslate"><span class="pre">val</span></code> field in this case represents the input shape/dtype that the graph is
expected to receive for this input parameter.</p>
</div>
<div class="section" id="output">
<h3>output<a class="headerlink" href="#output" title="Permalink to this heading">¶</a></h3>
<p>An output call represents a return statement in a function; it thus terminates the
current graph. There is one and only one output node, and it will always be the
last node of the graph.</p>
<p><strong>Representation in FX</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>output[](args = (%something, …))
</pre></div>
</div>
<p>This has the exact semantics as in <a class="reference internal" href="fx.html#module-torch.fx" title="torch.fx"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx</span></code></a>. <code class="docutils literal notranslate"><span class="pre">args</span></code> represents the node
to be returned.</p>
<p><strong>Metadata</strong></p>
<p>Output node has the same metadata as <code class="docutils literal notranslate"><span class="pre">call_function</span></code> nodes.</p>
</div>
<div class="section" id="get-attr">
<h3>get_attr<a class="headerlink" href="#get-attr" title="Permalink to this heading">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">get_attr</span></code> nodes represent reading a submodule from the encapsulating
<a class="reference internal" href="fx.html#torch.fx.GraphModule" title="torch.fx.GraphModule"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.GraphModule</span></code></a>. Unlike a vanilla FX graph from
<a class="reference internal" href="fx.html#torch.fx.symbolic_trace" title="torch.fx.symbolic_trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">torch.fx.symbolic_trace()</span></code></a> in which <code class="docutils literal notranslate"><span class="pre">get_attr</span></code> nodes are used to read
attributes such as parameters and buffers from the top-level
<a class="reference internal" href="fx.html#torch.fx.GraphModule" title="torch.fx.GraphModule"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.fx.GraphModule</span></code></a>, parameters and buffers are passed in as
inputs to the graph module, and stored in the top-level
<a class="reference internal" href="export.html#torch.export.ExportedProgram" title="torch.export.ExportedProgram"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.export.ExportedProgram</span></code></a>.</p>
<p><strong>Representation in FX</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="o">%</span><span class="n">name</span> <span class="o">=</span> <span class="n">get_attr</span><span class="p">[</span><span class="n">target</span> <span class="o">=</span> <span class="n">name</span><span class="p">](</span><span class="n">args</span> <span class="o">=</span> <span class="p">())</span>
</pre></div>
</div>
<p><strong>Example</strong></p>
<p>Consider the following model:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">functorch.experimental.control_flow</span> <span class="kn">import</span> <span class="n">cond</span>
<span class="k">def</span> <span class="nf">true_fn</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">return</span> <span class="n">x</span><span class="o">.</span><span class="n">sin</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">false_fn</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">return</span> <span class="n">x</span><span class="o">.</span><span class="n">cos</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
<span class="k">return</span> <span class="n">cond</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">true_fn</span><span class="p">,</span> <span class="n">false_fn</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">])</span>
</pre></div>
</div>
<p>Graph:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span><span class="p">():</span>
<span class="o">%</span><span class="n">x_1</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">placeholder</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">x_1</span><span class="p">]</span>
<span class="o">%</span><span class="n">y_1</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">placeholder</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">y_1</span><span class="p">]</span>
<span class="o">%</span><span class="n">true_graph_0</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_attr</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">true_graph_0</span><span class="p">]</span>
<span class="o">%</span><span class="n">false_graph_0</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_attr</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">false_graph_0</span><span class="p">]</span>
<span class="o">%</span><span class="n">conditional</span> <span class="p">:</span> <span class="p">[</span><span class="n">num_users</span><span class="o">=</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">call_function</span><span class="p">[</span><span class="n">target</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">higher_order</span><span class="o">.</span><span class="n">cond</span><span class="p">](</span><span class="n">args</span> <span class="o">=</span> <span class="p">(</span><span class="o">%</span><span class="n">y_1</span><span class="p">,</span> <span class="o">%</span><span class="n">true_graph_0</span><span class="p">,</span> <span class="o">%</span><span class="n">false_graph_0</span><span class="p">,</span> <span class="p">[</span><span class="o">%</span><span class="n">x_1</span><span class="p">]),</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{})</span>
<span class="k">return</span> <span class="n">conditional</span>
</pre></div>
</div>
<p>The line, <code class="docutils literal notranslate"><span class="pre">%true_graph_0</span> <span class="pre">:</span> <span class="pre">[num_users=1]</span> <span class="pre">=</span> <span class="pre">get_attr[target=true_graph_0]</span></code>,
reads the submodule <code class="docutils literal notranslate"><span class="pre">true_graph_0</span></code> which contains the <code class="docutils literal notranslate"><span class="pre">sin</span></code> operator.</p>
</div>
</div>
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this heading">¶</a></h2>
<div class="section" id="symint">
<h3>SymInt<a class="headerlink" href="#symint" title="Permalink to this heading">¶</a></h3>
<p>A SymInt is an object that can either be a literal integer or a symbol that represents
an Integer (represented in Python by <code class="docutils literal notranslate"><span class="pre">sympy.Symbol</span></code> class). When SymInt is a
symbol, it describes a variable of type integer that is unknown to the graph at
compile time, that is, its value is only known at runtime.</p>
</div>
<div class="section" id="faketensor">
<h3>FakeTensor<a class="headerlink" href="#faketensor" title="Permalink to this heading">¶</a></h3>
<p>A FakeTensor is an object that contains the metadata of a tensor. It can be
viewed as having the following metadata.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">FakeTensor</span><span class="p">:</span>
<span class="n">size</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">SymInt</span><span class="p">]</span>
<span class="n">dtype</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">dtype</span>
<span class="n">device</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">device</span>
<span class="n">dim_order</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="c1"># This doesn't exist yet</span>
</pre></div>
</div>
<p>The size field of FakeTensor is a list of integers or SymInts. If SymInts are
present, this means this tensor has a dynamic shape. If integers are present, it
is assumed that the tensor will have that exact static shape. The rank of the
TensorMeta is never dynamic. The dtype field represents the dtype of the
output of that node. There are no implicit type promotions in Edge IR. There
are no strides in FakeTensor.</p>
<p>In other words:</p>
<ul class="simple">
<li><p>If the operator in node.target returns a Tensor, then <code class="docutils literal notranslate"><span class="pre">node.meta['val']</span></code> is a
FakeTensor describing that tensor.</p></li>
<li><p>If the operator in node.target returns an n-tuple of Tensors, then
<code class="docutils literal notranslate"><span class="pre">node.meta['val']</span></code> is an n-tuple of FakeTensors describing each tensor.</p></li>
<li><p>If the operator in node.target returns an int/float/scalar that is known at
compile time, then <code class="docutils literal notranslate"><span class="pre">node.meta['val']</span></code> is None.</p></li>
<li><p>If the operator in node.target returns an int/float/scalar that is not known
at compile time, then <code class="docutils literal notranslate"><span class="pre">node.meta['val']</span></code> is of type SymInt.</p></li>
</ul>
<p>For example:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">aten::add</span></code> returns a Tensor; so its spec will be a FakeTensor with dtype
and size of the tensor returned by this operator.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">aten::sym_size</span></code> returns an integer; so its val will be a SymInt because its
value is only available at runtime.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">max_pool2d_with_indexes</span></code> returns a tuple of (Tensor, Tensor); so the spec
will also be a 2-tuple of FakeTensor objects, the first TensorMeta describes
the first element of the return value etc.</p></li>
</ul>
<p>Python code:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">add_one</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">return</span> <span class="n">torch</span><span class="o">.</span><span class="n">ops</span><span class="o">.</span><span class="n">aten</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>Graph:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span><span class="p">():</span>
<span class="o">%</span><span class="n">ph_0</span> <span class="p">:</span> <span class="p">[</span><span class="c1">#users=1] = placeholder[target=ph_0]</span>
<span class="o">%</span><span class="n">add_tensor</span> <span class="p">:</span> <span class="p">[</span><span class="c1">#users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%ph_0, 1), kwargs = {})</span>
<span class="k">return</span> <span class="p">[</span><span class="n">add_tensor</span><span class="p">]</span>
</pre></div>
</div>
<p>FakeTensor:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FakeTensor</span><span class="p">(</span><span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">int</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,],</span> <span class="n">device</span><span class="o">=</span><span class="n">CPU</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="pytree-able-types">
<h3>Pytree-able Types<a class="headerlink" href="#pytree-able-types" title="Permalink to this heading">¶</a></h3>
<p>We define a type “Pytree-able”, if it is either a leaf type or a container type
that contains other Pytree-able types.</p>
<p>Note:</p>
<blockquote>
<div><p>The concept of pytree is the same as the one documented
<a class="reference external" href="https://jax.readthedocs.io/en/latest/pytrees.html">here</a> for JAX:</p>
</div></blockquote>
<p>The following types are defined as <strong>leaf type</strong>:</p>
<table class="colwidths-given docutils colwidths-auto align-default">
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Type</p></th>
<th class="head"><p>Definition</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Tensor</p></td>
<td><p><a class="reference internal" href="tensors.html#torch.Tensor" title="torch.Tensor"><code class="xref py py-class docutils literal notranslate"><span class="pre">torch.Tensor</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p>Scalar</p></td>
<td><p>Any numerical types from Python, including integral types, floating point types, and zero dimensional tensors.</p></td>
</tr>
<tr class="row-even"><td><p>int</p></td>
<td><p>Python int (bound as int64_t in C++)</p></td>
</tr>
<tr class="row-odd"><td><p>float</p></td>
<td><p>Python float (bound as double in C++)</p></td>
</tr>
<tr class="row-even"><td><p>bool</p></td>
<td><p>Python bool</p></td>
</tr>
<tr class="row-odd"><td><p>str</p></td>
<td><p>Python string</p></td>