Skip to content
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

Added Tensor to PyObject conversion using torch_python #457

Closed
wants to merge 16 commits into from

Conversation

egordm
Copy link

@egordm egordm commented Feb 19, 2022

These changes add a few additional bindings to torch_python library.

Mainly:
THPVariable_Unpack for unpacking PyObject into a Tensor pointer
THPVariable_Check for checking whether PyObject is a valid Tensor object
THPVariable_Wrap for creating PyObject from a Tensor pointer (and transferring ownership)

Additionally pyo3 type conversion traits are implemented for Torch struct to convert between PyObject and Tensor seamlessly when defining pyo3 functions.

An example project is included creating a simple counter/metric class which accumulates tensor objects and computes a metric as output while exposing the counter tensor.

The changes are split over torch-sys (python feature) and tch (torch_python feature) modules.

The relevant issue to this PR would be: #174

Thanks in advance. Let me know if some changes are needed.

@kszlim
Copy link

kszlim commented Nov 28, 2022

Would be very interested in this as well, as this would be a nice path forward for writing fast dataloader in rust.

@kcking
Copy link

kcking commented Feb 15, 2023

@LaurentMazare, would love to see this PR considered; it would make integrating python and rust pytorch code more ergonomic.

@sebastiandero
Copy link

Any updates on this one?

@sebastiandero
Copy link

@egordm we merged new changes and fixed issues with macOS support in this new PR here: #698

Thank you very much for this, saved our day!

@LaurentMazare
Copy link
Owner

Closing this as these functionalities should now be available from the pyo3-tch crate (see #730).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants