-
Notifications
You must be signed in to change notification settings - Fork 72
Add LazyTensor class to implement ir.TensorProtocol #2232
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
--- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/onnxscript?shareId=XXXX-XXXX-XXXX-XXXX).
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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.
Pull Request Overview
This PR introduces a LazyTensor class that implements the TensorProtocol and defers expensive tensor transformations until methods like numpy() or tobytes() are called. Key changes include:
- Adding the LazyTensor class and its implementation details in onnxscript/ir/_core.py.
- Implementing unit tests for LazyTensor behavior in onnxscript/ir/_core_test.py.
- Exporting LazyTensor in onnxscript/ir/init.py to make it available as part of the public API.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
onnxscript/ir/_core_test.py | Adds tests to validate LazyTensor initialization, numpy conversion, and byte serialization. |
onnxscript/ir/_core.py | Implements the LazyTensor class with support for lazy evaluation and caching. |
onnxscript/ir/init.py | Exports LazyTensor for public use. |
Comments suppressed due to low confidence (1)
onnxscript/ir/_core_test.py:1343
- The expected byte literal in the tobytes test is hard-coded and might be brittle on platforms with different endianness or integer representations. Consider generating the expected bytes dynamically using lazy_tensor.numpy().tobytes() to improve test resilience.
lazy_tensor.tobytes(),
b"\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00"
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.
Will there be a follow up that actually uses this in any implementation?
Yes! See microsoft/onnxruntime-genai#1427 |
I used copilot to help implement #2231. The lazy tensor class allows users to delay transformations to the tensors until serialization time, which helps with memory usage and avoids the need to cache of unload intermediate tensor data to disk.
Example
Fixes #2231
For more details, open the Copilot Workspace session.