KEMBAR78
inductor cpp wrapper: add GIL release back by chunyuan-w · Pull Request #123897 · pytorch/pytorch · GitHub
Skip to content

Conversation

@chunyuan-w
Copy link
Collaborator

@chunyuan-w chunyuan-w commented Apr 12, 2024

Stack from ghstack (oldest at bottom):

Fixes #123517.
This PR adds the GIL release (originally added in #111888) back following the suggestion here: #123897 (comment).
We added a default constructor and an assignment operator for the RAIIPyObject class
(#123897 (comment)) in order to declare the custom_op_wrapper outside of the GIL acquisition scope.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler @amjames @desertfire @chauhang

@pytorch-bot
Copy link

pytorch-bot bot commented Apr 12, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/123897

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 f831a94 with merge base e3ac615 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Apr 12, 2024
ghstack-source-id: cb4b6bc
Pull Request resolved: #123897
Comment on lines 523 to 524
# release GIL to support multiple instances inference (in different threads of the same process)
self.prefix.splice("pybind11::gil_scoped_release release;")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the story for config.abi_compatible=True?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line of GIL release has been removed in #122554.
I'm still checking if it's intended but it does cause regression in #123517.

For abi_compatible, I met some failures for UTs on CUDA after adding this line back. Still checking what happens.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because in the ABI-compatible mode, we aren't allowed to call dispatcher Boxed call, instead we go back to Python to call custom ops in #122554 (Note: this is only for the JIT mode). If this is really performance critical, you could gil_scoped_release by default, gil_scoped_acquire before entering the custom op call and destroy that gil_scoped_acquire after done with the custom op call.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Apr 15, 2024
ghstack-source-id: 46f2898
Pull Request resolved: #123897
Fixes #123517.
This PR adds the GIL release (originally added in #111888) back.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
@chunyuan-w chunyuan-w added the topic: not user facing topic category label Apr 16, 2024
Fixes #123517.
This PR adds the GIL release (originally added in #111888) back.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Apr 16, 2024
ghstack-source-id: a6de6ca
Pull Request resolved: #123897
@chunyuan-w chunyuan-w marked this pull request as ready for review April 16, 2024 02:40
@chunyuan-w chunyuan-w added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 17, 2024
@chunyuan-w
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

sanketpurandare pushed a commit to sanketpurandare/pytorch that referenced this pull request Apr 22, 2024
Fixes pytorch#123517.
This PR adds the GIL release (originally added in pytorch#111888) back following the suggestion here: pytorch#123897 (comment).
We added a default constructor and an assignment operator for the `RAIIPyObject` class
 (pytorch#123897 (comment)) in order to declare the `custom_op_wrapper` outside of the GIL acquisition scope.

Pull Request resolved: pytorch#123897
Approved by: https://github.com/peterbell10, https://github.com/jgong5
pytorch-bot bot pushed a commit that referenced this pull request May 3, 2024
Fixes #123517.
This PR adds the GIL release (originally added in #111888) back following the suggestion here: #123897 (comment).
We added a default constructor and an assignment operator for the `RAIIPyObject` class
 (#123897 (comment)) in order to declare the `custom_op_wrapper` outside of the GIL acquisition scope.

Pull Request resolved: #123897
Approved by: https://github.com/peterbell10, https://github.com/jgong5
@github-actions github-actions bot deleted the gh/chunyuan-w/10/head branch May 31, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants