Repository navigation
Commit 6d7b17a
[export] Use bytecode to flatten graph inputs. (pytorch#171110)
Summary:
Previously for dynamo_graph_capture_for_export, we use make_fx() to trace through the dynamo bytecode so that the GraphModule looks like the following:
```
tree_leaves = pytree_flatten(*args)
graph_inputs = self.in_shuffle_graph(*tree_leaves)
graph_outputs = graph(*graph_inputs)
tree_outs = outputs = self.out_shuffle_graph(*graph_outputs)
return pytree.tree_unflatten(tree_outs)
```
After a bunch of experiments, we think the make_fx step is not necessaery, and to further close the gap between strict export and dynamo, we propose the new impl to do the following using torch.fx codegen:
```
graph_inputs = self._dynamo_bytecode_flatten(*args)
graph_outs = graph(*graph_inputs)
return self._dynamo_bytecode_unflatten(*graph_outs)
```
The `_dynamo_bytecode_flatten` and `_dynamo_bytecode_unflatten` wrappers are constructed in the way that the behavior will be 100% identical to directly running bytecode.
This is important for also making precompile reusing the same piece of logic that torch.export uses.
Test Plan: test:test_export -- -r _strict_export_v2
Differential Revision: D89673950
Pull Request resolved: pytorch#171110
Approved by: https://github.com/tugsbayasgalan1 parent 3bfdf85 commit 6d7b17a
5 files changed
Lines changed: 356 additions & 127 deletions
File tree
- test/export
- torch
- _dynamo
- export
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | 784 | | |
791 | 785 | | |
792 | 786 | | |
793 | 787 | | |
794 | | - | |
795 | | - | |
| 788 | + | |
| 789 | + | |
796 | 790 | | |
797 | 791 | | |
798 | 792 | | |
799 | | - | |
| 793 | + | |
800 | 794 | | |
801 | 795 | | |
802 | 796 | | |
| |||
818 | 812 | | |
819 | 813 | | |
820 | 814 | | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | 815 | | |
829 | 816 | | |
830 | 817 | | |
831 | 818 | | |
832 | | - | |
833 | | - | |
| 819 | + | |
| 820 | + | |
834 | 821 | | |
835 | 822 | | |
836 | 823 | | |
837 | 824 | | |
838 | 825 | | |
839 | 826 | | |
840 | | - | |
| 827 | + | |
841 | 828 | | |
842 | 829 | | |
843 | 830 | | |
| |||
916 | 903 | | |
917 | 904 | | |
918 | 905 | | |
919 | | - | |
920 | | - | |
| 906 | + | |
| 907 | + | |
921 | 908 | | |
922 | 909 | | |
923 | 910 | | |
924 | | - | |
| 911 | + | |
925 | 912 | | |
926 | 913 | | |
927 | 914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9778 | 9778 | | |
9779 | 9779 | | |
9780 | 9780 | | |
9781 | | - | |
9782 | 9781 | | |
9783 | 9782 | | |
9784 | 9783 | | |
| |||
10023 | 10022 | | |
10024 | 10023 | | |
10025 | 10024 | | |
10026 | | - | |
10027 | 10025 | | |
10028 | 10026 | | |
10029 | 10027 | | |
| |||
10343 | 10341 | | |
10344 | 10342 | | |
10345 | 10343 | | |
10346 | | - | |
10347 | 10344 | | |
10348 | 10345 | | |
10349 | 10346 | | |
| |||
16487 | 16484 | | |
16488 | 16485 | | |
16489 | 16486 | | |
16490 | | - | |
16491 | | - | |
16492 | | - | |
16493 | | - | |
16494 | | - | |
| 16487 | + | |
| 16488 | + | |
16495 | 16489 | | |
16496 | | - | |
| 16490 | + | |
16497 | 16491 | | |
16498 | 16492 | | |
16499 | 16493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
1106 | 1111 | | |
1107 | 1112 | | |
1108 | 1113 | | |
| |||
1114 | 1119 | | |
1115 | 1120 | | |
1116 | 1121 | | |
1117 | | - | |
| 1122 | + | |
| 1123 | + | |
1118 | 1124 | | |
1119 | 1125 | | |
1120 | 1126 | | |
| |||
0 commit comments