Repository navigation
[library] Keep the user's module on a triton_op's function - #202256
bobrenjc93 wants to merge 17 commits into
Conversation
[ghstack-poisoned]
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202256
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 95de7f4 with merge base 25298e6 ( 🟢 GREEN LIGHT - PR approved to be merged without human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
@claude review |
|
Claude finished @bobrenjc93's task in 56s —— View job The change is correct and safe to approve; the only problem is a test assertion that is always true. PR Review: #202256Summary
I checked these call sites and none of them change behaviour:
Testing
RecommendationApprove. Fix the test assertion above before landing. One limitation for the follow-up PRs in this stack: |
[ghstack-poisoned]
|
Review replies:
|
|
@claude review |
|
Claude finished @bobrenjc93's task in 35s —— View job I found no new issues, and the earlier review's test-assertion finding is fixed at HEAD, so this looks ready to land. PR Review: #202256 (re-review)Summary
The earlier finding about the always-true Apart from RecommendationApprove. Nothing blocks landing. |
[ghstack-poisoned]
[ghstack-poisoned]
`torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: 9a1509a Pull-Request: #202256
`torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: 9a1509a Pull-Request: #202256
[ghstack-poisoned]
`torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: e1fc4de Pull-Request: #202256
[ghstack-poisoned]
`torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: 65521ff Pull-Request: #202256
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
There was a problem hiding this comment.
Automated review of 95de7f4: nothing blocking; ready for human review.
The PR wraps triton_op's internal backend_fn with functools.wraps(fn, updated=()), so CustomOpDef._init_fn's module, name, qualname and wrapped come from the user's function instead of torch._library.triton. It also adds a regression test, and the review found no issues. Recommendation: Approve.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 0 checks: Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…02256) `torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#202256 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: pytorch#202253
…02256) `torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#202256 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: pytorch#202253
Stack from ghstack (oldest at bottom):
torch.library.triton_opnow wraps the user's function withfunctools.wraps, so the op's_init_fn.__module__is the module that defined it, nottorch._library.triton.Why precompile needs this
A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through
torch._library.custom_ops.OPDEFS[name]._init_fn.__module__. For acustom_opthat is already the user's module. For atriton_opit wastorch._library.triton, which is importable but registers nothing, so the artifact would import the wrong module and still fail.What changes
triton_op's innerbackend_fnis decorated withfunctools.wraps(fn, updated=()). This copies__module__,__name__,__qualname__,__doc__and__wrapped__, but not__dict__.Test plan
New test
test_triton_op_function_is_the_usersintest/test_custom_ops.py.Written with an AI assistant (Claude Code) and reviewed by me.
Co-Authored-By: Claude Opus 5.5 [email protected]