-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add custom class pt2 tutorial #3431
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: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3431
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit ba48f42 with merge base 8476a99 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
06880b9
to
be8b159
Compare
|
||
import torch | ||
|
||
torch.ops.load_library("//caffe2/test:test_torchbind_cpp_impl") |
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.
is this internal stuff?
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.
probably, I hope the OSS buck/bazel target for torch isn't caffe2 lol
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.
So it would be nice if we had some sample code someone could download that had the C++ extension set up with it. Then it would be clearer exactly what needs to be loaded (via load_library, or an import statement). But I'm happy to ship some version of this as-is without that because it already helps alot
However, it may be difficult for users to write a fake class: the original class | ||
uses some third-party library that determines the output shape of the methods, | ||
or is complicated and written by others. Besides, users may not care about the | ||
limitations listed above. In this case, please reach out to us! |
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.
Can also mention users can define x.tracing_mode(), which returns "real" so as to skip fakification.
Thanks for porting this tutorial! Looks good to me. |
This tutorial is a follow-on to the | ||
:doc:`custom C++ classes <torch_script_custom_classes>` tutorial, and | ||
introduces additional steps that are needed to support custom C++ classes in | ||
PyTorch 2. |
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.
torch.compile/torch.export. I don't think users understand the difference between 2 being a version and pt2 being the codename for torch.compile/torch.export.
ditto for the title.
:doc:`custom C++ classes <torch_script_custom_classes>` tutorial, and | ||
introduces additional steps that are needed to support custom C++ classes in | ||
PyTorch 2. | ||
|
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.
Do we have a sense of the stability of this? Does it always work now? If not, some warning about the rough edges around this (this is a "prototype" feature, right? or "unstable" in the current classification) would help
Why do we need to make a Fake Class? | ||
------------------------------------ |
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.
We should try to list out all the caveats around tensor aliasing. Namely, we're gonna assume that tensors inside and outside a torchbind object are different. If you do things like mutate one of them, there will be undefined behavior.
Porting over part of https://docs.google.com/document/d/1xUfRsqyQp3CUqpHaPjG3APxx9gHEKjQ3ISYi5jtKpuk/edit?tab=t.0
preview: https://docs-preview.pytorch.org/pytorch/tutorials/3431/advanced/custom_class_pt2.html
cc @williamwen42 @msaroufim @anijain2305 @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @suo @ydwu4