Skip to content

[HIP] Fuse a 32-point Hadamard rotation into the MXFP4 per-1x32 quant and AR + RMSNorm epilogue - #6734

Merged
TennyWang1223 merged 6 commits into
ROCm:mainfrom
mjkvaak-amd:mxfp4-hadamard32-quant
Nov 6, 2026
Merged

TennyWang1223 merged 6 commits into
ROCm:mainfrom
mjkvaak-amd:mxfp4-hadamard32-quant

Conversation

@mjkvaak-amd

@mjkvaak-amd mjkvaak-amd commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds hadamard_rotate=True to the HIP per-1x32 MXFP4 quant and to the fused AR + RMSNorm + MXFP4 epilogue: each 32-element group is rotated by a normalized Hadamard matrix in registers before it is quantized. gfx950 only.

Motivation

MXFP4 shares one e8m0 scale per 32 values, so a single outlier channel flushes the rest of its block toward zero. Rotating each block by a normalized Hadamard matrix spreads the outlier across the block, and the same rotation applied to the weight leaves the GEMM unchanged: ((xH)(WH)^T = xW^T). Quark exports MXFP4 checkpoints with this online rotation (input_rotation).

Today the rotation needs a separate pass over HBM before the quant, and rotated layers lose the AR + RMSNorm + MXFP4 fusion. The consumer is vLLM's MXFP4 ASM GEMM path (vllm-project/vllm#63272), which applies this quant only for shapes tuned in AITER's a4w4 configs; the configs for Qwen3.8-2.4T's GDN in_proj_qkvz are in #7441.

