-
Notifications
You must be signed in to change notification settings - Fork 24.9k
[export] inline jit.scripted function in export #155180
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
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/155180
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 503740c with merge base 3f34d26 ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
cc: @justinchuby
Does this handle control flows of the scripted function? I thought it would be nice to directly inline the scripted function to leverage its ability to capture them (which is most of the time why a user would want to script the function in the first place) |
It handles the control flow the same way as we exporting the python code: we specialize the constants and shapes, errors out for data-dependent ones. |
When we exporting a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. cc EikanWang jgong5 wenzhe-nrv sanchitintel [ghstack-poisoned]
I think it can be more helpful: the scripted functions are usually data dependent with control flows (that’s often why they are used) |
Yeah, I agree. Maybe we could try to use the auto converter tool we're developing when we see a jit.script annotated function. It's also a good test bed for testing the coverage of the auto converter. |
When we exporting a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. cc EikanWang jgong5 wenzhe-nrv sanchitintel [ghstack-poisoned]
When we export a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. We do the same thing for script method, where a "\_\_wrapped\_\_" attribute points to the original callable in most cases. There are some corner cases we identified: top-level jit.scripted modules' method doesn't have a \_\_wrapped\_\_. In this case, we fall back to the original scripted approach. Maybe there're more such cases but need verification. cc EikanWang jgong5 wenzhe-nrv sanchitintel [ghstack-poisoned]
When we export a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. We do the same thing for script method, where a "\_\_wrapped\_\_" attribute points to the original callable in most cases. There are some corner cases we identified: top-level jit.scripted modules' method doesn't have a \_\_wrapped\_\_. In this case, we fall back to the original scripted approach. Maybe there're more such cases but need verification. cc EikanWang jgong5 wenzhe-nrv sanchitintel [ghstack-poisoned]
When we export a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. We do the same thing for script method, where a "\_\_wrapped\_\_" attribute points to the original callable in most cases. There are some corner cases we identified: top-level jit.scripted modules' method doesn't have a \_\_wrapped\_\_. In this case, we fall back to the original scripted approach. Maybe there're more such cases but need verification. cc EikanWang jgong5 wenzhe-nrv sanchitintel [ghstack-poisoned]
When we export a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. We do the same thing for script method, where a "\_\_wrapped\_\_" attribute points to the original callable in most cases. There are some corner cases we identified: top-level jit.scripted modules' method doesn't have a \_\_wrapped\_\_. In this case, we fall back to the original scripted approach. Maybe there're more such cases but need verification. cc EikanWang jgong5 wenzhe-nrv sanchitintel [ghstack-poisoned]
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
When we export a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path. We do the same thing for script method, where a "\_\_wrapped\_\_" attribute points to the original callable in most cases. There are some corner cases we identified: top-level jit.scripted modules' method doesn't have a \_\_wrapped\_\_. In this case, we fall back to the original scripted approach. Maybe there're more such cases but need verification. Pull Request resolved: pytorch#155180 Approved by: https://github.com/zou3519
Stack from ghstack (oldest at bottom):
When we export a scripted function, we inline the original callable stored in "_torchdynamo_inline", this is the same strategy as torch.compile path.
We do the same thing for script method, where a "__wrapped__" attribute points to the original callable in most cases. There are some corner cases we identified: top-level jit.scripted modules' method doesn't have a __wrapped__. In this case, we fall back to the original scripted approach. Maybe there're more such cases but need verification.
cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel