-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[Core] Support Zero-Copy Serialization for Read-Only Tensors #57639
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Haichuan Hu <[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.
Code Review
This pull request introduces an optimization for serializing PyTorch tensors by enabling zero-copy serialization. This is achieved by converting tensors to NumPy arrays, which can be handled efficiently by Ray's existing serialization mechanisms. The feature is opt-in via the RAY_ENABLE_ZERO_COPY_TORCH_TENSORS
environment variable. The implementation adds recursive conversion functions to handle tensors nested within various data structures. My review focuses on improving code clarity, maintainability, and adherence to best practices by suggesting the use of constants and refactoring duplicated code.
Signed-off-by: Haichuan Hu <[email protected]>
Signed-off-by: Haichuan Hu <[email protected]>
Signed-off-by: Haichuan Hu <[email protected]>
Signed-off-by: Haichuan Hu <[email protected]>
Why are these changes needed?
Enable zero-copy serialization for all PyTorch tensors by setting
RAY_ENABLE_ZERO_COPY_TORCH_TENSORS=1
to accelerate serialization.Example test script:
Below are the performance gains and validation results:

Related issue number
Closes #56740
Checks
git commit -s
) in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.