Changes

  • Quant. per_1x32_mx_quant_hip, per_1x32_f4_quant_hip and dynamic_per_group_scaled_quant gain hadamard_rotate=False. With True, the output is the MXFP4 quantization of x.view(m, n // 32, 32) @ (scipy.linalg.hadamard(32) / sqrt(32)), computed in fp32 and rounded to x.dtype before the scale is taken. Scales, packing, shuffle, num_rows and num_rows_factor behave as without rotation. The caller rotates the weight the same way.
  • AR + RMSNorm. tensor_model_parallel_fused_allreduce_rmsnorm_quant(..., quant_type="mxfp4", hadamard_rotate=True) returns MXFP4 bytes and scales bit-identical to per_1x32_f4_quant_hip(normed, hadamard_rotate=True), where normed is the kernel's own RMSNorm output. The residual and the emit_bf16 side output stay unrotated. This covers the 1-stage, 2-stage and fallback paths; other quant types raise ValueError.
  • Mechanism.
    • In the quant kernel, one thread already owns a whole group at group_size == 32 (thread_data_size == 32). A new hadamard32 template parameter of dynamic_per_group_scaled_quant_kernel runs a 5-stage fp32 butterfly on that thread's 32 values before the abs-max, so loads and stores are unchanged.
    • In the AR epilogue, a group spans 32 / PACK_SIZE lanes. Butterfly stages below PACK_SIZE run in registers and the rest exchange values with __shfl_xor. The rotated values take the quant kernel's RoundUp e8m0 scale and hardware FP4 convert.
    • Both parameters default to false under if constexpr, so existing paths compile to the same kernels.
  • Not covered. The non-AR fused RMSNorm + quant kernels do not rotate. Rotation sizes other than 32 still need a separate pass.

Performance (if applicable)

Before: AR + RMSNorm, then a standalone rotated quant. After: the rotation fused into the AR epilogue. bf16, Gemma RMSNorm with emit_bf16, us per call (graph replay of 20 calls × 50).

Hardware Workload/configuration Before After Change
8× MI355X TP8, m = 1, n = 4096 9.36 7.60 −19%
8× MI355X TP8, m = 8, n = 4096 11.13 8.93 −20%
8× MI355X TP8, m = 32, n = 4096 12.52 9.79 −22%
8× MI355X TP8, m = 1, n = 8192 11.45 9.83 −14%
8× MI355X TP8, m = 8, n = 8192 13.31 11.21 −16%
8× MI355X TP8, m = 32, n = 8192 13.98 12.19 −13%

The fused rotated epilogue is also 0.5–0.7 us faster than the unrotated one at these shapes (8.34 / 9.49 / 10.29 / 10.40 / 11.77 / 12.72 us).

Standalone quant on one MI355X, bf16 input (run_perftest, us), plain vs Hadamard-32:

m n plain Hadamard-32 ratio
1 2048 1.99 1.94 0.97
1 8192 2.33 2.72 1.17
32 2048 3.13 3.59 1.15
32 8192 3.23 3.67 1.14
256 2048 3.36 3.74 1.11
256 8192 4.15 4.47 1.08
2048 2048 5.06 5.84 1.15
2048 8192 10.30 10.71 1.04
8192 2048 10.78 10.98 1.02
8192 8192 31.00 33.09 1.07

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X
  • Tested on MI355X (gfx950)

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. hadamard_rotate defaults to False, and the unrotated kernels are unchanged.

PR Self-Review

Reviewed revision

f06b94f

Behavior and intent

With hadamard_rotate=True, the HIP per-1x32 MXFP4 quant and the AR + RMSNorm + MXFP4 epilogue quantize each 32-element group after a normalized Hadamard-32 rotation, instead of the caller rotating in a separate HBM pass and giving up the AR fusion. With the default False, behavior and generated kernels are unchanged.

Validation and unverified scope

MI355X (gfx950), branch installed editable with PREBUILD_KERNELS=0 GPU_ARCHS=gfx950 so the modules are JIT-built from it.

python3 op_tests/test_quant_mxfp4_hadamard.py --perf
python3 op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py
python3 op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py -t 8 --stage both --emit-bf16 \
    -s 1,8192 4,8192 8,8192 16,8192 32,8192 8,7168 16,4096

On the tree rebased onto 0f61f2b, all 12 quant cases pass bit-exactly. Every rotated AR case at TP 2 and 4 (1-stage, 2-stage and fallback; with and without gemma_norm) is byte-identical to the standalone rotated quant, also with --stage both; the unrotated cases pass as before. TP8 passed before the rebase; on the rebased tree it runs in the ci:multi-gpu job. per_1x32_mx_quant_hip(..., scale_layout_m32k4=True, hadamard_rotate=True) now fails its assert. Timings are in Performance; they were taken before the rebase, which does not touch the kernels.

Unverified: MI250X and MI300X were not run. The rotated path is rejected there by design and its test cases are skipped; the unrotated kernels compile to the same code. End-to-end model accuracy with rotated checkpoints is validated on the vLLM side, not here.

PR-specific question

  • Architecture. gfx950 only. The rotation feeds the gfx950 hardware FP4 convert, so dynamic_per_group_scaled_quant and fused_allreduce_rmsnorm_mxfp4_quant reject hadamard_rotate on any other arch with AITER_CHECK(get_gpu_arch() == "gfx950").
  • Dtype. bf16 or fp16 input, fp4x2 output. The Python quant wrapper asserts quant_dtype == dtypes.fp4x2; the AR wrappers raise ValueError for any quant_type other than "mxfp4".
  • Shape. group_size == 32 without scale_layout_m32k4, checked by AITER_CHECK in the C++ entry; per_1x32_mx_quant_hip also asserts against scale_layout_m32k4, whose branch does not reach that check. Inside the kernel, static_asserts require fp4 output, group_size == 32 and thread_data_size == 32, so the rotation is only instantiated where one thread owns a whole group. m and n follow the unrotated quant's existing limits.
  • Default. hadamard_rotate=False everywhere and the template parameters default to false under if constexpr, so no existing caller reaches the new code.

Changed op tests

  • op_tests/test_quant_mxfp4_hadamard.py (new): checks that packed bytes and scales from per_1x32_f4_quant_hip(hadamard_rotate=True) are bit-identical to rotating in torch and then quantizing, for ragged and aligned m, bf16 and fp16, and shuffled and unshuffled scales. It also checks that the torch butterfly reference equals the matrix definition. --perf adds rotated vs plain timings. No existing test covers the rotated quant.
  • op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py: adds rotated cases on gfx950 for every shape, with and without gemma_norm, checking the fused epilogue's output byte for byte against the rotated standalone quant of its own bf16 side output. This is the only test of the shuffle-based rotation in the AR epilogue, which is separate code from the quant kernel's in-register rotation.

Co-authored-by: Cursor [email protected]

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6734 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

omirosh added a commit to omirosh/sglang that referenced this pull request Oct 21, 2026
…ojections

SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=1 rotates each 32-wide input block of the online MXFP4 GDN projections by the orthonormal Hadamard matrix. The weight is rotated once at load. The activation is rotated inside per_1x32_f4_quant_hip (ROCm/aiter#6734). The product does not change, and the MXFP4 error is lower.

Thinking-on GSM8K, 8 reps at temperature 1.0: plain MXFP4 makes the answers 10.7% longer than BF16 (p=0.0017 on accuracy). With the rotation, the answers are 2.1% longer, and the accuracy is the same as BF16 (p=0.62).

Co-authored-by: Cursor <[email protected]>
mjkvaak-amd added a commit to mjkvaak-amd/vllm-project that referenced this pull request Oct 23, 2026
…R's MXFP4 quant

Add LinearMethodBase.fuse_input_hadamard(layer, size), default False.
InputHadamardLinearMethod calls it after the wrapped method's
process_weights_after_loading and skips its own input rotation when the
method takes it over. Online MXFP4 and Quark OCP MX forward the call to
their MxFp4LinearKernel; AiterMxfp4LinearKernel accepts on the ASM GEMM
path at size 32 and passes hadamard_rotate=True to the HIP activation
quant (ROCm/aiter#6734). hadamard_rotate is only passed to AITER when
set, so older AITER keeps working as long as nothing fuses.

Also fix the fake implementation of gemm_with_dynamic_quant, whose
signature had drifted from the op.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd
mjkvaak-amd marked this pull request as ready for review October 23, 2026 09:01
@mjkvaak-amd
mjkvaak-amd requested a review from a team October 23, 2026 09:01
@github-actions github-actions Bot added the HIP label Oct 23, 2026
@mjkvaak-amd
mjkvaak-amd marked this pull request as draft October 23, 2026 10:05
@mjkvaak-amd mjkvaak-amd changed the title [HIP] Fuse a 32-point Hadamard rotation into the MXFP4 per-1x32 quant [HIP] Fuse a 32-point Hadamard rotation into the MXFP4 per-1x32 quant and AR + RMSNorm epilogue Oct 23, 2026
@mjkvaak-amd
mjkvaak-amd marked this pull request as ready for review October 23, 2026 10:25
@mjkvaak-amd
mjkvaak-amd force-pushed the mxfp4-hadamard32-quant branch from bc2aec9 to baab824 Compare October 26, 2026 13:55
omirosh added a commit to omirosh/sglang that referenced this pull request Oct 28, 2026
…mard-32

Plain MXFP4 on the Qwen3.5 / Qwen3.8 GDN in_proj_qkvz and out_proj makes
the thinking longer. On thinking-on GSM8K (8 reps at temperature 1.0),
the answers are 10.7% longer than BF16, and the accuracy drops from
0.9641 to 0.9597 (McNemar p = 0.0017).

SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD (default true) rotates each 32-wide
input block of these projections by the orthonormal Hadamard matrix. The
weight is rotated once at load. The activation is rotated inside
per_1x32_f4_quant_hip (ROCm/aiter#6734), on the Triton and the ASM path.
The product does not change, and the MXFP4 error is lower. With the
rotation, the answers are 2.1% longer than BF16, and the accuracy is the
same (p = 0.62). TPOT changes by 0.2% or less.

Without hadamard_rotate in AITER, the layer raises RuntimeError. Set the
variable to 0 to run plain MXFP4.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sglang that referenced this pull request Nov 4, 2026
The review asks to not check AITER for hadamard_rotate. The SGLang AITER
pin must have ROCm/aiter#6734 before this PR merges. An AITER without it
raises TypeError at the first rotated quant.

With SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0, apply() does not give
hadamard_rotate to AITER, so plain MXFP4 runs on each AITER.

The fallback test goes away. The gfx95x test always runs both rotations.

Co-authored-by: Cursor <[email protected]>
@mjkvaak-amd
mjkvaak-amd requested a review from zufayu November 4, 2026 08:13
@mjkvaak-amd
mjkvaak-amd force-pushed the mxfp4-hadamard32-quant branch from baab824 to 19af255 Compare November 4, 2026 08:25
@aiter-bot

aiter-bot commented Nov 4, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision f06b94f71785 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

With `hadamard_rotate=True`, the HIP per-1x32 MXFP4 quant and the AR + RMSNorm + MXFP4 epilogue quantize each 32-element group after a normalized Hadamard-32 rotation, instead of the caller rotating in a separate HBM pass and giving up the AR fusion. With the default `False`, behavior and generated kernels are unchanged.

Validation and unverified scope

MI355X (gfx950), branch installed editable with `PREBUILD_KERNELS=0 GPU_ARCHS=gfx950` so the modules are JIT-built from it.

```bash
python3 op_tests/test_quant_mxfp4_hadamard.py --perf
python3 op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py
python3 op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py -t 8 --stage both --emit-bf16 \
    -s 1,8192 4,8192 8,8192 16,8192 32,8192 8,7168 16,4096
```

On the tree rebased onto 0f61f2b95d, all 12 quant cases pass bit-exactly. Every rotated AR case at TP 2 and 4 (1-stage, 2-stage and fallback; with and without `gemma_norm`) is byte-identical to the standalone rotated quant, also with `--stage both`; the unrotated cases pass as before. TP8 passed before the rebase; on the rebased tree it runs in the `ci:multi-gpu` job. `per_1x32_mx_quant_hip(..., scale_layout_m32k4=True, hadamard_rotate=True)` now fails its assert. Timings are in Performance; they were taken before the rebase, which does not touch the kernels.

Unverified: MI250X and MI300X were not run. The rotated path is rejected there by design and its test cases are skipped; the unrotated kernels compile to the same code. End-to-end model accuracy with rotated checkpoints is validated on the vLLM side, not here.

PR-specific question

- **Architecture.** gfx950 only. The rotation feeds the gfx950 hardware FP4 convert, so `dynamic_per_group_scaled_quant` and `fused_allreduce_rmsnorm_mxfp4_quant` reject `hadamard_rotate` on any other arch with `AITER_CHECK(get_gpu_arch() == "gfx950")`.
- **Dtype.** bf16 or fp16 input, fp4x2 output. The Python quant wrapper asserts `quant_dtype == dtypes.fp4x2`; the AR wrappers raise `ValueError` for any `quant_type` other than `"mxfp4"`.
- **Shape.** `group_size == 32` without `scale_layout_m32k4`, checked by `AITER_CHECK` in the C++ entry; `per_1x32_mx_quant_hip` also asserts against `scale_layout_m32k4`, whose branch does not reach that check. Inside the kernel, `static_assert`s require fp4 output, `group_size == 32` and `thread_data_size == 32`, so the rotation is only instantiated where one thread owns a whole group. `m` and `n` follow the unrotated quant's existing limits.
- **Default.** `hadamard_rotate=False` everywhere and the template parameters default to `false` under `if constexpr`, so no existing caller reaches the new code.

Changed op tests

- `op_tests/test_quant_mxfp4_hadamard.py` (new): checks that packed bytes and scales from `per_1x32_f4_quant_hip(hadamard_rotate=True)` are bit-identical to rotating in torch and then quantizing, for ragged and aligned `m`, bf16 and fp16, and shuffled and unshuffled scales. It also checks that the torch butterfly reference equals the matrix definition. `--perf` adds rotated vs plain timings. No existing test covers the rotated quant.
- `op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py`: adds rotated cases on gfx950 for every shape, with and without `gemma_norm`, checking the fused epilogue's output byte for byte against the rotated standalone quant of its own bf16 side output. This is the only test of the shuffle-based rotation in the AR epilogue, which is separate code from the quant kernel's in-register rotation.

Co-authored-by: Cursor <[email protected]>

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

mjkvaak-amd added a commit to mjkvaak-amd/vllm-project that referenced this pull request Nov 4, 2026
…R's MXFP4 quant

Add LinearMethodBase.fuse_input_hadamard(layer, size), default False.
InputHadamardLinearMethod calls it after the wrapped method's
process_weights_after_loading and skips its own input rotation when the
method takes it over. Online MXFP4 and Quark OCP MX forward the call to
their MxFp4LinearKernel; AiterMxfp4LinearKernel accepts on the ASM GEMM
path at size 32 and passes hadamard_rotate=True to the HIP activation
quant (ROCm/aiter#6734). hadamard_rotate is only passed to AITER when
set, so older AITER keeps working as long as nothing fuses.

Also fix the fake implementation of gemm_with_dynamic_quant, whose
signature had drifted from the op.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

ROCm/aiter PR #6734 — [HIP] Fuse a 32-point Hadamard rotation into the MXFP4 per-1x32 quant and AR + RMSNorm epilogue

Fuses a 32-point normalized Hadamard rotation into the gfx950 MXFP4 per-1x32 quant kernel and the AR+RMSNorm+MXFP4 epilogue behind a new opt-in hadamard_rotate flag, so rotated MXFP4 checkpoints no longer need a separate HBM rotation pass and keep the all-reduce fusion.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled) and no gfx950 GPU on this box (8× gfx942/MI300X) to hand-run the target op_tests/test_quant_mxfp4_hadamard.py, whose rotated path is gfx950-only by design; the target exists and default CI collects it, so this is an environment gap, not a PR defect.
Perf (advisory): NOT RUN — same environment gap: no gfx950 GPU here (8× gfx942) and auto-validation disabled, so neither the perf stage nor a hand run of the target's harness (python3 op_tests/test_quant_mxfp4_hadamard.py --perf) can execute the rotated path; the PR's −13%..−22% fused-path and +2%..+17% standalone-quant numbers remain author-measured only.

⚠️ [verified] aiter/ops/quant.py:561 — the pre-existing scale_layout_m32k4 branch of per_1x32_mx_quant_hip calls dynamic_per_group_scaled_quant(y, x, scale, 32, num_rows=None, scale_layout_m32k4=True) without hadamard_rotate, so per_1x32_mx_quant_hip(x, scale_layout_m32k4=True, hadamard_rotate=True) silently returns unrotated MXFP4 bytes while the caller rotates the weights the same way — wrong GEMM output, no crash, no error — and the C++ AITER_CHECK(!scale_layout_m32k4) this PR added at csrc/kernels/quant_kernels.cu:1598 for exactly that combination never fires because the flag never reaches C++ on that branch. Author must forward hadamard_rotate into that call so the C++ check rejects the combination, or assert the combination in the wrapper.
⚠️ [verified] The shuffle-based rotation in the AR epilogue (ar_mxfp4_hadamard32_quant in csrc/include/custom_all_reduce.cuh — separate code from the quant kernel's in-register rotation) is exercised only by op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py, which .github/scripts/aiter_test.sh never collects in default CI (MULTIGPU=FALSE scans only op_tests/*.py at depth 1) and which runs only under the ci:multi-gpu label this PR does not carry; the rotated cases it adds are Gemma+emit_bf16 only, so the GEMMA_NORM=false × HADAMARD32=true template instantiation ships unexercised by any test or CI job and a regression in it would surface only in downstream serving. Author must add the ci:multi-gpu label and extend the rotated cases to gemma_norm=False (the existing dequant comparison already covers it) before merge.
⚠️ [verified] The diff is STALE against merge target 0f61f2b: plain git apply fails at aiter/dist/device_communicators/custom_all_reduce.py:2554, and although a 3-way apply succeeds, that file has since moved 644 lines on main (new FlyDSL one-shot allreduce, IPC handle refactoring), so every CI result on this PR describes a tree that no longer exists and the hadamard_rotate threading has not been exercised against main's current allreduce routing. Author must rebase onto current main and re-run the multigpu suite (TP 2/4/8, 1-stage/2-stage/fallback) on the rebased tree before merge.
📝 [verified] The PR's own table shows the rotated fused epilogue 0.5–0.7 us faster than the unrotated one at every measured shape, because the rotated branch in csrc/include/custom_all_reduce.cuh quantizes via the hardware opus::fp32_to_fp4_packed_x2 convert while the unrotated branch keeps the per-element software ar_mxfp4_encode ladder — the existing unrotated epilogue leaves ~0.5–0.7 us per call on the table on gfx950. Reviewer should ask whether a follow-up switches the unrotated epilogue to the same hardware convert.
📝 [verified] The PR states the a4w4 tuned configs that let vLLM route Qwen3.8-2.4T's GDN in_proj_qkvz shapes to the MXFP4 ASM GEMM live in a separate [Config] PR, but no link or number is given — until that lands, hadamard_rotate stays dormant downstream because no consumer passes it. Reviewer should ask for the Config PR link so the activation path is reviewable.

mjkvaak-amd and others added 4 commits November 4, 2026 11:51
Add `hadamard_rotate` to per_1x32_mx_quant_hip, per_1x32_f4_quant_hip and
dynamic_per_group_scaled_quant. When set (fp4x2 output, group size 32),
each 32-element group is rotated by the normalized Sylvester Hadamard
matrix in registers before its amax is taken, so the output equals
quantizing an explicitly rotated input. Existing instantiations are
unchanged (new `hadamard32` template parameter defaults to false).

Adds op_tests/test_quant_mxfp4_hadamard.py.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
per_1x32_f4_quant_hip allocates its shuffled scale buffer with torch.empty,
so the padding the kernel does not write differs from the test's
zero-filled buffer. The packed output is fully written and stays compared.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
Fold the butterfly-vs-matrix check into the fused test and test three
shapes instead of six. Drop the GEMM error and rejection tests: the
first restates the math the exact match already pins down, the second
needs a subprocess to observe an AITER_CHECK abort.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
hadamard_rotate=True on fused_allreduce_rmsnorm_quant (MXFP4) quantizes
the normed output rotated per 32-element group, bit-exact with
per_1x32_f4_quant_hip(normed, hadamard_rotate=True). The bf16 side output
and the residual stay unrotated. Covers the 1-stage, 2-stage and fallback
paths.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
mjkvaak-amd and others added 2 commits November 4, 2026 11:51
The rotated quant and AR epilogue use the gfx950 FP4 convert, which opus
stubs to zeros on other targets. Check the arch at both entry points and
skip the rotated test cases elsewhere.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
…ut Gemma

The scale_layout_m32k4 branch of per_1x32_mx_quant_hip did not pass
hadamard_rotate on, so the combination returned unrotated bytes. The
rotated AR cases now also run with plain RMSNorm weights.

Signed-off-by: Mikko Tukiainen <[email protected]>
Co-authored-by: Cursor <[email protected]>
@mjkvaak-amd
mjkvaak-amd force-pushed the mxfp4-hadamard32-quant branch from 19af255 to f06b94f Compare November 4, 2026 12:08
@mjkvaak-amd mjkvaak-amd added the ci:multi-gpu Trigger multi-GPU op tests on PR label Nov 4, 2026
@mjkvaak-amd

Copy link
Copy Markdown
Contributor Author

ROCm/aiter PR #6734 — [HIP] Fuse a 32-point Hadamard rotation into the MXFP4 per-1x32 quant and AR + RMSNorm epilogue

Fuses a 32-point normalized Hadamard rotation into the gfx950 MXFP4 per-1x32 quant kernel and the AR+RMSNorm+MXFP4 epilogue behind a new opt-in hadamard_rotate flag, so rotated MXFP4 checkpoints no longer need a separate HBM rotation pass and keep the all-reduce fusion.

Review (advisory): ⚠️ NEEDS WORK Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled) and no gfx950 GPU on this box (8× gfx942/MI300X) to hand-run the target op_tests/test_quant_mxfp4_hadamard.py, whose rotated path is gfx950-only by design; the target exists and default CI collects it, so this is an environment gap, not a PR defect. Perf (advisory): NOT RUN — same environment gap: no gfx950 GPU here (8× gfx942) and auto-validation disabled, so neither the perf stage nor a hand run of the target's harness (python3 op_tests/test_quant_mxfp4_hadamard.py --perf) can execute the rotated path; the PR's −13%..−22% fused-path and +2%..+17% standalone-quant numbers remain author-measured only.

⚠️ [verified] aiter/ops/quant.py:561 — the pre-existing scale_layout_m32k4 branch of per_1x32_mx_quant_hip calls dynamic_per_group_scaled_quant(y, x, scale, 32, num_rows=None, scale_layout_m32k4=True) without hadamard_rotate, so per_1x32_mx_quant_hip(x, scale_layout_m32k4=True, hadamard_rotate=True) silently returns unrotated MXFP4 bytes while the caller rotates the weights the same way — wrong GEMM output, no crash, no error — and the C++ AITER_CHECK(!scale_layout_m32k4) this PR added at csrc/kernels/quant_kernels.cu:1598 for exactly that combination never fires because the flag never reaches C++ on that branch. Author must forward hadamard_rotate into that call so the C++ check rejects the combination, or assert the combination in the wrapper. ⚠️ [verified] The shuffle-based rotation in the AR epilogue (ar_mxfp4_hadamard32_quant in csrc/include/custom_all_reduce.cuh — separate code from the quant kernel's in-register rotation) is exercised only by op_tests/multigpu_tests/test_fused_ar_rms_mxfp4_quant.py, which .github/scripts/aiter_test.sh never collects in default CI (MULTIGPU=FALSE scans only op_tests/*.py at depth 1) and which runs only under the ci:multi-gpu label this PR does not carry; the rotated cases it adds are Gemma+emit_bf16 only, so the GEMMA_NORM=false × HADAMARD32=true template instantiation ships unexercised by any test or CI job and a regression in it would surface only in downstream serving. Author must add the ci:multi-gpu label and extend the rotated cases to gemma_norm=False (the existing dequant comparison already covers it) before merge. ⚠️ [verified] The diff is STALE against merge target 0f61f2b: plain git apply fails at aiter/dist/device_communicators/custom_all_reduce.py:2554, and although a 3-way apply succeeds, that file has since moved 644 lines on main (new FlyDSL one-shot allreduce, IPC handle refactoring), so every CI result on this PR describes a tree that no longer exists and the hadamard_rotate threading has not been exercised against main's current allreduce routing. Author must rebase onto current main and re-run the multigpu suite (TP 2/4/8, 1-stage/2-stage/fallback) on the rebased tree before merge. 📝 [verified] The PR's own table shows the rotated fused epilogue 0.5–0.7 us faster than the unrotated one at every measured shape, because the rotated branch in csrc/include/custom_all_reduce.cuh quantizes via the hardware opus::fp32_to_fp4_packed_x2 convert while the unrotated branch keeps the per-element software ar_mxfp4_encode ladder — the existing unrotated epilogue leaves ~0.5–0.7 us per call on the table on gfx950. Reviewer should ask whether a follow-up switches the unrotated epilogue to the same hardware convert. 📝 [verified] The PR states the a4w4 tuned configs that let vLLM route Qwen3.8-2.4T's GDN in_proj_qkvz shapes to the MXFP4 ASM GEMM live in a separate [Config] PR, but no link or number is given — until that lands, hadamard_rotate stays dormant downstream because no consumer passes it. Reviewer should ask for the Config PR link so the activation path is reviewable.

Thanks, addressed in f06b94f:

  1. scale_layout_m32k4 with hadamard_rotate. Right, that branch did not pass the flag on. per_1x32_mx_quant_hip now asserts not hadamard_rotate there, so the combination fails instead of returning unrotated bytes.
  2. Rotated AR coverage. The rotated cases now run with and without gemma_norm, so both HADAMARD32=true instantiations are byte-compared against the standalone rotated quant. Added the ci:multi-gpu label.
  3. Stale diff. Rebased onto 0f61f2b (no conflicts). hadamard_rotate still reaches every MXFP4 route on main: the captured and eager custom-AR paths and the AR + RMSNorm + separate-quant fallback. The FlyDSL one-shot allreduce has no MXFP4 epilogue, and _require_old_arch_fused_kernels only rejects gfx1250. The multi-GPU suite passes on the rebased tree; results are in the PR description.
  4. Software encode in the unrotated epilogue. The unrotated MXFP4 epilogue also runs on gfx942, where the hardware FP4 convert does not exist, so it keeps the portable ar_mxfp4_encode. That ladder rounds ties away from zero, where the hardware convert rounds to nearest even, so switching gfx950 over needs an arch branch and changes some unrotated output bytes. That belongs in a separate perf PR.
  5. Config PR. [Config] Add gfx950 a4w4 GEMM configs for Qwen3.8-2.4T GDN in_proj_qkvz at TP8 #7441; linked in the description.

@zufayu
zufayu requested a review from junhaha666 November 4, 2026 13:07
@zufayu

zufayu commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@TennyWang1223 aiter-bot clean we can move to human review

@TennyWang1223 TennyWang1223 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TennyWang1223
TennyWang1223 merged commit 55645da into ROCm:main Nov 6, 2026
jiangyon-amd added a commit to jiangyon-amd/aiter that referenced this pull request Nov 6, 2026
Add aiter.ops.flydsl.flydsl_rot_quant(x, RS, shuffle_scales=): one gfx950
kernel that rotates each RS-wide block of a bf16 activation by a normalized
Sylvester Hadamard matrix (RS in {32, 64, 128}), quantizes the result to
MXFP4 with the default RoundUp e8m0 scale, and optionally writes the scales
in the CK layout that gemm_a4w4 consumes. The output equals
per_1x32_f4_quant applied to the bf16-rounded rotated tensor.

Rotated MXFP4 checkpoints fold the rotation into the weights, so the
activation of every rotated projection needs it online. Unfused, that is a
Hadamard matmul followed by a quant pass. The HIP per-1x32 quant fuses a
32-point rotation since ROCm#6734; this op adds 64 and 128 in the same single
pass and agrees with the HIP path byte for byte at 32, apart from groups
under its amax floor.

One thread owns one RS-wide block, so the FWHT runs in registers without
cross-lane traffic. At RS=64 the 1/8 normalization is applied to each
group's amax and to the conversion exponent instead of to every element.

MI350X, K=4096, RS=64, CK-layout scales, CUDA graph: 1.8x (M=32) to 2.9x
(M>=1024) over a bf16 Hadamard matmul plus per_1x32_f4_quant_hip.

op_tests/test_flydsl_rot_quant.py checks the fp4 bytes and e8m0 scales
exactly against per_1x32_f4_quant (RS 32/64/128, both scale layouts, M
1..16384, K 2880/4096/7168, zero, tiny and NaN rows), parity with the HIP
path at RS=32, and the CK scale layout end to end through gemm_a4w4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jiangyon-amd added a commit to jiangyon-amd/aiter that referenced this pull request Nov 9, 2026
Add aiter.ops.flydsl.flydsl_rot_quant(x, RS, shuffle_scales=): one gfx950
kernel that rotates each RS-wide block of a bf16 activation by a normalized
Sylvester Hadamard matrix (RS in {32, 64, 128}), quantizes the result to
MXFP4 with the default RoundUp e8m0 scale, and optionally writes the scales
in the CK layout that gemm_a4w4 consumes. The output equals
per_1x32_f4_quant applied to the bf16-rounded rotated tensor.

Rotated MXFP4 checkpoints fold the rotation into the weights, so the
activation of every rotated projection needs it online. Unfused, that is a
Hadamard matmul followed by a quant pass. The HIP per-1x32 quant fuses a
32-point rotation since ROCm#6734; this op adds 64 and 128 in the same single
pass and agrees with the HIP path byte for byte at 32, apart from groups
under its amax floor.

One thread owns one RS-wide block, so the FWHT runs in registers without
cross-lane traffic. At RS=64 the 1/8 normalization is applied to each
group's amax and to the conversion exponent instead of to every element.

MI350X, K=4096, RS=64, CK-layout scales, CUDA graph: 1.8x (M=32) to 2.9x
(M>=1024) over a bf16 Hadamard matmul plus per_1x32_f4_quant_hip.

op_tests/test_flydsl_rot_quant.py checks the fp4 bytes and e8m0 scales
exactly against per_1x32_f4_quant (RS 32/64/128, both scale layouts, M
1..16384, K 2880/4096/7168, zero, tiny and NaN rows), parity with the HIP
path at RS=32, and the CK scale layout end to end through gemm_a4w4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mjkvaak-amd added a commit to mjkvaak-amd/vllm-project that referenced this pull request Nov 12, 2026
…R's MXFP4 quant

Add LinearMethodBase.fuse_input_hadamard(layer, size), default False.
InputHadamardLinearMethod calls it after the wrapped method's
process_weights_after_loading and skips its own input rotation when the
method takes it over. Online MXFP4 and Quark OCP MX forward the call to
their MxFp4LinearKernel; AiterMxfp4LinearKernel accepts on the ASM GEMM
path at size 32 and passes hadamard_rotate=True to the HIP activation
quant (ROCm/aiter#6734). hadamard_rotate is only passed to AITER when
set, so older AITER keeps working as long as nothing fuses.

Also fix the fake implementation of gemm_with_dynamic_quant, whose
signature had drifted from the op.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Mikko Tukiainen <[email protected]>
jiangyon-amd added a commit to jiangyon-amd/aiter that referenced this pull request Nov 14, 2026
Add aiter.ops.flydsl.flydsl_rot_quant(x, RS, shuffle_scales=): one gfx950
kernel that rotates each RS-wide block of a bf16 activation by a normalized
Sylvester Hadamard matrix (RS in {32, 64, 128}), quantizes the result to
MXFP4 with the default RoundUp e8m0 scale, and optionally writes the scales
in the CK layout that gemm_a4w4 consumes. The output equals
per_1x32_f4_quant applied to the bf16-rounded rotated tensor.

Rotated MXFP4 checkpoints fold the rotation into the weights, so the
activation of every rotated projection needs it online. Unfused, that is a
Hadamard matmul followed by a quant pass. The HIP per-1x32 quant fuses a
32-point rotation since ROCm#6734; this op adds 64 and 128 in the same single
pass and agrees with the HIP path byte for byte at 32, apart from groups
under its amax floor.

One thread owns one RS-wide block, so the FWHT runs in registers without
cross-lane traffic. At RS=64 the 1/8 normalization is applied to each
group's amax and to the conversion exponent instead of to every element.

MI350X, K=4096, RS=64, CK-layout scales, CUDA graph: 1.8x (M=32) to 2.9x
(M>=1024) over a bf16 Hadamard matmul plus per_1x32_f4_quant_hip.

op_tests/test_flydsl_rot_quant.py checks the fp4 bytes and e8m0 scales
exactly against per_1x32_f4_quant (RS 32/64/128, both scale layouts, M
1..16384, K 2880/4096/7168, zero, tiny and NaN rows), parity with the HIP
path at RS=32, and the CK scale layout end to end through gemm_a4w4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yadaish pushed a commit that referenced this pull request Nov 17, 2026
…e and MoE stage-1 inputs (flydsl_rot_quant) (#4549)

* [FlyDSL] Fused online Hadamard rotation + MXFP4 quantization

Add aiter.ops.flydsl.flydsl_rot_quant(x, RS, shuffle_scales=): one gfx950
kernel that rotates each RS-wide block of a bf16 activation by a normalized
Sylvester Hadamard matrix (RS in {32, 64, 128}), quantizes the result to
MXFP4 with the default RoundUp e8m0 scale, and optionally writes the scales
in the CK layout that gemm_a4w4 consumes. The output equals
per_1x32_f4_quant applied to the bf16-rounded rotated tensor.

Rotated MXFP4 checkpoints fold the rotation into the weights, so the
activation of every rotated projection needs it online. Unfused, that is a
Hadamard matmul followed by a quant pass. The HIP per-1x32 quant fuses a
32-point rotation since #6734; this op adds 64 and 128 in the same single
pass and agrees with the HIP path byte for byte at 32, apart from groups
under its amax floor.

One thread owns one RS-wide block, so the FWHT runs in registers without
cross-lane traffic. At RS=64 the 1/8 normalization is applied to each
group's amax and to the conversion exponent instead of to every element.

MI350X, K=4096, RS=64, CK-layout scales, CUDA graph: 1.8x (M=32) to 2.9x
(M>=1024) over a bf16 Hadamard matmul plus per_1x32_f4_quant_hip.

op_tests/test_flydsl_rot_quant.py checks the fp4 bytes and e8m0 scales
exactly against per_1x32_f4_quant (RS 32/64/128, both scale layouts, M
1..16384, K 2880/4096/7168, zero, tiny and NaN rows), parity with the HIP
path at RS=32, and the CK scale layout end to end through gemm_a4w4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] rot_quant: one MXFP4 group per lane

Split each RS-wide block across RS/32 adjacent lanes. Every lane runs the
first five FWHT stages on its 32 values in registers, and the lanes finish
the remaining log2(RS/32) stages with xor shuffles in the same stage order,
so the output is unchanged byte for byte. A lane now owns exactly one MXFP4
group: its scale stays thread-local, VGPRs drop from 101/228 to 60 at
RS=64/128, and small M spreads over 2-4x more lanes.

MI350X, K=4096, CK-layout scales, CUDA graph: RS=64 is 1.13-1.26x and
RS=128 1.15-1.77x faster than the previous revision; RS=32 is unchanged.
CTA size and the SLP setting were re-swept for the new mapping and kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] rot_quant: MoE stage-1 input with sorted scales

Add flydsl_rot_quant_moe_sort(x, sorted_ids, num_valid_ids, topk,
block_size, RS): the rotated MXFP4 quantization of the MoE stage-1 input
with its scales already sorted for the MoE GEMMs, i.e.
fused_dynamic_mxfp4_quant_moe_sort applied to the rotated tensor (without
that op's amax floor). Without it a rotated MoE layer runs a rotation pass
before the quant-and-sort kernel.

For small batches one kernel takes a thread per (sorted row, group):
valid routes rotate and quantize their token's group and scatter the scale
to the sorted row in the mxfp4_moe_sort_fwd layout, padding rows exit.
1024-thread CTAs keep the cost of the exiting threads down. Because a
token is quantized once per route, past M * topk * K = 2^21 the op instead
runs flydsl_rot_quant once and mxfp4_moe_sort_fwd. mxfp4_moe_sort_fwd loses
the last token's final scales when K // 32 is not a multiple of 4, so
those K always take the fused kernel.

MI350X, E=128, topk=8, CUDA graph: 1.3-2.8x faster than a Hadamard matmul
followed by fused_dynamic_mxfp4_quant_moe_sort; at K=2048 within ~0.5 us
of the unrotated quant-and-sort.

The op test gains test_rot_quant_moe_sort: fp4 bytes and sorted scales
compared exactly with the torch reference for K 2880/4096/7168, RS
32/64/128 and M 1..16384.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] rot_quant: pre-review fixes

- flydsl_rot_quant_moe_sort takes token_num in the position
  fused_dynamic_mxfp4_quant_moe_sort has it and rejects a stage-2 input;
  rotation_size and shuffle (were RS and shuffle_scales) are keyword-only.
- Skip the padding slots of a num_local_tokens sort (topk << 24 | count,
  a real token): M=64 with 40 local tokens 8.6 -> 5.8 us.
- Write 0 to the MoE scale padding columns, as mxfp4_moe_sort_fwd does.
- K // 32 not a multiple of 4 now takes the two-pass path as well, with
  zero-padded scale columns to avoid #7646: K=2880 M=16384 141.6 -> 42.4 us.
- Launch under the input's device.
- Set the no-SLP compile hint directly; one helper for the CK padded
  scale columns.
- Test: block_m 16/32/64 and counted sorts in the MoE check, padding
  columns compared, per-candidate column names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] rot_quant: review follow-ups

- MoE: stop writing the scale padding columns. As for
  fused_dynamic_mxfp4_quant_moe_sort, only the first K // 32 columns of
  valid-route rows are defined; mxfp4_moe_sort_fwd's scatter store leaves the
  padding columns unwritten, so the two-pass path never matched a "0" claim.
- Merge the no-SLP hint into existing llvm_options instead of replacing them.
- Module docstring shows the keyword API; note that the #7646 padding goes
  away with #7653.
- Test: extra block sizes and counted sorts only for M <= 1024 (48 -> 34 s).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] rot_quant: keep padded K on the fused MoE kernel longer

When K // 32 is not a multiple of 4 the two-pass path also pads the scales
for #7646, which moves its crossover with the fused kernel about 8x higher.
Switch at M * topk * K > 2^24 for those K and keep 2^21 otherwise.
K=2880, rotation size 64, MI350X: 1.27-1.68x faster for M * topk from 768 to
4096; other K are unchanged. Over 544 measured points (K 2048-7168, every
rotation size, topk 4 and 8) the dispatch is within 0.7% of the faster path
on average, against 2.4% before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] rot_quant: drop the #7646 padding now that #7653 is in main

mxfp4_moe_sort_fwd keeps the last row's tail scales since #7653, so the
MoE two-pass path no longer pads the scale rows, and the 2^24 threshold
that compensated for the padding goes too. With the fixed sort the
padded-K dims cross over where the others do: one 2^21 switch for every K
is within 5% of the faster path on 567 of 600 measured points (MI350X,
K 2048-7168, every rotation size, topk 4 and 8), 0.9% off on average.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 17, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 17, 2026
The final review of the branch estimates that the rotation adds about
100 VALU instructions to each quant round. Two changes keep the same bits
with fewer instructions:

- The cross-lane stages compute -b + a in the upper lane, not a - b.
  The partner value then has one use, so its DPP move can fold into the add.
- _quad_scale packs the rotated values to bf16 one time, then unpacks them
  for the amax. It does not round each value and then pack again.

A CPU model of the new order gives the same bf16 values as the order of
ROCm/aiter#6734 for 2^20 values of each input
kind, and for blocks of signed zeros.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 18, 2026
…nt_x by Hadamard-32

sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32. The activation must get the same
rotation before its MXFP4 quant.

- Add hadamard32_quad to mono/ops.py. It rotates a 1 x 32 block that lies on
  4 adjacent lanes. It adds in the order of hadamard32_rotate of
  ROCm/aiter#6734, so the bf16 values are the same
  bit for bit.
- Add the h32 flag to quant_x and _quad_scale in layer.py and in
  mono/stages/moe.py. The flag is off by default, so the plain builds do not
  change.
- Add check_quant.py and TestQwen38MoeQuant. The check compares the rotation
  and the LDS rows of quant_x with per_1x32_f4_quant_hip, plain and rotated,
  bit for bit. The rotation inputs have an exponent for each element, so the
  f32 sums round and a changed add order shows.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 18, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 28, 2026
…nt_x by Hadamard-32

sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32. The activation must get the same
rotation before its MXFP4 quant.

- Add hadamard32_quad to mono/ops.py. It rotates a 1 x 32 block that lies on
  4 adjacent lanes. It adds in the order of hadamard32_rotate of
  ROCm/aiter#6734, so the bf16 values are the same
  bit for bit.
- Add the h32 flag to quant_x and _quad_scale in layer.py and in
  mono/stages/moe.py. The flag is off by default, so the plain builds do not
  change.
- Add check_quant.py and TestQwen38MoeQuant. The check compares the rotation
  and the LDS rows of quant_x with per_1x32_f4_quant_hip, plain and rotated,
  bit for bit. The rotation inputs have an exponent for each element, so the
  f32 sums round and a changed add order shows.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 28, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 30, 2026
…nt_x by Hadamard-32

sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32. The activation must get the same
rotation before its MXFP4 quant.

- Add hadamard32_quad to mono/ops.py. It rotates a 1 x 32 block that lies on
  4 adjacent lanes. It adds in the order of hadamard32_rotate of
  ROCm/aiter#6734, so the bf16 values are the same
  bit for bit.
- Add the h32 flag to quant_x and _quad_scale in layer.py and in
  mono/stages/moe.py. The flag is off by default, so the plain builds do not
  change.
- Add check_quant.py and TestQwen38MoeQuant. The check compares the rotation
  and the LDS rows of quant_x with per_1x32_f4_quant_hip, plain and rotated,
  bit for bit. The rotation inputs have an exponent for each element, so the
  f32 sums round and a changed add order shows.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Nov 30, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Dec 1, 2026
…nt_x by Hadamard-32

sgl-project/sglang#46059 rotates the weights of the
MXFP4 GDN projections by Hadamard-32. The activation must get the same
rotation before its MXFP4 quant.

- Add hadamard32_quad to mono/ops.py. It rotates a 1 x 32 block that lies on
  4 adjacent lanes. It adds in the order of hadamard32_rotate of
  ROCm/aiter#6734, so the bf16 values are the same
  bit for bit.
- Add the h32 flag to quant_x and _quad_scale in layer.py and in
  mono/stages/moe.py. The flag is off by default, so the plain builds do not
  change.
- Add check_quant.py and TestQwen38MoeQuant. The check compares the rotation
  and the LDS rows of quant_x with per_1x32_f4_quant_hip, plain and rotated,
  bit for bit. The rotation inputs have an exponent for each element, so the
  f32 sums round and a changed add order shows.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sgl-amd-mono that referenced this pull request Dec 1, 2026
…n the README

- Section 2 tells how the qh and oh builds rotate the activation of the
  MXFP4 GDN projections of sgl-project/sglang#46059,
  in the order of ROCm/aiter#6734.
- Section 5 refuses only an unknown quant method or state now. _build makes
  a launch for each format of the projections.
- Section 6 adds the quant check, and the e2e tests run the default
  rotation of SGLang.

Co-authored-by: Cursor <[email protected]>
omirosh added a commit to omirosh/sglang that referenced this pull request Dec 1, 2026
…ontainers

A rocm720 image built before docker/rocm.Dockerfile set
SGLANG_ROCM_GDN_ONLINE_MXFP4_HADAMARD=0 does not have the flag. Its AITER
has no hadamard_rotate (ROCm/aiter#6734), so the
online MXFP4 GDN tests fail there with a TypeError.
amd_ci_start_container.sh now sets the flag for --rocm-version rocm720.
Remove it with the pin bump of the rocm720 stage.

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:multi-gpu Trigger multi-GPU op tests on PR HIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants