Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# c67db7c762 and AITER 581579ab 0.1.29.dev156 with FlyDSL 0.4.2, both editable checkouts under
# /sgl-workspace).
# AITER
# - Not touched. The image's AITER has what the AITER release wheel gave this recipe before:
# - Not replaced. The image's AITER has what the AITER release wheel gave this recipe before:
# ROCm/aiter#5992 (FlyDSL causal conv1d prefill, GDN decode/verify kernels), #6670 (FlyDSL
# fused QSA sparse decode, needed by sglang#45196), #6496 (FlyDSL single-kernel GDN fused
# chunked prefill) and #5993 (hc_mix kernels). The script only checks that the FlyDSL modules
# are importable.
# chunked prefill) and #5993 (hc_mix kernels). The script checks that the FlyDSL modules are
# importable.
# SGLang (each patch is the source-only diff of an open upstream PR, rebased onto the image's
# SGLang; tests, benchmarks and AITER's AOT registry dropped; the header of each file names the
# PR and its head commit)
Expand All @@ -20,11 +20,19 @@
# - 07 sglang#48090 MTP verify target probs on the top-k support instead of a vocabulary-wide
# sort (on with SGLANG_USE_AITER under rejection sampling; the image lacks
# sglang#41916, so the patch carries its top-p rescale helper)
# - 09 sglang#50024 one FP8 quant + one GEMM for the GDN in_proj_qkvz / in_proj_ba of up to 64 rows
# (on by default; the monokernel points set SGLANG_QWEN35_PACKED_IN_PROJ=0)
# sgl-amd-mono (/sgl-workspace/sgl-amd-mono, an editable install of commit a04ceab159d9)
# - 10 amd-asalykov/sgl-amd-mono asalykov/qfn-mono-tp (afbb25a457009d): the updated Qwen3.8-Flash-Next
# monokernel (QSA index chain, stage placement, TP 1 / 2 / 4 launches), the
# qwen38_flash_next package and the common/ops.py and common/sync.py it needs
# (the diff a04ceab..afbb25a; a04ceab already has afbb25a's common/ops.py and sync.py)
# Already in the image, so not patched: sglang#41683 (strided GDN prefill projection views, merged
# 2026-11-17), the monokernel (--enable-amd-monokernel), the AITER topk_gating router (sglang#40708),
# ratio-3 GDN packing (sglang#44302) and the 128-row hc_mix (sglang#41880). All Python. A patch
# that no longer applies, or a missing FlyDSL module, fails the worker.
set -euo pipefail
# 2026-11-17), the original monokernel (--enable-amd-monokernel; patch 10 updates it), the AITER
# topk_gating router (sglang#40708), ratio-3 GDN packing (sglang#44302) and the 128-row hc_mix
# (sglang#41880). All Python. A patch that no longer applies, or a missing FlyDSL module, fails the
# worker.
set -eo pipefail
# srtctl only looks up setup_script here; the patches live with the single-node
# recipe and are read through the workspace mount.
patches=/infmax-workspace/benchmarks/single_node/srt-slurm-recipes/qwen3.8next/sglang/mi355x-fp4-mtp/patches
Expand Down Expand Up @@ -62,6 +70,9 @@ print(
f"flydsl {metadata.version('flydsl')}, from {importlib.util.find_spec('aiter').origin}"
)
PY
# Patches 12 and 22 write into the AITER that python imports, which must be the image's editable checkout.
aiter_root="$(python3 -c 'import aiter, pathlib; print(pathlib.Path(aiter.__file__).resolve().parents[1])')"
[[ $aiter_root == /sgl-workspace/aiter ]] || { echo "qwen3.8next: aiter imports from $aiter_root, expected /sgl-workspace/aiter" >&2; exit 1; }

