Skip to content

Use int64 addressing in _triton_permute_bwd_kernel - #4988

Open
indianspeedster wants to merge 1 commit into
pytorch:mainfrom
indianspeedster:fix/permute-bwd-int64
Open

indianspeedster wants to merge 1 commit into
pytorch:mainfrom
indianspeedster:fix/permute-bwd-int64

Conversation

@indianspeedster

@indianspeedster indianspeedster commented Oct 8, 2026 •

Copy link
Copy Markdown

Summary

_triton_permute_bwd_kernel computes row * cols in int32 for both its gradient
load and its scatter store. Once rows * cols >= 2**31 the address overflows and
the access hits an illegal address. This widens the loaded destination rows and
the gradient row offsets to int64.

The size is reachable in practice: DeepSeek-V3-16B with EP=8 and imbalanced
routing sent 1,141,504 rows x 2048 cols = 2,337,800,192 elements through this
kernel. _triton_permute_bwd is also the backward of permute_mxfp8_fwd_hp_bwd,
so this fixes that path too.

Split out of #4623 as requested in review. #4623 is stacked on this PR, because
it routes the bf16 permute_and_pad backward through this kernel.

Test plan

New test test_triton_permute_bwd_addresses_past_int32 in
test/prototype/moe_training/ep/test_kernels.py covers both sides of the fix:

  • Store: a 4096-row gradient scattered into the last rows of an output with more
    than 231 elements (the last 1024 of those rows start past 231).
  • Load: a gradient with more than 2**31 elements whose last rows scatter into a
    small output.

It runs the kernel in a child process with a 120 s timeout, so an illegal address
or hang fails the test instead of crashing the pytest process. The child is
pointed at the same torchao the test imported. Each case needs about 4 GiB of GPU
memory; the test skips with less than 6 GiB free.

MI355X (gfx950) B200 (SM100)
test_permute.py + ep/test_kernels.py with this change 11 passed 11 passed
New test against main's kernel fails: illegal memory access fails: illegal memory access
New test with only the load widening reverted fails not run
New test with only the store widening reverted fails not run

Test command on both machines: pytest test/prototype/moe_training/ep/test_permute.py test/prototype/moe_training/ep/test_kernels.py. MI355X: torch 2.15.0.dev+rocm7.14, triton 3.8.0; because main gates these files to SM100, the MI355X runs override that gate locally. B200: torch 2.14.1+cu130, triton 3.8.0.

No upstream CI runner has SM100, and these test files are gated to SM100 on main, so today these tests run in no CI job. After #4987 (which enables them on gfx950) they run in the ROCm regression job (regression_test_rocm.yml, MI350 runner, triggered by ciflow/rocm or a push to main).

This PR and #4989 both append tests to the end of ep/test_kernels.py, so
whichever lands second needs a trivial rebase.


Authored with assistance from an AI coding agent.

@pytorch-bot

pytorch-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

Note: Links to docs will display an error until the docs builds have been completed.

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 8, 2026
The kernel computed `row * cols` in int32 for both its gradient load and its
scatter store, so once rows * cols >= 2**31 the addresses overflowed. On
MI355X and B200 the access then hits an illegal address. Widen the loaded
destination rows and the gradient row offsets to int64.

_triton_permute_bwd is the backward of permute_mxfp8_fwd_hp_bwd, so this
fixes that path too.

Test: test_triton_permute_bwd_addresses_past_int32 covers the store (a small
gradient scattered past 2**31 output elements) and the load (a gradient with
more than 2**31 elements). It runs the kernel in a child process, so an
illegal address or hang becomes a normal test failure.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant