-
Notifications
You must be signed in to change notification settings - Fork 57
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
[IR] Improve external data handling #2020
base: main
Are you sure you want to change the base?
Conversation
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.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
onnxscript/ir/_external_data_test.py:352
- The
tobytes
method should raise aTypeError
instead of returning it.
return TypeError
❌ 20 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Co-authored-by: Copilot <[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.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
onnxscript/ir/_external_data.py:174
- The variable name 'base_path' should be renamed to 'base_dir' for consistency.
base_path: str | os.PathLike,
onnxscript/ir/_external_data.py:252
- The word 'unneccesarry' should be corrected to 'unnecessary'.
# Sort all tensors based on tensor sizes, in order to avoid unneccesarry alignment.
model: _core.Model, | ||
path: str | os.PathLike, | ||
format: str | None = None, | ||
external_data: str | os.PathLike | None = None, |
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.
nit suggestion: maybe name it as external_data_path to clarify it is a path to file?
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.
Since the option is intended to provided by keyword, I find external_data
to be more concise and as clear. Let me know if you think differently?
I have a question (the same one discussed earlier too): is it possible to ensure that small tensors (typically scalar constants, and shapes) stay internal to the model? This is a question that impacts all ONNX users, so it is worth making a decision based on overall requirements (as opposed to just the IR perspective). The clear need is to have large tensors external (typically weights). Scalars and shapes: not so much. Further, no point in incurring any of the overheads of external tensors for them (not worth memory-mapping, not worth lazy loading, etc.) ONNX shape inference specifically does not load any external tensors during inference, and will be impacted if shapes are stored externally. Updating ONNX shape inference to do this will be a somewhat non-trivial task. Another related question is the role of "Constant()" nodes vs. initializers ... here, there is no issue with using initializers in favor of Constant nodes (except inside Functions, which don't support them, but that's another issue worth discussing separately). Eg., initializers seem to be handled better by Netron (and a few other tools) than Constant nodes. |
That makes sense. We can have a size limit like the onnx.save function does |
external_data
option toir.save
. This will save all initializers as external tensors. It is robust against data loss when overwriting.modify_model
option toir.save
to allow users to control if they want to keep the model unchanged when saving to external data.ir.save
method.Note
We do not need to add external data options to
ir.load
. The external data is always loaded lazily in the IR. If we want to transfer the data to memory at loading, we can use the_external_tensor_to_memory_tensor
internally.Example usage