apply() {
git -c safe.directory="*" -C "$1" apply "$patches/$2"
Expand All @@ -75,5 +86,36 @@ apply /sgl-workspace/sglang 04-sglang-45529-qwen35-fuse-selfattn-prepare.patch
apply /sgl-workspace/sglang 05-sglang-41879-aiter-gdn-conv-prefill.patch
apply /sgl-workspace/sglang 06-sglang-44103-aiter-gdn-chunked-prefill.patch
apply /sgl-workspace/sglang 07-sglang-48090-mtp-sparse-rejection-target-probs.patch
apply /sgl-workspace/sglang 09-sglang-50024-qwen4-packed-fp8-gdn-in-proj.patch
apply /sgl-workspace/sgl-amd-mono 10-sgl-amd-mono-qfn-mono-tp-afbb25a.patch
apply /sgl-workspace/sglang 11-sglang-48625-qsa-grouped-verify.patch
apply "$aiter_root" 12-aiter-7556-qsa-flydsl-sparse-prefill.patch
apply /sgl-workspace/sglang 13-sglang-51179-qsa-flydsl-prefill.patch
apply /sgl-workspace/sglang 14-sglang-49852-mxfp4-moe-pad128.patch
apply /sgl-workspace/sglang 15-sglang-50863-hc-prefill-triton.patch
apply /sgl-workspace/sglang 16-sglang-50871-51263-qsa-prefill-topk-v2.patch
apply /sgl-workspace/sglang 21-sglang-50871-51242-qsa-decode-select.patch
apply /sgl-workspace/sglang 24-sglang-51180-gdn-verify.patch
apply "$aiter_root" 22-aiter-8174-moe-stage2-fp8.patch
apply /sgl-workspace/sglang 23-sglang-51198-moe-stage2-fp8.patch
# 26 brings patch 15's two files to sglang#50863's head, so 15 stays and 26 applies after it.
apply /sgl-workspace/sglang 26-sglang-50863-hc-prefill-triton-head.patch
apply /sgl-workspace/sglang 27-sglang-51023-decode-fp8-quant-fuse.patch
# 28 and 29 are the forms of the GDN split prefill and the GDN fused prefill that the validation windows ran; each
# header names the upstream drafts.
apply /sgl-workspace/sglang 28-sglang-gdn-split-prefill.patch
apply /sgl-workspace/sglang 29-sglang-gdn-prefill-fused.patch
apply /sgl-workspace/sglang 30-sglang-51663-language-model-only.patch

# The monokernel patch must be the code python imports (an editable install of the checkout).
python3 - <<'PY'
import importlib.util
import sys

spec = importlib.util.find_spec("sgl_amd_mono.qwen38_flash_next.gfx950.draft_head")
if spec is None or not spec.origin.startswith("/sgl-workspace/sgl-amd-mono/"):
sys.exit(f"qwen3.8next: sgl_amd_mono imports from {spec and spec.origin}, expected /sgl-workspace/sgl-amd-mono")
print(f"qwen3.8next sgl-amd-mono patched: {spec.origin}")
PY

echo "$digest" > "$marker"
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ base:
engine: sglang
# The image (lmsysorg/sglang-rocm 20261117: SGLang c67db7c762, AITER 581579ab 0.1.29.dev156,
# FlyDSL 0.4.2) already has the AITER FlyDSL kernels this recipe uses (ROCm/aiter#5992, #5993,
# #6496, #6670), so AITER is not touched. The setup script patches SGLang with open upstream
# PRs (sgl-project/sglang #48648, #45196, #48649, #45529, #41879, #44103, #48090); the patch
# files are in patches/ next to this recipe.
# #6496, #6670), so AITER is not replaced. The setup script patches SGLang with open upstream
# PRs (sgl-project/sglang #48648, #45196, #48649, #45529, #41879, #44103, #48090, #50024). It
# also patches the image's sgl-amd-mono (the monokernel, an editable install at
# /sgl-workspace/sgl-amd-mono) with the updated Qwen3.8-Flash-Next monokernel of
# amd-asalykov/sgl-amd-mono, branch asalykov/qfn-mono-tp (afbb25a457009d), which serves TP 1, 2
# and 4. The patch files are in patches/ next to this recipe.
setup_script: qwen3.8next-rocm10-patches.sh
roles:
agg:
Expand Down Expand Up @@ -49,7 +52,6 @@ base:
scheduler-recv-interval: 10
stream-interval: 50
reasoning-parser: qwen3
default-chat-template-kwargs: '{"enable_thinking": false}'
tool-call-parser: qwen3_coder
speculative-algorithm: NEXTN
speculative-num-steps: 3
Expand All @@ -61,6 +63,8 @@ base:
tokenizer-worker-num: 6
enable-metrics: true
enable-cache-report: true
# Patch 30: serve the checkpoint as a text model; the server skips the vision tower's weights.
language-model-only: true
env:
PYTHONNOUSERSITE: '1'
ROCM_QUICK_REDUCE_QUANTIZATION: NONE
Expand All @@ -76,6 +80,11 @@ base:
SGLANG_AITER_GDN_CONV: '1'
SGLANG_AITER_GDN_PREFILL: '1'
SGLANG_AITER_GDN_PREFILL_H: fused
# Patch 28: that fused chunked prefill, for a batch of 1,024 tokens or more, as prep kernels in parallel over
# the chunks plus a serial state kernel, bit for bit the same. Patch 29: the prefill conv, one FP8 quant for
# in_proj_qkvz and in_proj_ba, the gated norm with the out_proj quant, and the gating on new kernels.
SGLANG_AMD_GDN_PREFILL: '1'
SGLANG_AMD_GDN_PREFILL_FUSED: '1'
benchmark:
env:
AIPERF_REQUIRED_SERVER_METRIC_PREFIX: 'sglang:'
Expand All @@ -87,7 +96,10 @@ base:
# Admission equals the concurrency. These points also set SGLANG_USE_AITER, which the
# monokernel requires (the image sets it too), so they form their own GSM8K eval group.
# Every point uses mem-fraction-static as given instead of the aiter backend's 0.85
# scaling.
# scaling. SGLANG_QWEN35_PACKED_IN_PROJ=0 turns off the packed GDN input projection of
# sglang#50024 (patch 09) at the monokernel points: the monokernel runs the decode-sized
# steps it packs, and it builds a second copy of the projections. Every other point keeps
# it on.
override_c1:
roles:
agg:
Expand All @@ -97,9 +109,14 @@ override_c1:
enable-amd-monokernel: true
max-running-requests: 1
cuda-graph-max-bs-decode: 1
# Mamba state at every prefill chunk; level 2 keeps one state per path and recomputes more prompt tokens.
hybrid-cache-checkpoints-level: 3
env:
SGLANG_AITER_HONOR_EXPLICIT_MEM_FRACTION: '1'
SGLANG_USE_AITER: '1'
SGLANG_QWEN35_PACKED_IN_PROJ: '0'
# Patch 10 runs the MTP draft's lm_head on an FP8 copy unless this is 0; 0 keeps the shipped BF16 head.
SGLANG_AMD_MONO_QWEN38_DRAFT_HEAD_FP8: '0'
benchmark:
env:
CONC: '1'
Expand All @@ -114,9 +131,12 @@ override_c2:
enable-amd-monokernel: true
max-running-requests: 2
cuda-graph-max-bs-decode: 2
hybrid-cache-checkpoints-level: 3
env:
SGLANG_AITER_HONOR_EXPLICIT_MEM_FRACTION: '1'
SGLANG_USE_AITER: '1'
SGLANG_QWEN35_PACKED_IN_PROJ: '0'
SGLANG_AMD_MONO_QWEN38_DRAFT_HEAD_FP8: '0'
benchmark:
env:
CONC: '2'
Expand All @@ -132,8 +152,8 @@ override_c2:
# norm and inject into the mix. The prefill CUDA graph backend is breakable (the AMD
# reference recipes get it from an SGLang default change that this image lacks), which
# captures the GDN prefill on static per-bucket tables; a batch outside the captured
# buckets runs eagerly through the AITER fused prefill. c80 caches only the prompt on
# finish and keeps at most two Mamba states per path.
# buckets runs eagerly through the AITER fused prefill. c48 and c80 cache only the prompt
# on finish and keep at most two Mamba states per path.
override_c12:
roles:
agg:
Expand All @@ -152,6 +172,24 @@ override_c12:
SGLANG_USE_AITER_UNIFIED_ATTN: '1'
SGLANG_AITER_HONOR_EXPLICIT_MEM_FRACTION: '1'
SGLANG_OPT_QWEN4_FUSED_HC: '1'
# Patch 11: the 4 draft rows of a request share their compressed-key reads in QSA verify.
SGLANG_AMD_QSA_GROUPED_VERIFY: '1'
# Patches 12-13: QSA sparse prefill attention on the FlyDSL kernels.
SGLANG_AMD_QSA_FLYDSL_PREFILL: '1'
# Patch 14: the MoE intermediate padded to 640, so AITER's tuned MXFP4 rows apply.
SGLANG_AMD_MXFP4_PAD128: '1'
# Patches 15 and 26: gated HC sites above 48 rows on Triton kernels, split-K up to 512 rows.
SGLANG_USE_HIP_HC_PREFILL_TRITON: '1'
# Patch 16: QSA indexer prefill blocks selected by the exact topk_v2, scored in one pipeline stage.
SGLANG_AMD_QSA_PREFILL_TOPK_V2: '1'
# Patch 21: QSA decode, verify and draft-extend blocks selected by the exact topk_v2,
# and draft-extend rows scored grouped as in verify.
SGLANG_AMD_QSA_DECODE_TOPK_V2: '1'
SGLANG_AMD_QSA_GROUPED_DRAFT_EXTEND: '1'
# Patches 22-23: the target's FlyDSL reduce MoE stage 2 writes FP8 route rows, summed in FP32.
SGLANG_AITER_MOE_STAGE2_FP8: '1'
# Patch 24: GDN ReplaySSM verify and commit kernels.
SGLANG_AMD_GDN_VERIFY: '1'
benchmark:
env:
KV_OFFLOADING: none
Expand All @@ -164,6 +202,10 @@ override_c24:
<<: *fp8_args
max-running-requests: 48
cuda-graph-max-bs-decode: 48
# Every size to the admission, so decode batches never pad; c12 keeps the image's sizes.
cuda-graph-bs-decode: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48]
env: *fp8_env
benchmark:
env:
Expand All @@ -177,12 +219,21 @@ override_c48:
<<: *fp8_args
max-running-requests: 128
cuda-graph-max-bs-decode: 128
# Every size to 64, then every 8 to the admission: decode batches up to 64 never pad.
cuda-graph-bs-decode: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 72, 80, 88, 96, 104, 112, 120, 128]
max-mamba-cache-size: 720
enable-hierarchical-cache: true
hicache-size: 298
hicache-io-backend: kernel
hicache-mem-layout: page_first
hicache-write-policy: write_back
# Cache only the prompt on finish; the AgentX replay never re-sends model output.
strip-thinking-cache: true
# At most two Mamba states per conversation path; stale interior states skip host write-back.
mamba-max-states-per-path: 2
env: *fp8_env
benchmark:
env: &hicache_client
Expand All @@ -196,10 +247,6 @@ override_c80:
args:
<<: *hicache_args
max-mamba-cache-size: 640
# Cache only the prompt on finish; the AgentX replay never re-sends model output.
strip-thinking-cache: true
# At most two Mamba states per conversation path; stale interior states skip host write-back.
mamba-max-states-per-path: 2
env: *fp8_env
benchmark:
env:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# [Perf] [AMD] Qwen3.8-Flash-Next: Pack the FP8 GDN input projections on ROCm
# https://github.com/sgl-project/sglang/pull/50024 (PR head f88569cd120660801e00459449856f1f1e0a844a, a merge of main; the diff below is the PR's own changes)
# Generated against the SGLang checkout of the image (1ced9a9eb0) with patches 01-08 applied; source files only (tests dropped).
# One FP8 quant and one GEMM for the GDN in_proj_qkvz and in_proj_ba of up to 64 rows (decode and verify
# steps), instead of two of each. It is on by default; SGLANG_QWEN35_PACKED_IN_PROJ=0 turns it off. The monokernel
# points (c1 TP1/2/4, c2) set it to 0: the monokernel covers the steps this packs, and packing builds a second
# copy of the projections (about 1.5 GB) that those points do not read.

