-
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
❌ 125 Tests Failed:
View the top 2 failed tests by shortest run time
View the full list of 1 ❄️ flaky tests
To view more test analytics, go to the Test Analytics Dashboard |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
@@ -0,0 +1,128 @@ | |||
import os |
Check warning
Code scanning / lintrunner
RUFF/CPY001 Warning
See https://docs.astral.sh/ruff/rules/missing-copyright-notice
@@ -0,0 +1,128 @@ | |||
import os |
Check warning
Code scanning / lintrunner
RUFF-FORMAT/format Warning
|
||
def _create_simple_model(): | ||
tensor = ir.tensor([1.0], dtype=ir.DataType.FLOAT, name="X") | ||
node = ir.Node("Identity", inputs=[tensor], outputs=["Y"]) |
Check failure
Code scanning / lintrunner
PYLINT/E1120 Error
See no-value-for-parameter. To disable, use # pylint: disable=no-value-for-parameter
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
PYLINT/E0602 Error
See undefined-variable. To disable, use # pylint: disable=undefined-variable
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
RUFF/F821 Error
See https://docs.astral.sh/ruff/rules/undefined-name
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
RUFF/F821 Error
See https://docs.astral.sh/ruff/rules/undefined-name
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
PYLINT/E0602 Error
See undefined-variable. To disable, use # pylint: disable=undefined-variable
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
RUFF/F821 Error
See https://docs.astral.sh/ruff/rules/undefined-name
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
PYLINT/E0602 Error
See undefined-variable. To disable, use # pylint: disable=undefined-variable
node = ir.node("Identity", inputs=[tensor], outputs=["Y"]) | ||
graph = ir.graph([node], name="test_graph", outputs=[node.outputs[0]], initializers=[tensor]) | ||
model = ir.model(graph) | ||
core_model = _core.Model(model) |
Check failure
Code scanning / lintrunner
RUFF/F821 Error
See https://docs.astral.sh/ruff/rules/undefined-name
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
TODO