Repository navigation
Fix dim1 e8m0 scale indexing and Triton 3.9 FP8 compile errors - #4941
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4941
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit ec31606 with merge base 4ab9d61 ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Fixes the ROCm CI failure, failure run https://github.com/pytorch/ao/actions/runs/33204661724/job/98962533733 |
|
@vkuzo , can u plz approve and add rocm label, thanks |
|
@claude review
is this a kernel bug that can be fixed directly instead of restricting autotune candidates? |
|
Claude finished @vkuzo's task in 2m 9s —— View job Review
Short answer: yes, it's a kernel bug in the scale-store indexing of Root cause (
|
|
|
jeffdaily
left a comment
There was a problem hiding this comment.
My agent came up with this analysis, but I've read and approved it.
The 2D masked store looks right, and it also fixes the unmasked column tail when COL_TILE_SIZE does not divide n_cols. One request on the test before this lands.
Kernel: the new offsets
(start_col + c) * S + pid_row * BPRT + bwith maskcol < n_cols & block < Sare correct for every (ROW_TILE_SIZE, COL_TILE_SIZE) config and match the old offsets exactly when both tiles divide the shape. A simulation of old vs new offsets over M in {128..1024}, K in {128..512} and all six configs shows the old code losing or clobbering scales whenever RT does not divide n_rows, and writing past the end of the scale tensor in two cases: padding blocks of the last column when RT does not divide n_rows, and every column >= n_cols when CT does not divide n_cols (e.g. K=128 or 384 with CT=256). The new code writes each valid slot exactly once and nothing out of bounds.Test (test/prototype/mx_formats/test_kernels.py:496-497): the added shapes depend on which config autotune picks, and the autotune key is only n_cols, so (512, 384) reuses the config tuned on (384, 384). (512, 384) is also divisible by every ROW_TILE_SIZE, so it never takes the non-divisible row path. The column-tail OOB cannot be seen by comparing values. Could the test sweep the configs directly with autotune bypassed, e.g.
to_mxfp8_dim1_kernel.fn[grid](..., ROW_TILE_SIZE=rt, COL_TILE_SIZE=ct)for rt in (128, 256, 512) and ct in (128, 256), and allocate the scale buffer with a sentinel-filled tail that must stay untouched? That fails on the old code for M=128, 256 and 384 regardless of GPU or test order.Nit: the
TODO(future): this mask is for row-major ...comment above the fp8 store (kernels.py:721) is stale; that mask is correct.
cc @vkuzo for the merge decision.
|
Thanks @jeffdaily , @vkuzo @jeffdaily Can we plz merge this PR? seeing CI failures with the above signature on other PRs. |
|
@claude review, also why are the checks still pending |
|
Claude finished @vkuzo's task in 1m 28s —— View job Review + CI status
Why the checks are pendingThrough the Actions API, the head commit
None of the workflows triggered by This PR comes from a fork, so the most likely cause is that those runs are waiting for maintainer approval. The pytorch-bot comment "CI has now been triggered for the ciflow labels" only covers the tag-triggered workflows like ROCm. It doesn't start the I couldn't confirm this from inside the job: Code reviewKernel (
Test (
The fix is to sweep the configs directly, bypassing autotune, and to guard the scale buffer with a sentinel tail: @pytest.mark.parametrize("ROW_TILE_SIZE", (128, 256, 512))
@pytest.mark.parametrize("COL_TILE_SIZE", (128, 256))
@pytest.mark.parametrize("M, K", ((128, 128), (128, 384), (256, 128), (384, 384), (640, 256)))
def test_triton_mxfp8_dim1_all_tiles(M, K, ROW_TILE_SIZE, COL_TILE_SIZE):
x = torch.randn(M, K, dtype=torch.bfloat16, device="cuda")
_, s_ref = triton_to_mxfp8_dim1_reference(x, block_size=32, scaling_mode=ScaleCalculationMode.RCEIL)
out = torch.empty((K, M), dtype=torch.float8_e4m3fn, device="cuda") # match host-side layout
n_scales = K * (M // 32)
s_buf = torch.full((n_scales + 1024,), 0xAB, dtype=torch.uint8, device="cuda")
grid = (triton.cdiv(M, ROW_TILE_SIZE), triton.cdiv(K, COL_TILE_SIZE))
to_mxfp8_dim1_kernel.fn[grid](
x, out, s_buf, M, K,
ROW_TILE_SIZE=ROW_TILE_SIZE, COL_TILE_SIZE=COL_TILE_SIZE,
INNER_BLOCK_SIZE=32, SCALING_MODE="rceil",
)
torch.testing.assert_close(s_buf[:n_scales].view(K, M // 32), s_ref.view(torch.uint8).reshape(K, M // 32), rtol=0, atol=0)
assert (s_buf[n_scales:] == 0xAB).all() # no out-of-bounds writesThis sketch needs adapting: the output allocation and stride should follow what Nits:
VerdictThe kernel fix is correct and also closes an out-of-bounds write on the column tail. It's safe to land as-is. Before merging, I'd add the deterministic per-config test, so this can't silently regress depending on which config autotune picks. I couldn't run any tests here because this runner has no SM100 or MI350 GPU. The only GPU evidence is the passing MI350 ROCm regression run above. |
|
can you rebase on main? looks like CI did not properly run, I hope a rebase would fix it |
Dim1 scale stores are wrong when ROW_TILE_SIZE is larger than n_rows (e.g. M=128 with a 256/512 tile). Skip those configs and key autotune on n_rows so a large-shape winner is not reused on a small tensor. Authored with the assistance of an AI coding agent (Cursor). Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
22ba7c5 to
7adefea
Compare
rebase done. |
|
Both PRs (current one and #5036) fail in CI on the other's bug, so I will port the other PR to this Pr itself. |
Signed-off-by: Jagadish Krishnamoorthy <[email protected]>
|
PT2E workflow failure is due to known CI issue: credential issue. |
Avoid AWS/OIDC auth failures on forked PRs by running PT2E ROCm under ciflow/rocm instead of pull_request; keep CUDA in regression_test_pt2e_gpu.yml. Co-authored-by: Cursor <[email protected]>
[ROCm] Move PT2E ROCm tests to ciflow/rocm workflow
Head branch was pushed to by a user without write access
|
PT2E tests are now passing. |
vkuzo
left a comment
There was a problem hiding this comment.
the triton part looks fine, I don't think changes to pt2e CI belong in this PR though
|
@jagadish-amd Can you please separate out the changes to the pt2e workflows into another PR? |
|
Head branch was pushed to by a user without write access
reverted the pt2e fix, can we merge or do we need to run the workflows? the CI results are green for previous runs. |
|
@claude review |
|
Claude finished @vkuzo's task in 53s —— View job Review
Verdict: LGTM to merge. The changes look correct, and your request to drop the PT2E change has been handled. One test gap from earlier reviews is still open. It doesn't block the merge. PT2E CI changes: removed ✅The net diff against The branch history is messy: it contains a merge of the PT2E branch, the revert of it, and the old commit "Prune Triton autotune tiles". Please squash-merge and write a commit message that describes only the two fixes. dim1 e8m0 scale store (
|
Dim1 e8m0 scales are stored at c * (n_rows / 32) + b. The old tile offset matched that address only when ROW_TILE_SIZE divided n_rows, so a 256- or 512-row tile on M=128 overwrote other columns' scales. Write the address directly and mask padding.
This also includes the Triton 3.9 fix from #5036. The ROCm nightly Torch wheel now depends on Triton 3.9, which rejects [:, None] on a rank-0 tl.program_id(). Each pull request failed CI on the other pull request's bug, so both fixes are in this branch.
Authored with the assistance of an AI coding agent (Cursor).