Repository navigation
fix(conversion): convert aten._grouped_mm when the group offsets are a constant - #5047
Open
SharvenRane wants to merge 1 commit into
Open
SharvenRane wants to merge 1 commit into
SharvenRane wants to merge 1 commit into
Conversation
…a constant Fixed group sizes, such as a buffer that says how many rows each expert gets, reach the converter as a torch.Tensor after freezing. The dense lowering passed that tensor straight to cast_trt_tensor, which needs an ITensor, so the conversion raised a TypeError. Turn the offsets into a TensorRT tensor first, as the converter already does for its other inputs. Fixes pytorch#5038
narendasan
requested review from
zewenli98
and removed request for
narendasan
November 23, 2026 23:31
This branch has not been deployed
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.
Description
When a mixture of experts layer has fixed group sizes, for example a buffer of offsets, the offsets reach the
aten._grouped_mmconverter as a constanttorch.Tensorafter freezing. The dense lowering passed them straight tocast_trt_tensor, which needs anITensor, sodynamo.compilefailed withTypeError: add_cast(): incompatible function argumentsand the grouped matmul stayed out of TensorRT, splitting the graph into extra engines.impl.moe.grouped_mmnow turnsoffsinto a TensorRT tensor withget_trt_tensorbefore the cast. The change is in the shared implementation rather than inenforce_tensor_types, becauseoffscan be positional or keyword andenforce_tensor_typesis indexed one way only.Fixes #5038
Type of change
Testing
test_grouped_mm_constant_offscovers offsets passed by keyword and by position.conversion/test_moe_aten.py: 2 failed, 7 passed on main; 9 passed with this change.tests/py/dynamo/conversion/: the same 42 tests fail on main and with this change (71 of the repo wide failures come from the recent nightlydict.discardchange addressed in fix: FakeTensorUpdater with the dict processed_hashes in PyTorch main #5046); the only difference is the 2 new tests, which pass.Tested on an RTX 5070 Ti with TensorRT 11.4 and torch 2.16.0.dev20261115.
Checklist: