Skip to content

Fix Triton 3.9 compile errors in FP8 scale indexing - #5036

Closed
jagadish-amd wants to merge 2 commits into
pytorch:mainfrom
jagadish-amd:fix_triton_fp8_index
Closed

jagadish-amd wants to merge 2 commits into
pytorch:mainfrom
jagadish-amd:fix_triton_fp8_index

Conversation

@jagadish-amd

Copy link
Copy Markdown
Contributor
  • Triton 3.9 rejects [:, None] and [None, :] on a rank-0 tl.program_id(), which broke the ROCm nightly FP8 kernel tests and fails on CUDA wheels that depend on the same Triton.
  • Store blockwise reciprocal scales with scalar program ids, and broadcast the MoE expert id against the real k_offs block.
  • Scalar broadcasting is the same pattern these kernels already use, so Triton 3.7 and 3.8 keep compiling them.

pytest -v -s test/prototype/blockwise_fp8_training/test_blockwise_kernels.py::test_triton_quantize_fp8_weight_quant_transposed_rhs test/prototype/moe_training/test_kernels.py::test_fp8_rowwise_3d_transpose_rhs_atomic

Prepared with AI assistance in Cursor.

- Triton 3.9 rejects `[:, None]` and `[None, :]` on a rank-0 `tl.program_id()`, which broke the ROCm nightly FP8 kernel tests and fails on CUDA wheels that depend on the same Triton.
- Store blockwise reciprocal scales with scalar program ids, and broadcast the MoE expert id against the real `k_offs` block.
- Scalar broadcasting is the same pattern these kernels already use, so Triton 3.7 and 3.8 keep compiling them.

pytest -v -s test/prototype/blockwise_fp8_training/test_blockwise_kernels.py::test_triton_quantize_fp8_weight_quant_transposed_rhs   test/prototype/moe_training/test_kernels.py::test_fp8_rowwise_3d_transpose_rhs_atomic

Prepared with AI assistance in Cursor.

Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 1 Unclassified Failure

As of commit 8bbcf6a with merge base 1884ad0 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • PR Label Check / Check PR Labels (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    ##[error]This PR requires at least one label starting with 'module:'. Available modules can be found at: https://github.com/pytorch/ao/labels?q=module

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 30, 2026
@jagadish-amd

Copy link
Copy Markdown
Contributor Author

cc @akashveramd @jithunnair-amd

@jagadish-amd

Copy link
Copy Markdown
Contributor Author

@vkuzo can you plz review and add ci labels.

@vkuzo

vkuzo commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Claude finished @vkuzo's task in 47s —— View job


Review: Fix Triton 3.9 compile errors in FP8 scale indexing

  • Read the PR diff and the surrounding kernel code
  • Check that the new code computes the same thing as the old code
  • Search the rest of torchao/ for the same pattern
  • Post review

LGTM. This is a small, correct fix, and I found nothing that blocks merging.

torchao/prototype/blockwise_fp8_training/kernels.py:913-917

  • pid_m and pid_n are rank-0, and so is scale, because tl.max reduces over the whole tile. The old code built (1, 1) offset and mask tensors and stored a broadcast scalar into them. The new code does a scalar store with a scalar mask, which writes the same single element to the same address.
  • Minor nit, optional: scale_mask is always true here. The host wrapper asserts that M and N are divisible by block_size, and the grid is cdiv(M, BS) x cdiv(N, BS), so pid_n < N // BLOCK_SIZE and pid_m < M // BLOCK_SIZE always hold. It's harmless and guards against future callers, so keeping it is fine.

torchao/prototype/moe_training/kernels/float8_rowwise.py:195-199, 255-259

  • expert_idx * stride_scales_dim0 is a scalar, and adding it to k_offs[None, :] * stride_scales_dim1 still gives shape (1, BLOCK_SIZE_K). That matches scales_mask and scales[None, :] in the atomic_min, and the (N, K) * (1, K) broadcast in the cast kernel. The shapes and semantics are unchanged.
  • This also matches how expert_idx is already used in input_offs and output_offs in the same kernels.
  • The int32 program id times the stride_scales_dim0: int stride has the same overflow behaviour as before, so this change introduces no new risk.

Other places with the same pattern

I listed every variable assigned from tl.program_id(...) under torchao/ and searched for [:, None] or [None, :] applied to any of them. Nothing else matches, so these two files appear to be the only places in the repo that would fail on Triton 3.9 for this reason.

Suggestions (optional)

  • The PR doesn't add a test. The two tests listed in the description already exercise both kernels, so I wouldn't block on that. Once a CI job runs Triton 3.9 nightly, it will catch regressions here.

I didn't run the tests myself because this runner has no GPU. Please confirm the ROCm and CUDA CI jobs pass once labels are added.

@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/rocm-mi300.
Currently recognized labels are

  • ciflow/benchmark
  • ciflow/docs
  • ciflow/tutorials
  • ciflow/rocm
  • ciflow/4xh100
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@jagadish-amd

Copy link
Copy Markdown
Contributor Author

@vkuzo I have fixed ruff failures.

@jagadish-amd

Copy link
Copy Markdown
Contributor Author

Run Regression Tests on ROCm / test-nightly (ROCM Nightly, linux.rocm.gpu.ecosystem.mi350.1, --pre torchvision torch --index-url... / linux-job (gh)
test_triton_mxfp8_dim1_randn[ScaleCalculationMode.FLOOR-256-128]
--> this is fixed by #4941 which is pending merge.

@jithunnair-amd

Copy link
Copy Markdown
Contributor

@vkuzo The failure on PT2E GPU tests is because that workflow cannot run successfully on fork PRs. We will file a separate PR to fix that problem, but it shouldn't block this PR's merge, which is needed to unblock #5032.

@jagadish-amd

Copy link
Copy Markdown
Contributor Author

combining this PR into #4941 to avoid circular failures, and hence retiring the current PR.

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

Labels

ciflow/rocm ciflow/rocm-mi300 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.

3 participants