-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix external data bug in version converter #6847
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
Signed-off-by: Yuan Yao <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6847 +/- ##
==========================================
+ Coverage 56.28% 56.31% +0.03%
==========================================
Files 509 509
Lines 32580 32606 +26
Branches 3099 3099
==========================================
+ Hits 18337 18363 +26
Misses 13385 13385
Partials 858 858 ☔ View full report in Codecov by Sentry. |
|
Could you add a test in https://github.com/onnx/onnx/blob/main/onnx/test/version_converter_test.py |
I'm not sure what's a good way to create external data with the ONNX API. I tried running the following, but no external data is created. If I increase the shape to (20000,30000) it takes a long time and goes out of memory. Could be a bug somewhere. Any thoughts? The example in the description uses onnx-graphsurgeon to create the model. But we probably don't want to introduce another dependency. |
|
I think you need to set onnx/onnx/external_data_helper.py Line 154 in 95ecc67
Admittedly there are more work to be done in the helpers. |
Signed-off-by: Yuan Yao <[email protected]>
Signed-off-by: Yuan Yao <[email protected]>
dad3e41 to
b56ad09
Compare
Signed-off-by: Yuan Yao <[email protected]>
Signed-off-by: Yuan Yao <[email protected]>
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.
Thank you!
|
@justinchuby @andife @ramkrishna2910 |
|
@jywu-msft Looks like it was merged after branch cut. To use the version converter for large models, consider import onnxscript.version_converter
from onnxscript as ir
model = ir.load("model.onnx") # Or use `model = ir.from_proto(model_proto)` if the model is from a proto already
onnxscript.version_converter.convert_version(model, target_version=21, fallback=True)
model.ir_version = 10 # Enable support for INT4
ir.save(model, "converted.onnx")
# or model_proto = ir.to_proto(model)If desired we can update the api to accept a protobuf as well. The same logic is implemented in Olive: https://github.com/microsoft/Olive/blob/422353ecb6ca724495e7a6f366fb53a8b3146818/olive/passes/onnx/conversion.py#L662 |
|
thanks @justinchuby. |
|
@bas-aarts could you share a concrete example? If anything doesn’t work it is a bug we need to fix. |
Description
There is currently a bug in the convert.cc::conver_version() function for models with external data. This function calls ir_pb_converter.cc::ImportModelProto(), which calls ir_pb_converter.cc::graphProtoToGraph(), which calls ir_pb_converter.cc::tensorProtoToTensor(). But tensorProtoToTensor() doesn't handle external data. While TensorProto has external data support, the struct in tensor.h::Tensor does not. The version converter works on a Graph and not a GraphProto, so the conversion to Tensor struct destroys the external data references. This PR adds the missing logic for external data.
The change can be verified on a simple model with external data:
Motivation and Context
#6529