Repository navigation
[PyTorch] Fix IndexError in non-eager EP ops when scale buffers are None - #3816
Merged
Merged
Conversation
dispatch, prepare_and_dispatch, and combine_bwd list their optional MXFP8 scale buffers in mutates_args with a None default. When the dispatcher calls a Python kernel it drops trailing arguments equal to their default, so on the BF16 path (scales None) the schema's mutated index points past the end of the boxed args and torch's ADInplaceOrView kernel raises IndexError. Remove the defaults so the arguments are always present, and pass None explicitly in the BF16 combine_bwd call. The scale buffers stay in mutates_args, so their version counters are still bumped when present. Fixes NVIDIA#3814 Signed-off-by: Andrew Liu <all2209@columbia.edu>
test_torch_compile.py is skipped as a whole unless torch has the opaque object API, but the bug and the test apply to every supported torch. test_permutation.py has no such gate and already covers MoE ops in L0. Signed-off-by: Andrew Liu <all2209@columbia.edu>
Contributor
[Medium impact] The PR appears safe to merge, with non-blocking feedback to restore the focused regression test. SummaryRequires explicit scale arguments for the three affected EP custom ops, preventing trailing
Reviews (2) · Last reviewed commit: "[PyTorch] Remove EP regression test and ..." · Reviewed by Greptile |
Member
|
@pggPL Please take a look |
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Collaborator
|
@andrewliu2001 thanks for the contribution. Note that for PyTorch 2.13 this is no more bug. Since we support torch >= 2.8 I'lll merge this. |
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
The non-eager EP path crashes on BF16 with
IndexError: tuple index out of rangefromtorch.ops.transformer_engine_ep.prepare_and_dispatch(#3814).dispatchandcombine_bwdhave the same problem.These ops list their optional MXFP8 scale buffers in
mutates_argsand give them aNonedefault. When the dispatcher calls a Python kernel it drops trailing argumentsthat equal their default, so on the BF16 path, where the scales are
None, they aremissing from the boxed args. torch's
ADInplaceOrViewkernel for custom ops thenindexes
argswith the schema position of each mutated argument and runs past theend. PyTorch main now guards that index, but no release through 2.13 does.
This removes the defaults from those arguments so they are always present, and passes
Noneexplicitly in the one call that omitted them (BF16combine_bwd). The scalebuffers stay in
mutates_args, so their version counters are still bumped andtorch.compile still sees the mutation when they are present.
Fixes #3814
Type of change
Changes
= Nonedefaults from the optional scale arguments of thedispatch,prepare_and_dispatch, andcombine_bwdcustom ops, with a comment explaining why.None, Noneexplicitly in the BF16combine_bwdcall.test_ep_custom_ops_optional_mutated_argstotest_permutation.py. It calls thethree ops with the backend stubbed, so it runs on one GPU without NCCL EP: with
Nonescales (the BF16 path) and with scale tensors, where it also checks that the mutated
scale buffer's version counter is bumped once per op.
Testing
Single GPU, 1x A100 80GB PCIe, driver 570.195.03, CUDA 12.8, PyTorch 2.11.0+cu128,
python -m pytest -v tests/pytorch/test_permutation.py -k ep_custom_ops: both cases pass.With only
ep.pyreset to 720b252 (current main), thebf16case fails withIndexError: tuple index out of rangeand themxfp8_scalescase passes, which isthe reported behavior.
EP suite, 8x H100 80GB HBM3 (SXM5, NVLink), same driver and PyTorch, NCCL 2.30.4,
built with
NVTE_CUDA_ARCHS=90:ep.pyfrom main,run_ep.pynon-eager BF16 (NVTE_EP_EAGER=0): 37 tests,14 errors, 20 skipped, all
IndexErrorfromprepare_and_dispatch, matching theissue. The fused pass (
NVTE_EP_FUSED_PREPARE_DISPATCH=1) fails the same way.tests/pytorch/distributed/run_test_ep.sh: noIndexErrorin anypass, and every
TestEPtest passes or skips. Two things still fail in thisenvironment and look unrelated:
TestMoeEpSequential.test_megamoe_*tests fail in every pass, eager included,with "Single grouped parameters require the native grouped-tensor GroupedLinear
path, which is unavailable for the current device, dtype, or quantization recipe."
My build used CUDA 12.8; the issue reports these passing on CUDA 13.4 with the
workaround applied.
cu128 wheel I used does not have (same as the side issue noted in [Bug][PyTorch] EP non-eager dispatch crashes: IndexError in torch.ops.transformer_engine_ep.prepare_and_dispatch (mutates_args includes optional trailing None arg) #3814).
I also checked the change on CPU with torch 2.8.0 and 2.11.0: the old schemas raise
the IndexError for
Nonescales and the new ones do not, the mutated scale buffer'sversion counter is bumped when present, and the ops trace under
torch.compile(fullgraph=True).Checklist: