pytorch/torch/_export/serde
angelayi 5314a6fe82 [export] Fix deserialization issue (#150515)
An internal model was serialized in 2023, and is now breaking while loading with the following error:
```
  File "<eval_with_key>.1675", line 4
    def forward(self, arg1163_1, arg1164_1, , arg1166_1, , arg1168_1, arg1169_1, arg1170_1, , arg1172_1, arg1173_1, arg1174_1, arg1175_1, arg1176_1, arg1177_1, arg1178_1, arg1179_1, arg1180_1, arg1181_1, arg1182_1, arg1183_1, arg1184_1, arg1185_1, arg1186_1, arg1187_1, arg1188_1, arg1189_1, arg1190_1, arg1191_1, arg1192_1, arg1193_1, arg1194_1, arg1195_1, arg1196_1, arg1197_1, arg1198_1, arg1199_1, arg1200_1, arg1201_1, arg1202_1, arg1203_1, arg1204_1, arg1205_1, arg1206_1, arg1207_1, arg1208_1, arg1209_1, arg1210_1, arg1211_1, arg1212_1, arg1213_1, arg1214_1, arg1215_1, arg1216_1, , arg1218_1, arg1219_1, arg1220_1, arg1221_1, arg1222_1, arg1223_1, arg1224_1, , arg1226_1, arg1227_1, arg1228_1, , arg1230_1, , , , , , , , , , , , , , , ):
                                            ^
SyntaxError: invalid syntax
```

The syntax errors are due to inputs that are `None` when exporting. Prior to changes in https://github.com/pytorch/pytorch/pull/123590 (landed 4/2024), input specs for none inputs look like `InputSpec(userInput=UserInputSpec(arg=Argument(asNone=True)))`, and during deserialization when creating a node, we would just use a dummy name `arg`. After to those changes, the input specs for none inputs look like `InputSpec(constantInput=InputToConstantInputSpec(name='y', value=ConstantValue(asNone=True)))`, and when creating  a node we would use the name `y` as the name. However the PR didn't handle the case if it's loading an old package which doesn't have this name, so ended up putting empty names in the placeholder nodes.

This error was uncovered after https://github.com/pytorch/pytorch/pull/149717, where we now use the GraphModule's python codegen to run the UnflattenedModule instead of going through the interpreter path. The placeholder nodes having empty names caused the python codegen to fail.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/150515
Approved by: https://github.com/yushangdi
2025-04-03 15:27:45 +00:00
..
gen-cpp2 [export][ez] Fix forward D67044185 (#143193) 2024-12-13 16:06:42 +00:00
__init__.py
aoti_schema.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
dynamic_shapes.py [export] refactor _Dim into Dim (#149891) 2025-03-28 06:19:03 +00:00
export_schema.thrift [export] Sync aoti schema to schema.py (#148017) 2025-02-27 21:46:11 +00:00
schema_check.py Fix "invalid application of 'sizeof' to an incomplete type" (#148854) 2025-03-11 00:40:00 +00:00
schema.py [export] Sync aoti schema to schema.py (#148017) 2025-02-27 21:46:11 +00:00
schema.yaml [export] Sync aoti schema to schema.py (#148017) 2025-02-27 21:46:11 +00:00
serialize.py [export] Fix deserialization issue (#150515) 2025-04-03 15:27:45 +00:00
union.py [BE]: Enable ruff SLOT checks (#146276) 2025-02-04 19:18:23 +00:00