fix: tensor dispatch with TP enabled#23
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make the training weight wrapper tensor dispatch behave correctly when Tensor Parallelism (TP) is enabled, so that distributed weight movement and GEMM/grouped GEMM paths don’t accidentally drop the wrapper semantics needed for low-precision routing.
Changes:
- Preserve the wrapper subclass across
c10d.scatter_(used by TP to distribute weights). - Special-case GEMM-like ops and
_grouped_mmin__torch_dispatch__to avoid the generic unwrap-and-call path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+116
to
+119
| elif func.__name__ in gemm_ops or func.__name__ == "_grouped_mm": | ||
| # Delegate to the subclass' GEMM / grouped_mm overrides without | ||
| # unwrapping the wrapper tensor, avoiding __torch_dispatch__ recursion. | ||
| return cls.__torch_function__(func, types, args, kwargs or {}) |
Comment on lines
+116
to
+119
| elif func.__name__ in gemm_ops or func.__name__ == "_grouped_mm": | ||
| # Delegate to the subclass' GEMM / grouped_mm overrides without | ||
| # unwrapping the wrapper tensor, avoiding __torch_dispatch__ recursion. | ||
| return cls.__torch_function__(func, types, args, kwargs or {}) |
Comment on lines
+42
to
+43
| # required for TP - scatter_ is used to distribute weights | ||
| torch.ops.c10d.scatter_.default, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When TP enabled, mm/addmm is dispatch via
__torch_dispatch__not__torch_function__. We have to manually call thefuncto make sure LPT kernels are correctly invoked.Note: this is a temp fix!!! Autograd backward is not working in
__torch_dispatch__.