Skip to content

[ROCm] Use hipBLASLt swizzle GEMM for fp8/bf16 linears - #8

Merged
apinge merged 1 commit into
qwen3_5_v0.5.15_dflashfrom
qwen3_5_v0.5.15_dflash_th
Aug 3, 2026
Merged

apinge merged 1 commit into
qwen3_5_v0.5.15_dflashfrom
qwen3_5_v0.5.15_dflash_th

Conversation

@TianHao65

@TianHao65 TianHao65 commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Port of upstream sgl-project#214 (eb0e3f8) to qwen3_5_v0.5.15_dflash.

Routes PTPC-FP8 and unquantized bf16 linears through hipb_mm instead of aiter's
gemm_a8w8_bpreshuffle / tgemm.mm, behind SGLANG_ROCM_USE_AITER_LINEAR_FP8HIPB
and SGLANG_ROCM_USE_AITER_LINEAR_SHUFFLE. FP8 weights are stored (K, N) with
weight_scale transposed to match. Both env vars are already exported by the
Qwen3.5 launch scripts
, so this makes them live with no script change.

Performance

Qwen3.5-397B-A17B-PTPC-FP8, TP=8, MI308X, bench_serving random 512 in / 256 out,
same host and config before and after:

conc tok/s before → after TTFT ms before → after TPOT ms before → after
16 2758.10 → 2774.31 (+0.6%) 538.4 → 489.9 (-9.0%) 15.33 → 15.42
64 5825.37 → 6044.20 (+3.8%) 1749.7 → 1514.0 (-13.5%) 26.13 → 25.88
128 7490.48 → 7743.29 (+3.4%) 2306.9 → 2092.6 (-9.3%) 39.50 → 38.49

Most of the gain is in prefill, which is GEMM-bound — hence the large TTFT
improvement against a much flatter TPOT curve.

Reachability

Profiled over the same workload to confirm the switch actually happens rather than
being silently guarded out:

kernel calls before → after
aiter gemm_a8w8* / *bpreshuffle* 1440 → 0
hipBLASLt Cijk_* (incl. fp8 F8NBS) 0 → 572 (5,290 us)

Bonus fix

Unblocks --disable-shared-experts-fusion, where the shared-expert down_proj K
(64 on 35B, 128 on 397B) trips aiter's Unsupported K for heuristic dispatch: Supported K greater than 192. hipb_mm handles both; verified at K=64 and K=128,
err 0.0010.

Three deliberate differences from the upstream patch

  • unquant.py — the swizzle check has to go above the existing
    _use_aiter → tgemm.mm branch, not below it, or it never runs on ROCm.
  • fp8_utils.py — apply_fp8_ptpc_linear here has a pre-quantized tuple
    entry point (fused RMSNorm+Quant) that upstream's copy doesn't, and it needs the
    same layout handling. Otherwise it reads weight.shape[0] as K instead of N and
    quietly feeds a transposed weight to a gemm expecting (N, K).
  • Layout tracking — uses a weight.hipb_swizzled tag set at load time rather
    than re-reading the env var at apply time, so shapes that fail can_shuffle()
    stay on the old path instead of reaching hipb_mm transposed. Tagging attributes
    on the Parameter (not self) since a quant-method instance isn't guaranteed
    per-layer. This is an established idiom here (cf. layer.weight_scale.format_ue8m0).

Numerics

Checked against a torch dequant reference for M=1..1024 and N/K ∈ {1536, 2048, 4096},
tuple path included: max abs err ~0.004 on outputs of magnitude ~3, matching baseline.

Files: environ.py, compressed_tensors/utils.py (new AiterHipblaslt + 2 helpers),
compressed_tensors/schemes/compressed_tensors_w8a8_fp8.py, fp8_utils.py,
unquant.py — 203 insertions, 16 deletions.

