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

Add support for moving PyTorch Tensors from python to rust via PyO3 #698

Closed
wants to merge 18 commits into from
Closed

Add support for moving PyTorch Tensors from python to rust via PyO3 #698

wants to merge 18 commits into from

Conversation

sebastiandero
Copy link

@sebastiandero sebastiandero commented May 4, 2023

All Credit goes to @egordm

@LaurentMazare Please let us know what you need from us to merge this, we urgently need this functionality

Updated version of #457
Merged changes and added macOS support (dylib)

Copy link

@egordm egordm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job.
I have just tested it as well. Works well.
I have highlighted a few parts I may have accidentally left behind.

Cargo.toml Outdated

[dev-dependencies]
anyhow = "1"

[workspace]
members = ["torch-sys"]
members = ["torch-sys", "examples/python-entropy"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

Comment on lines 11 to 17
# eye = torch.eye(3)
# eye.grad = torch.ones(3, 3)
# print('aaaaa')
# eye2 = pe.print(eye)
# print(eye)
# print('eye2')
# print(eye2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part can be deleted. :P

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this! Hope we can merge this today @LaurentMazare?

@LaurentMazare
Copy link
Owner

I've pushed a more barebone sets of changes that should hopefully make it possible to write python extensions using tch, see #704. I think it's somewhat similar but more minimalist, the idea is to only provide some low level api for now and not bring in the dependency to PyO3 explicitely and refine this over time (or have the actual Python glue bits live in another crate).
An upside of the changes is that it lifts a recent overhaul of the build script so as to make it easy to ensure that the Python libtorch version is actually being used rather than potentially a different shared library than what the Python side uses.
A very simple example is in examples/python-extension.

@LaurentMazare
Copy link
Owner

Closing this now, hopefully the main functionalities are now covered in a slightly different way in the newly minted pyo3-tch crate #730 . The sample Python extension can also be found in a separate repo tch-ext.

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.

3 participants