-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[export] Serialize getattr nodes #107924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[export] Serialize getattr nodes #107924
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/107924
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit be3d23e with merge base b4c6c4d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think it's reasonable to have get_attr in the graph. In fact I forgot this corner case before.
torch/_export/serde/schema.py
Outdated
@@ -250,6 +250,7 @@ class GraphModule: | |||
# TODO(zhxchen17) Merge call_spec into call graph. | |||
call_spec: CallSpec | |||
module_call_graph: List[ModuleCallEntry] | |||
constants: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to bump schema version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking no because we haven't published things yet :P but I would bump it if a schema change was made after today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so you're going to store attributes that are tensors here. Didn't we have a general place to store tensors by reference in the IR as well?
@angelayi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
9ff84ed
to
18025e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, few questions.
elif isinstance(attr, torch.fx.GraphModule): | ||
with self.save_graph_state(): | ||
graph = self.serialize_graph(attr) | ||
return Argument.create(as_graph=GraphArgument(name=arg.target, graph=graph)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if in the future it would make sense to store graphs by name as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either way is fine, but graph arguments are more consistent with fx.GraphModule and other existing format (e.g. onnx).
torch/_export/serde/schema.py
Outdated
@@ -250,6 +250,7 @@ class GraphModule: | |||
# TODO(zhxchen17) Merge call_spec into call graph. | |||
call_spec: CallSpec | |||
module_call_graph: List[ModuleCallEntry] | |||
constants: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so you're going to store attributes that are tensors here. Didn't we have a general place to store tensors by reference in the IR as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I would need to block this diff.
Let's consider Tensor serialization holistically with AOTInductor, and Model Processing workstream.
cc @suo, @muchulee8
The serialization format is private implementation detail hidden behind torch.export.save/load API, so we have freedom to evolve it. Since there is no support for serializing or deserializing constant tensors like these yet, this change doesn't make the situation any worse than what it is today (no support at all). Can we land this solution (torch.save-based) now so that torch.export.save() doesn't silently lose constant tensors (a severe bug) today to make 2.1 branchcut? Then we can immediately evolve it in a BC-compatible way. |
Ok, but we need to make it clear that we DOES NOT have any BC guarantee on this exported version of the weights! My concern is that once this weight format is leaked into production service, we will be tied to it, which becomes very hard to change! Notice that this is a different problem from the state_dict serialization! Weights in state_dict serialization and deserialization is not specific in the PT2 IR. But this constant tensor serialization/deserialization is part of the IR spec. |
Yeah, we made some scary warnings in the pytorch doc pytorch/torch/export/__init__.py Line 1120 in c68d0a7
|
Ok, I removed the block. Let's come up with a proper solution soon. |
Yep, let's do it next week |
Another plausible solution is to lift such constant weights as graph inputs, so they can be handle in the same way as weights/buffers. |
discussed in comment, agreed to proceed
comment resolved, reviewer out of work hour, need to land soon
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: Meta Internal-Only Changes Check Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge -f "only failure is Meta Internal-Only Changes Check, which is an infra failure" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Turns out some graphs will result in getattr nodes...so let's serialize them Pull Request resolved: #107924 Approved by: https://github.com/zhxchen17, https://github.com/avikchaudhuri
Turns out some graphs will result in getattr nodes...so let's serialize them