[ez][export] Better error message for schema check in torch.export.load (#156361)

Summary:
Fixes https://github.com/pytorch/pytorch/issues/156354

torch.export.load() only supports files generated by torch.export.save()

Test Plan:
CI

Rollback Plan:

Differential Revision: D76928725

Pull Request resolved: https://github.com/pytorch/pytorch/pull/156361
Approved by: https://github.com/zhxchen17
This commit is contained in:
Yiming Zhou
2025-06-19 04:50:52 +00:00
committed by PyTorch MergeBot
parent 3f69e3b3a0
commit a21806f038

View File

@ -475,7 +475,9 @@ def load(
SCHEMA_VERSION, # todo change archive version to schema version
)
assert len(version) == len(SCHEMA_VERSION)
assert len(version) == len(SCHEMA_VERSION), (
"Version in the saved file has incorrect length, double check if the file is generated by torch.export.save()"
)
if version[0] != str(SCHEMA_VERSION[0]):
raise RuntimeError(
f"Serialized version {version} does not match our current "