diff --git a/python/sglang/srt/models/qwen3_5.py b/python/sglang/srt/models/qwen3_5.py
index 6381115b5693..e142324e580a 100644
--- a/python/sglang/srt/models/qwen3_5.py
+++ b/python/sglang/srt/models/qwen3_5.py
@@ -163,8 +163,11 @@
_is_gfx95 = is_gfx95_supported()
_is_hip = is_hip()
_QWEN3_5_MOE_TEXT_MODEL_TYPES = ("qwen3_5_moe_text", "qwen4_exp_text")
-# qwen4_exp shares these classes, but the ROCm packed path is Qwen3.5-only.
+# qwen4_exp shares these classes; on ROCm it packs only the Quark FP8 projections.
_QWEN3_5_ROCM_PACKED_MODEL_TYPES = ("qwen3_5_text", "qwen3_5_moe_text")
+_QWEN3_5_ROCM_PACKED_FP8_MODEL_TYPES = _QWEN3_5_ROCM_PACKED_MODEL_TYPES + (
+ "qwen4_exp_text",
+)
_is_xpu = is_xpu()
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and _is_hip
if _use_aiter:
@@ -711,7 +714,7 @@ def finalize_fused_in_proj(self) -> None:
return
if (
_use_aiter
- and self.config.model_type not in _QWEN3_5_ROCM_PACKED_MODEL_TYPES
+ and self.config.model_type not in _QWEN3_5_ROCM_PACKED_FP8_MODEL_TYPES
):
return
if get_lora().enable_lora or get_lora().lora_paths:
@@ -723,6 +726,11 @@ def finalize_fused_in_proj(self) -> None:
qkvz, ba = self.in_proj_qkvz, self.in_proj_ba
if _use_aiter and self._finalize_fused_fp8_in_proj():
return
+ if (
+ _use_aiter
+ and self.config.model_type not in _QWEN3_5_ROCM_PACKED_MODEL_TYPES
+ ):
+ return
if not (
isinstance(qkvz.quant_method, UnquantizedLinearMethod)
and isinstance(ba.quant_method, UnquantizedLinearMethod)
@@ -756,7 +764,7 @@ def _finalize_fused_fp8_in_proj(self) -> bool:
type(getattr(proj, "scheme", None)) is QuarkW8A8Fp8
and proj.scheme.weight_qscheme == "per_channel"
and proj.scheme.per_token
- and proj.input_scale is None
+ and getattr(proj, "input_scale", None) is None
and proj.bias is None
and proj.weight.dtype == torch.float8_e4m3fn
and proj.weight.is_cuda
@@ -1893,7 +1901,10 @@ def get_input_embeddings(self):
return self.embed_tokens

def prepare_before_cuda_graph_capture(self, model_runner) -> None:
- if _use_aiter and self.config.model_type in _QWEN3_5_ROCM_PACKED_MODEL_TYPES:
+ if (
+ _use_aiter
+ and self.config.model_type in _QWEN3_5_ROCM_PACKED_FP8_MODEL_TYPES
+ ):
packed = 0
mxfp4 = 0
for module in self.modules():
diff --git a/python/sglang/srt/models/qwen4_exp.py b/python/sglang/srt/models/qwen4_exp.py
index f20b5ae77c72..35b5a7d899a0 100644
--- a/python/sglang/srt/models/qwen4_exp.py
+++ b/python/sglang/srt/models/qwen4_exp.py
@@ -2337,6 +2337,11 @@ class Qwen4ExpForConditionalGeneration(Qwen3VLForConditionalGeneration):
def should_apply_lora(self, module_name: str) -> bool:
return module_name.startswith("model.layers.")

+ def prepare_before_cuda_graph_capture(self, model_runner) -> None:
+ prepare = getattr(self.model, "prepare_before_cuda_graph_capture", None)
+ if prepare is not None:
+ prepare(model_runner)
+
@staticmethod
def shared_experts_fusion_disable_reason(hf_config, quant_config):
return Qwen4ExpVLModel.shared_experts_fusion_disable_reason(
Loading