Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
6d4c2bd to
e80fea3
Compare
|
@tanth47 Is this suppose to be draft still? |
HaiShaw
left a comment
There was a problem hiding this comment.
LGTM.
Please pay attention to numeric and scaling.
cc @carlushuang @shengnxu @coderfeli @kkHuang-amd @1am9trash
|
@coderfeli @shengnxu @carlushuang please review. |
Signed-off-by: tanth47 <[email protected]>
8e92e27 to
bceaa5a
Compare
|
I rebased the branch onto latest main. The previous run didn’t reach the tests, the branch was missing the recently added |
|
Hi @amd-ruitang3 Have you had a chance to look at this? |
|
We've confirmed the bug. Disassembly of both code objects verifies the root cause: the a8w8 MLA kernel converts the softmax numerators to E4M3 before P@V while the denominator stays in FP32, so probabilities with a logit gap > ~7 from the row max flush to zero and the output magnitude shrinks — it worsens with context length, and cosine-only tests won't catch it. The math in your patch is correct (scale p by 448 before the FP8 cvt, 1/448 at the end), but since it patches the .co at the ISA level we won't merge it as-is. We'll land the fix from the kernel source and regenerate all a8w8 MLA variants on gfx950 and gfx942 — the same missing scaling is present in the _ps, MTP, and qh32 variants, and #6139 is the same class of issue on gfx942 FP8 FMHA. We'll keep your regression test with credit and extend it to the other variants with a magnitude check. This is tracked for the next AITER release. |
|
Thanks for the change. We re-checked the FlashMLA reference path in TensorRT-LLM, and their FP8 implementation seems to keep the softmax stats in FP32 while directly converting the softmax-weight fragment to FP8, without an extra P rescaling step before the cast: kernel path: https://github.com/NVIDIA/TensorRT-LLM/blob/09bad734e1972452e33fd62936b0444b361bb7b4/cpp/tensorrt_llm/kernels/flashMLA/flash_fwd_mla_kernel.h#L476-L481 |
|
Thank you Chefang for your in‑depth investigation. FlashMLA is normally used as our golden standard for implementation alignment. Therefore, it is recommended that we maintain the existing status for now. |
|
Thanks for checking the reference. My concern is the magnitude error in the constant-V repro: expected output is approximately 1, but AITER returns 0.349609; with scaling it returns 0.996094. Have you run this fixture through FP8 FlashMLA? Its online-softmax traversal and split-KV could affect when the weights are quantized, so the same cast doesn’t necessarily imply identical numerical behavior. Could we compare both paths against FP32 using magnitude error and agree on an acceptable tolerance? If FlashMLA also exhibits the loss, that would suggest a shared numerical issue rather than invalidate the repro. I’m happy with a source-generated fix instead of merging the patched binary. |
|
Thank you for the finding, #6422 copied this fix and expanded to more kernels, and merged, no more need to merge this pr |
Summary
Fix the gfx950 non-persistent A8W8 MLA decode kernel for 16 query heads by
scaling online-softmax numerators before E4M3 conversion, and add a
deterministic regression for the failure.
The fixture uses one logit at
0, 2,047 logits at-7, and an all-ones valuevector. Correct attention therefore returns an all-ones output regardless of
the score distribution. It also includes a uniform-score control to validate
the fixture and dispatch.
Motivation
The current kernel converts unscaled online-softmax numerators to E4M3 before
P@V. For this fixture,
exp(-7)rounds to zero in E4M3 even though the FP32softmax denominator retains the aggregate long-tail mass.
On gfx950 with current
main(9252f4672), the test loads:Observed means:
The original AITER result is within
7.67e-4max-absolute error of theunscaled-FP8 oracle and
0.650383away from ordinary FP32 attention.Static disassembly of the same code object shows
v_exp_f32, an FP32denominator reduction, and then direct
v_cvt_pk_fp8_f32instructions beforeFP8 P@V. There is no probability scaling instruction between exponentiation
and E4M3 conversion.
Independent corroboration: SGLang's gfx95 TileLang FP8 sparse MLA kernel
scales softmax numerators by the E4M3FN maximum (
448)before the FP8 P@V GEMM and
applies
1/448afterward.This is the same arithmetic modeled by the scaled-FP8 oracle in this
regression; FP32 attention remains the correctness reference.
Changes
mla_a8w8_qh16_qseqlen1_gqaratio16.coat the ISA level:448.0;v38:v45after the FP32 denominator accumulation and before all 24v_cvt_pk_fp8_f32instructions across the six repeated softmax blocks;1/448once in the final P@V normalization.failure when the output direction is preserved.
Testing
Hardware and software:
2.11.0+rocm7.2mainat9252f4672Command:
The exact original and patched code objects were tested in separate Python
processes inside the same pinned container.
LoadKernelconfirmed the targetpath in both arms.
Original code object
(
sha256:6a56860188249bd4d70ab339dcc18dfa18c4ee21b00c1759f0eb7c29b6f061ea):Patched code object
(
sha256:b1459224771c31a27e06d3d874f67874da448d7411d25fdf83cc0aae2faba3a0):The patched regression passed four times with identical values (the initial
run plus three repeats). The uniform-score control also passes.
Static checks:
python3 -m py_compile op_tests/test_mla_fp8_softmax_numerics.pygit diff --checkdocs/examples/isa_optimization/roundtrip.shon the patched object:.text,.rodata, metadata, and ELF target flags all round-trip identically.bytes LDS. The patch adds 27 instructions / 216 bytes of
.textwithoutincreasing the declared allocation.
Generator follow-up
The source or generator for this exact non-persistent HSACO is not present in
the public repository. This PR therefore includes an ISA-level code-object
patch so the repair is executable and the regression is green.
If this object is generated from a private or external source, please apply the
same arithmetic there and regenerate it to avoid the binary and generator
drifting. Sibling A8W8 MLA code objects using the same P@V scheme should also
be audited; this PR changes only the exact object exercised by the regression.
Performance
On the synthetic 2,048-token fixture, a same-container
torch.cuda.Eventmicrobenchmark (50 warmups, 10 samples x 500 launches) measured:
This is kernel-only evidence for this shape, not an engine-level benchmark.
Dependencies