Skip to content

Commit

Permalink
Revert "Remove redundant serialization code (pytorch#126249)"
Browse files Browse the repository at this point in the history
This reverts commit aab448e.

Reverted pytorch#126249 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it is failing sigmoid/frontend:serialization_test internally ([comment](pytorch#126249 (comment)))
  • Loading branch information
pytorchmergebot authored and ZelboK committed May 19, 2024
1 parent 45a3349 commit 2f044a8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions torch/_export/serde/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,21 @@ def export_nn_module_stack(val):
path, ty = val

assert isinstance(path, str)
assert isinstance(ty, str)

return path + "," + ty
# node.meta["nn_module_stack"] could have two forms:
# 1. (path: str, module_type: 'type'), e.g.
# ('', <class 'sigmoid.inference.MySimpleModel'>)
# 2. (path: str, module_type: str), e.g.
# ('', 'sigmoid.inference.MySimpleModel')
# ExportedProgram directly produced by torch.export() has form 1
# ExportedProgram deserialized from disk has form 2
# TODO: This is not ideal, we should fix this.
if isinstance(ty, str):
normalized_ty = ty
else:
normalized_ty = ty.__module__ + "." + ty.__qualname__

return path + "," + normalized_ty

# Serialize to "key,orig_path,type_str"
nn_module_list = [
Expand Down

0 comments on commit 2f044a8

Please sign in to comment.