Skip to content

[AMD] [GLM-5.3-Flash Day 0] Route mHC through AITER on gfx950 - #37626

Closed
Raiden-Makoto wants to merge 4 commits into
sgl-project:xinyuan/glm-5.3-flash-supportfrom
Raiden-Makoto:RM/glm53-enablement
Closed

Raiden-Makoto wants to merge 4 commits into
sgl-project:xinyuan/glm-5.3-flash-supportfrom
Raiden-Makoto:RM/glm53-enablement

Conversation

@Raiden-Makoto

@Raiden-Makoto Raiden-Makoto commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

GLM-5.3-Flash uses mHC in all 45 decoder layers (hc_mult=4, hidden_size=4096). The support branch already carries the flattened mHC state contract and MHCLayerCommunicator, but hc_pre and hc_post have no AITER dispatch: enabling SGLANG_USE_AITER=1 still leaves them on TileLang when its flags are set, or on the Torch fallback otherwise.

This is a Day-0 correctness blocker on gfx950, not a performance-only path. Every attention and FFN sublayer crosses an mHC pre/post boundary before DSA, KDA, or MoE can produce a model output.

Condition Before With this PR
HIP + gfx95 + SGLANG_USE_AITER=1 no AITER mHC route aiter.ops.mhc.mhc_pre / mhc_post
AITER symbol missing no probe one warning, latch disabled, Torch fallback
AITER runtime failure request failure one warning, latch disabled, Torch fallback
HIP + DeepGEMM mHC flag reaches NVIDIA-only prenorm path rejected by the backend gate
non-HIP TileLang/DeepGEMM existing optimized route unchanged

The AITER imports stay lazy because this module is imported during model-registry discovery. No AITER symbol is required until the gfx950 runtime actually selects this backend.

Scope

python/sglang/kernels/ops/layernorm/mhc.py is the only production file changed.

  • Add the HIP + gfx95 + AITER dispatch and failure latch.
  • Gate TileLang mHC pre/post and DeepGEMM prenorm to their non-HIP route.
  • Preserve the existing Torch, TileLang, gfx1250, communicator, model, and tensor contracts.
  • Add one CPU dispatch test, one gfx950 kernel/flow test, and one checkpoint-driven manual test.

The fused mhc_post_pre boundary is intentionally untouched. It is a later launch-fusion optimization; this PR enables the standalone mhc_post -> mhc_pre sequence required for correctness. DSA, k-pool, MLA, MoE, CUDA graphs, and full-model serving are outside this PR.

Test plan

Docker: rocm/sgl-dev:v0.5.18-rocm720-mi35x-20260901.
Base: xinyuan/glm-5.3-flash-support @ 545bd6f839.
The same three test files were run in both arms; mhc.py is the only variable.

Arm Result
Baseline CPU dispatch: 1 passed, 5 errors; every AITER-specific gfx950/checkpoint case fails because _try_aiter_mhc_pre / _try_aiter_mhc_post do not exist. The checkpoint-only tensor audit passes.
This PR CPU dispatch: 6 passed; isolated gfx950: 3 passed; checkpoint-driven: 3 passed.

The gfx950 arm covers production hidden_size=4096, hc_mult=4, token counts 0/1/8/17/32/64/128, 2 and 20 Sinkhorn iterations, norm fused/unfused, deterministic replay, and the complete attention-to-FFN pre/post flow.

The checkpoint arm uses zai-org/GLM-5.3-Flash and amd/GLM-5.3-Flash-Quark-MXFP4@b5688f2549 without loading either model. It verifies all 270 mHC tensors are complete and byte-identical, runs every real attention and FFN parameter set across layers 0-44 through AITER against the Torch oracle, and runs the complete two-sublayer flow for every layer.

Check Detail
Registration CPU logic uses register_cpu_ci(suite="base-a-test-cpu"); gfx950 coverage uses register_amd_ci(suite="stage-b-test-1-gpu-small-amd-mi35x")
pre-commit all hooks pass on all four files, including registered-test CI validation
Accuracy not measured — GLM-5.3-Flash still depends on the remaining Day-0 enablement PRs before server-level accuracy is meaningful
Speed not measured — this PR establishes standalone mHC correctness and does not add post/pre fusion

CI States

Latest PR Test (Base): ❌ Run #33835290186
Latest PR Test (Extra): ❌ Run #33835290053
Latest PR Test (AMD ROCm 7.2): ❌ Run #33835290197

Route GLM-5.3-Flash mHC through AITER with safe Torch fallback and add isolated production-dimension and checkpoint-driven coverage.
@Raiden-Makoto Raiden-Makoto changed the title [AMD] [GLM-5.3-Flash Day 0] Enable mHC with AITER on gfx950 [AMD] [GLM-5.3-Flash Day 0] Route mHC through AITER on gfx950 Sep 2, 2026
@Raiden-Makoto
Raiden-Makoto marked this pull request as ready for review September 2, 2026 18:38
Jacob0226 and others added 2 commits September 3, 2026 08:27
The k-pool indexer is CUDA-only end to end. forward_cuda raises
NotImplementedError off CUDA, the paged (decode) path picks between a
tilelang kernel whose selector returns False off CUDA and DeepGEMM, and
the ragged (prefill) path calls deep_gemm.fp8_mqa_logits directly.
DeepGEMM has no ROCm build, so GLM-5.3-Flash cannot start.

Open the forward gate to HIP and route both logits paths to AITER:

  - paged: aiter_paged_mqa_logits(..., preshuffle=True), resolved through
    DSAPagedMQALogitsBackend so --dsa-paged-mqa-logits-backend reaches
    this path rather than branching on is_hip() at the call site.
    resolve() already pins ROCm to AITER.
  - ragged: _fp8_mqa_logits() picks aiter.ops.triton.fp8_mqa_logits on
    HIP. It takes the fp8 values and scales as separate arguments where
    DeepGEMM takes a tuple.

AITER's paged kernel reads the index-K cache in a 16x16 tile order, so
kpool_fp8_index has to write it that way. The four write kernels and the
one read kernel now share _kpool_cache_k_offsets, which follows
_set_k_and_s_triton_kernel in index_buf_accessor.py -- the non-pooled
indexer already lays its cache out this way for the same AITER kernel,
and the two must agree.

aiter_paged_mqa_logits inserts the next_n dim itself, so q_fp8 stays
[tokens, heads, dim] through the dispatch and the tilelang and DeepGEMM
branches unsqueeze at their own call sites.

Add layout coverage. A write/read disagreement here does not raise, it
silently returns the wrong top-k, so the offsets are pinned against an
independent reference, checked for collisions, and round-tripped through
the reader. The round trip follows the runtime tile rather than pinning
16, so it also holds on a build without AITER's preshuffle kernel.

Co-authored-by: Cursor <[email protected]>
@1am9trash 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Sep 4, 2026
@Fridge003
Fridge003 deleted the branch sgl-project:xinyuan/glm-5.3-flash-support September 6, 2026 09:28
@Fridge003 Fridge003 closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants