Repository navigation
[ROCm] Use hipBLASLt swizzle GEMM for fp8/bf16 linears - #8
Merged
Merged
Conversation
TianHao65
force-pushed
the
qwen3_5_v0.5.15_dflash_th
branch
from
July 31, 2026 03:28
0739fbd to
42240f5
Compare
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
force-pushed
the
qwen3_5_v0.5.15_dflash_th
branch
from
July 31, 2026 03:57
42240f5 to
a6f5d30
Compare
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port of upstream sgl-project#214 (
eb0e3f8) toqwen3_5_v0.5.15_dflash.Routes PTPC-FP8 and unquantized bf16 linears through
hipb_mminstead of aiter'sgemm_a8w8_bpreshuffle/tgemm.mm, behindSGLANG_ROCM_USE_AITER_LINEAR_FP8HIPBand
SGLANG_ROCM_USE_AITER_LINEAR_SHUFFLE. FP8 weights are stored(K, N)withweight_scaletransposed to match. Both env vars are already exported by theQwen3.5 launch scripts, so this makes them live with no script change.
Performance
Qwen3.5-397B-A17B-PTPC-FP8, TP=8, MI308X,
bench_servingrandom 512 in / 256 out,same host and config before and after:
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:
gemm_a8w8*/*bpreshuffle*Cijk_*(incl. fp8F8NBS)Bonus fix
Unblocks
--disable-shared-experts-fusion, where the shared-expertdown_projK(64 on 35B, 128 on 397B) trips aiter's
Unsupported K for heuristic dispatch: Supported K greater than 192.hipb_mmhandles 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.mmbranch, not below it, or it never runs on ROCm.fp8_utils.py—apply_fp8_ptpc_linearhere has a pre-quantizedtupleentry 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 andquietly feeds a transposed weight to a gemm expecting
(N, K).weight.hipb_swizzledtag set at load time ratherthan re-reading the env var at apply time, so shapes that fail
can_shuffle()stay on the old path instead of reaching
hipb_mmtransposed. Tagging attributeson the Parameter (not
self) since a quant-method instance isn't guaranteedper-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(newAiterHipblaslt+ 2 helpers),compressed_tensors/schemes/compressed_tensors_w8a8_fp8.py,fp8_utils.py,unquant.py— 203 insertions, 16 deletions.