Add Python Torch conversions - #11
Open
yuanknv wants to merge 8 commits into
Open
Conversation
yuanknv
force-pushed
the
feature/torch-conversions-py
branch
from
August 19, 2026 00:01
fdd989f to
4197dee
Compare
yuanknv
force-pushed
the
feature/torch-conversions-py
branch
from
August 19, 2026 18:15
4197dee to
778a301
Compare
nvcyc
reviewed
Aug 20, 2026
Comment on lines
+15
to
+19
| <depend>rosidl_buffer</depend> | ||
|
|
||
| <exec_depend>pytorch_vendor</exec_depend> | ||
| <exec_depend>rosidl_buffer_py</exec_depend> | ||
| <exec_depend>tensor_msgs</exec_depend> |
Contributor
There was a problem hiding this comment.
Do we need to add cuda_buffer and cuda_buffer_py as depndencies?
Suggested change
| <depend>rosidl_buffer</depend> | |
| <exec_depend>pytorch_vendor</exec_depend> | |
| <exec_depend>rosidl_buffer_py</exec_depend> | |
| <exec_depend>tensor_msgs</exec_depend> | |
| <depend>cuda_buffer</depend> | |
| <depend>rosidl_buffer</depend> | |
| <exec_depend>cuda_buffer_py</exec_depend> | |
| <exec_depend>pytorch_vendor</exec_depend> | |
| <exec_depend>rosidl_buffer_py</exec_depend> | |
| <exec_depend>tensor_msgs</exec_depend> |
Expose typed CPU and CUDA tensor-message conversions, preserve DLPack-backed buffer ownership, and validate zero-copy inter-process rclpy transport.
Add an independent Python Torch vendor and keep CUDA integration optional so CPU and CUDA platforms use the same conversion API.
Keep package documentation centralized and avoid duplicating platform behavior details.
Rename the Python package to pytorch_vendor and align both vendor selectors with official CUDA 13.0 and 13.2 artifacts.
Separate CPU and CUDA conversion behavior behind a private registry so future hardware support does not change the public API.
Make the private extension's scope explicit so future hardware adapters can provide distinct native bridges.
Use a versioned C ABI so CPU users are not forced to install CUDA buffer runtime dependencies.
Keep the core CPU-capable package platform-independent and discover optional conversion adapters through Python entry points.
yuanknv
force-pushed
the
feature/torch-conversions-py
branch
from
August 27, 2026 23:04
4dddf00 to
f5c5175
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request adds typed Python conversions between PyTorch tensors and
tensor_msgs/ExperimentalTensormessages.The new
torch_conversions_pypackage exposes thetorch_conversionsPython module with the following APIs:allocate_tensor_msg(): Allocates CPU-backed or CUDA-backed message storage.from_output_tensor_msg(): Returns a writable Torch view over message-owned storage.from_input_tensor_msg(): Returns an independent tensor by default or a zero-copy read-only view withclone=False.to_tensor_msg(): Copies an existing Torch tensor into message-owned storage.set_stream(): Provides CUDA stream context management.For CUDA-backed messages, a private pybind extension exposes the
rosidl::Bufferallocation through DLPack. The DLPack context retains the buffer and its CUDA read or write handle until PyTorch releases the tensor, preserving asynchronous stream and event synchronization without copying the message storage.This pull request is stacked on #6, which provides
cuda_buffer_py.Is this user-facing behavior change?
No. This pull request adds a new optional Python API without changing existing behavior.
This adds a new Python API for constructing
ExperimentalTensormessages and accessing their CPU or CUDA storage as PyTorch tensors.Did you use Generative AI?
Yes. OpenAI GPT-5.6 Sol via Cursor was used to assist with implementation and test.
Additional Information
This work extends the C++ Torch conversions introduced in #1 with an equivalent Python-facing API.