-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ONNX] De-duplicate initializers #68202
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
Conversation
CI Flow Status⚛️ CI FlowRuleset - Version:
You can add a comment to the PR and tag @pytorchbot with the following commands: # ciflow rerun, "ciflow/default" will always be added automatically
@pytorchbot ciflow rerun
# ciflow rerun with additional labels "-l <ciflow/label_name>", which is equivalent to adding these labels manually and trigger the rerun
@pytorchbot ciflow rerun -l ciflow/scheduled -l ciflow/slow For more information, please take a look at the CI Flow Wiki. |
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 0793a75 (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
Job | Step | Action |
---|---|---|
Report results | 🔁 rerun |
This comment was automatically generated by Dr. CI (expand for details).
Please report bugs/suggestions to the (internal) Dr. CI Users group.
auto valsToParamsMap = buildValueToParamsMap(b, paramsDict); | ||
fuseConvBatchNorm(b, valsToParamsMap); | ||
if (opset_version >= OPSET_VERSION_15) { | ||
// Apply de-duplication after opset 15 for backward compatibility. |
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.
Please elaborate on this comment. I don't see anything in the ONNX 1.10 release notes that seems to relate to duplicate initializers.
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.
This is open to discussion. Not related to ONNX release, but we are changing default behavior of exporter regarding initializers, so I'm wondering if we should only apply it on newer opsets for BC purpose. This applies for other future passes of similar types as well. Would love to hear your thoughts on this.
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 unless we have reason to believe this will not work on older runtimes, we should not guard the behavior.
I suggest we test this against Caffe2 using test_pytorch_onnx_caffe2.py. If we want to be extra careful you could also install an older version of ORT and run test_pytorch_onnx_onnxruntime.py.
If it passes both of those, then I think it's likely that we don't need to guard this behavior.
WDYT?
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 we can give a try. For general usage I'm not too worried. If there are issues they are considered bugs and we can resolve them. I'm slightly worried against user custom behaviors on top of initializer/parameters.
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.
The test_operator.py
result is one example, the change in parameters may appear confusing for users. For better readability I updated the logic to insert identity node instead of directly replacing initializers.
841a2da
to
402b276
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.
Please address comments before merging, but basically LGTM.
Thanks!
Still LGTM with identity nodes. Feel free to merge once tests pass. |
47682e7
to
bbbb02f
Compare
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbao@microsoft.com> [ghstack-poisoned]
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> ghstack-source-id: d17dfa4 Pull Request resolved: pytorch#69547
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> Differential Revision: [D32994271](https://our.internmc.facebook.com/intern/diff/D32994271) [ghstack-poisoned]
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> Differential Revision: [D32994271](https://our.internmc.facebook.com/intern/diff/D32994271) [ghstack-poisoned]
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> Differential Revision: [D32994271](https://our.internmc.facebook.com/intern/diff/D32994271) [ghstack-poisoned]
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> Differential Revision: [D32994271](https://our.internmc.facebook.com/intern/diff/D32994271) [ghstack-poisoned]
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> ghstack-source-id: d17dfa4 Pull Request resolved: pytorch#69547
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> ghstack-source-id: d17dfa4 Pull Request resolved: pytorch#69547
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> ghstack-source-id: d17dfa4 Pull Request resolved: pytorch#69547
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> ghstack-source-id: d17dfa4 Pull Request resolved: pytorch#69547
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> Differential Revision: [D32994271](https://our.internmc.facebook.com/intern/diff/D32994271) [ghstack-poisoned]
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Co-authored-by: BowenBao <bowbaomicrosoft.com> Differential Revision: [D32994271](https://our.internmc.facebook.com/intern/diff/D32994271) [ghstack-poisoned]
Summary: Pull Request resolved: #69547 ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Test Plan: Imported from OSS Reviewed By: msaroufim Differential Revision: D32994271 Pulled By: malfet fbshipit-source-id: 10ac66638b6255890875272472aa9ed07a5b1d9a Co-authored-by: BowenBao <bowbao@microsoft.com>
Summary: Pull Request resolved: #69547 ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same `data_ptr`, `strides` and `sizes`. Test Plan: Imported from OSS Reviewed By: msaroufim Differential Revision: D32994271 Pulled By: malfet fbshipit-source-id: 10ac66638b6255890875272472aa9ed07a5b1d9a Co-authored-by: BowenBao <bowbao@microsoft.com> (cherry picked from commit d7cbde9)
if ((valsToParamsMap.find(v1) == valsToParamsMap.end()) || | ||
(valsToParamsMap.find(v2) == valsToParamsMap.end())) { | ||
return false; |
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.
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.
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.
Yes related to #108342. I think I misread the code, not super familiar with C++.
ScriptModule export introduces duplicated ONNX initializers for shared weights, unnecessarily increases ONNX model size. This PR de-duplicates ONNX initializers for model exported in eval mode, by checking if the underlying tensors share the same
data_ptr
,strides
andsizes
.