@TianHao65
TianHao65 force-pushed the qwen3_5_v0.5.15_dflash_th branch from 0739fbd to 42240f5 Compare July 31, 2026 03:28
Port of upstream sgl-project#214 (eb0e3f8). Routes PTPC-FP8 and unquantized bf16
linears through hipb_mm instead of aiter's gemm_a8w8_bpreshuffle / tgemm.mm,
behind SGLANG_ROCM_USE_AITER_LINEAR_FP8HIPB and
SGLANG_ROCM_USE_AITER_LINEAR_SHUFFLE. fp8 weights are stored (K, N) with
weight_scale transposed to match. Both vars are already exported by the
Qwen3.5 launch scripts, so this makes them live.

Qwen3.5-397B-A17B-PTPC-FP8, TP=8, MI308X, bench_serving random
512 in / 256 out, same host and config before and after:

  conc | tok/s  before -> after      | TTFT ms before -> after   | TPOT ms
  -----+----------------------------+---------------------------+--------------
    16 | 2758.10 -> 2774.31  (+0.6%) |  538.4 ->  489.9  (-9.0%) | 15.33 -> 15.42
    64 | 5825.37 -> 6044.20  (+3.8%) | 1749.7 -> 1514.0 (-13.5%) | 26.13 -> 25.88
   128 | 7490.48 -> 7743.29  (+3.4%) | 2306.9 -> 2092.6  (-9.3%) | 39.50 -> 38.49

Most of the gain is in prefill, which is GEMM-bound, hence the large TTFT
improvement against a much flatter TPOT curve.

Profile over the same workload confirms the switch actually happens, i.e.
the new path is reached rather than silently guarded out:

  kernel                              | calls before -> after
  ------------------------------------+----------------------
  aiter gemm_a8w8* / *bpreshuffle*    |  1440 -> 0
  hipBLASLt Cijk_* (incl. fp8 F8NBS)  |     0 -> 572

Also unblocks --disable-shared-experts-fusion, where the shared-expert
down_proj K (64 on 35B, 128 on 397B) trips aiter's "Supported K greater
than 192" dispatch check. hipb_mm handles both.

Three deliberate differences from the upstream patch:

- unquant.py: the swizzle check has to go above the existing
  `_use_aiter -> tgemm.mm` branch, not below it, or it never runs on ROCm.
- fp8_utils.py: apply_fp8_ptpc_linear here has a pre-quantized tuple entry
  point upstream's copy doesn't, and it needs the same layout handling --
  otherwise it reads weight.shape[0] as K and quietly returns garbage.
- Layout is tracked with a weight.hipb_swizzled tag set at load time rather
  than re-reading the env var at apply time, so shapes that fail
  can_shuffle() stay on the old path instead of reaching hipb_mm transposed.

Numerics checked against a torch dequant reference for M=1..1024 and
N/K in {1536, 2048, 4096}, tuple path included: max abs err ~0.004 on
outputs of magnitude ~3, matching baseline.
@TianHao65
TianHao65 force-pushed the qwen3_5_v0.5.15_dflash_th branch from 42240f5 to a6f5d30 Compare July 31, 2026 03:57
@TianHao65 TianHao65 changed the title Qwen3 5 v0.5.15 dflash th [ROCm] Use hipBLASLt swizzle GEMM for fp8/bf16 linears Jul 31, 2026
@apinge
apinge merged commit 43f134d into qwen3_5_v0.5.15_dflash Aug 3, 2026
10 of 13 checks passed
TianHao65 added a commit that referenced this pull request Nov 2, 2026
Port apinge/sglang PR #8 (a6f5d30)
using the previously tested v0.5.21 adaptation.

Route PTPC-FP8 and unquantized BF16 linears through AITER hipb_mm behind
the existing swizzle flags. Track weight layouts per Parameter and retain
fallback dispatch for weights that fail the swizzle shape guard.

Handle v0.5.21 prequantized three-element tuples and leading dimensions,
and support BF16 caller-owned output buffers.

(cherry picked from commit 0bcf65b)
Signed-off-by: TianHao65 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants