Repository navigation
feat(gdn) Add opt-in AITER FlyDSL GDN prefill on gfx942 for Qwen3.8 Flash Next - #62
Conversation
| ) | ||
| except ModuleNotFoundError: | ||
| # AITER versions before the gated_delta_net directory rename. | ||
| from aiter.ops.triton._triton_kernels.gated_delta_rule.prefill.chunk_o import ( |
There was a problem hiding this comment.
Shall we report a error here or fallback to another kernel ?
There was a problem hiding this comment.
If this path also fails to import, it will be caught by except ImportError as exc: on L46 and log a warning as you suggested.
| return ops[0](lengths, cu_seqlens=cu, chunk_size=CHUNK_SIZE) | ||
|
|
||
|
|
||
| def aiter_gdn_prefill_supported(q, k, v, g, beta, states, indices, cu) -> bool: |
There was a problem hiding this comment.
shall we check the import of aiter at this stage as well ?
| ): | ||
| from sglang.kernels.ops.attention.fla.l2norm import l2norm_fwd | ||
|
|
||
| _, prepare, recurrent, output = _aiter_ops() |
There was a problem hiding this comment.
Since the duplicated imports may happen, I dont think the import of aiter op should be included in its forward function (aiter_gdn_prefill). Maybe a separate class for aiter gdn ?
There was a problem hiding this comment.
_aiter_ops() is cached with @functools.lru_cache(maxsize=1). The imports execute on the first call, which normally happens during metadata initialization. This also keeps aiter optional when the aiter gdn path is disabled. So I suggest keeping the current adapter.
There was a problem hiding this comment.
_aiter_ops()is cached with@functools.lru_cache(maxsize=1). The imports execute on the first call, which normally happens during metadata initialization. This also keeps aiter optional when the aiter gdn path is disabled. So I suggest keeping the current adapter.
@copilot what's your opinion ?
There was a problem hiding this comment.
Considering the maintenance, its better to follow the format of other backend
There was a problem hiding this comment.
Considering the maintenance, its better to follow the format of other backend
Updated as suggested: added class AiterGDNKernel(LinearAttnKernelBase)
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
If theif (...)condition is not met for a given batch, `self.forward_metadata.aiter_gdn_prefill_m… · New_aiter_ops()can returnNone(e.g., AITER not installed / import fails). In that case,… · New The comment says to preserve a BF16 default, but the code sets the default tofloat32. Please… · New
What changed in this PR
Adds an opt-in AITER FlyDSL fast path for GDN ordinary prefill on gfx942, wiring the metadata through the forward pass and providing ROCm-focused tests and a launch script update.
Changes:
- Introduces
gdn_aiter(AITER-backed 3-stage GDN prefill) and gates it behindSGLANG_USE_AITER_GDN_PREFILL. - Plumbs prefill metadata through
ForwardMetadata,GDNAttnBackend, andTritonGDNKernel.extend()to enable the AITER path. - Adds gfx942 ROCm tests validating correctness, radix tracking behavior, and fallback rules; updates a MI308X launch script for dtype + flag control.
| File | Description |
|---|---|
| test/registered/attention/test_gdn_prefill_aiter.py | New ROCm/gfx942 tests covering AITER-vs-Triton parity and fallback behavior. |
| scripts/launch_qwen38_flash_next_fp8_mi308x_pure_tp_4_or_8_or_2.sh | Adds MAMBA_SSM_DTYPE + exports SGLANG_USE_AITER_GDN_PREFILL for MI308X runs. |
| python/sglang/srt/layers/attention/mamba/mamba2_metadata.py | Adds aiter_gdn_prefill_metadata to ForwardMetadata (TYPE_CHECKING typed). |
| python/sglang/srt/layers/attention/linear/kernels/gdn_triton.py | Adds opt-in AITER dispatch in TritonGDNKernel.extend() when metadata is present. |
| python/sglang/srt/layers/attention/linear/kernels/gdn_aiter.py | New module implementing AITER FlyDSL GDN prefill and support checks. |
| python/sglang/srt/layers/attention/linear/gdn_backend.py | Builds and stores prefill metadata once per forward batch; passes it into kernels. |
| python/sglang/srt/environ.py | Adds the SGLANG_USE_AITER_GDN_PREFILL env flag. |
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
5 open issues
LINEAR_ATTN_PREFILL_BACKEND_CHOICEScan accumulate duplicates (e.g., if a choice already exists… · NewLINEAR_ATTN_PREFILL_BACKEND_CHOICEScan accumulate duplicates (e.g., if a choice already exists… · New The script validatesMAMBA_SSM_DTYPEbut does not validateLINEAR_ATTN_PREFILL_BACKEND. Since… · New The script validatesMAMBA_SSM_DTYPEbut does not validateLINEAR_ATTN_PREFILL_BACKEND. Since… · New This unit test only needsextend_kernelto be not anAiterGDNKernel, but currently constructs… · New
3 resolved since last review
Review effort: Lite
There was a problem hiding this comment.
Why we need a fallback kernel ? As my understanding, the decode_kernel has been already wrapped here.
There was a problem hiding this comment.
The fallback is for unsupported prefill batches, not decode. Selecting decode_kernel does not provide fallback for AiterGDNKernel.extend(). When aiter cannot handle a batch, we call the existing triton instance’s extend() method. We pass the same triton_kernel instance already created by the dispatcher, so no additional instance is created.
prefill
→ dispatcher.extend_kernel
→ AiterGDNKernel.extend()
├─ support:aiter prefill
└─ unsupport:fallback_kernel.extend(),run triton prefill
There was a problem hiding this comment.
It makes sense for prefill stage, but if this kernel can support prefill only, maybe its unnecessary to define a new decode function. BTW could you add a warning log when fallback happen?
|
|
||
| The forward metadata certifies real request rows. | ||
| """ | ||
| if q.ndim != 4 or k.shape != q.shape or v.ndim != 4: |
There was a problem hiding this comment.
Shall combine these 2 if check here ?
48ff3eb to
1068f9f
Compare
| ) | ||
|
|
||
|
|
||
| def _run_aiter_gdn_prefill( |
There was a problem hiding this comment.
Since it is used by class AiterGDNKernel only, its better to wrap this function into class AiterGDNKernel, and there is no need to pack prepare, recurrent, output as its inputs.
There was a problem hiding this comment.
Agree. I will open another pr to update it.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Check for AITER ops availability and raise error if unavailable. Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Select the existing AITER pipeline with --linear-attn-prefill-backend aiter while keeping Triton decode and verify. Load optional operators in the backend constructor, preserve per-batch metadata and state-pool semantics, and remove the environment-driven Triton override. Cover backend selection, fallback and metadata lifetime, FP32/BF16 prefill-to-decode and verify, and radix state restore. Update the Qwen3.8 launcher to use the public backend option.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Add validation for LINEAR_ATTN_PREFILL_BACKEND variable. Co-authored-by: Copilot Autofix powered by AI <[email protected]>
1068f9f to
01ae2b3
Compare
| self.fallback_kernel = fallback_kernel | ||
| self._ops = _aiter_ops() | ||
| if self._ops is not None: | ||
| from sglang.kernels.ops.attention.fla.l2norm import l2norm_fwd |
There was a problem hiding this comment.
Will you consider port a fused version: sgl-project#33290, estimate AMD-Qwen3.5-397B-A17B-FP8 in MI308x,TTFT improved ~0.5%, gain < 2%
There was a problem hiding this comment.
Thanks for reminding. I'll combined and added it in another pr.
4d63dea
into
qwen38-flash-next-amd-current-fix-install
* feat(gdn) Add opt-in AITER FlyDSL GDN prefill on gfx942 for Qwen3.8 Flash Next (#62) * Add opt-in AITER FlyDSL GDN prefill on gfx942 * Enable AITER GDN prefill autotuning in Qwen3.8 launcher * Drop explicit GDN autotune environment switch * regulate script * expand support for bf16 mamba ssm dtype * Update comments for clarity on data types Co-authored-by: Copilot Autofix powered by AI <[email protected]> * Add AITER ops availability check in gdn_aiter.py Check for AITER ops availability and raise error if unavailable. Co-authored-by: Copilot Autofix powered by AI <[email protected]> * update aiter_gdn_prefill_metadata init * update aiter_gdn_prefill_supported * Register AITER as a GDN prefill backend Select the existing AITER pipeline with --linear-attn-prefill-backend aiter while keeping Triton decode and verify. Load optional operators in the backend constructor, preserve per-batch metadata and state-pool semantics, and remove the environment-driven Triton override. Cover backend selection, fallback and metadata lifetime, FP32/BF16 prefill-to-decode and verify, and radix state restore. Update the Qwen3.8 launcher to use the public backend option. * update script * revert some update * Update GDNAttnBackend kernel dispatcher configuration Co-authored-by: Copilot Autofix powered by AI <[email protected]> * Validate LINEAR_ATTN_PREFILL_BACKEND input Add validation for LINEAR_ATTN_PREFILL_BACKEND variable. Co-authored-by: Copilot Autofix powered by AI <[email protected]> * de-duplicate LINEAR_ATTN_PREFILL_BACKEND_CHOICES * add log fallback * update aiter_gdn_prefill_supported --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]> (cherry picked from commit 4d63dea) * [AMD] Enable AITER GDN prefill in Qwen3.5 launch scripts Pass --linear-attn-prefill-backend aiter; decode and verify stay on Triton. --------- Co-authored-by: tongqiu <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: Xiake Sun <[email protected]>



Motivation
Based on apinge/aiter#5, this pr introduces aiter gdn. The this implementation achieves a much higher speedup than pure autotune alone( see profile in #52)
Modifications
Original sglang gdn prefill uses
chunk_local_cumsum_scalar_kernel->chunk_gated_delta_rule_fwd_kkt_solve_kernel->recompute_w_u_fwd_kernel->chunk_gated_delta_rule_fwd_kernel_h_blockdim64->chunk_fwd_kernel_oThis PR uses 3 aiter's kernel
gdn_prepare_kernel->chunk_gdn_fwd_h_flydsl_op->chunk_fwd_kernel_o_opt_vkThis feature can be enabled via
--linear-attn-prefill-backend aiterBe aware these prefill gdn kernels support both bf16 ssm state and f32 ssm state, use
--mamba-ssm-dtype bfloat16to speicify this feature (float32is defualt)Notice that this PR does not adopt all ATOM flow (last kernel of ATOM is
chunk_fwd_kernel_onotchunk_fwd_kernel_o_opt_vk) because sglang and ATOM have different metadata.Accuracy Tests
gsm8k test in TP2 no mtp no radix cache,
--mamba-ssm-dtype defaultgsm8k test in TP2 no mtp no radix cache,
--mamba-ssm-dtype bfloat16Speed Tests and Profiling
sglang benchmark
1conc 12k in 350out no mtp no radix cache,
--mamba-ssm-dtype defaultBefore
After
kernel profile in 12k
Kernel execution time reduced by 49.7% (1.99x speedup)
Before
After
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci