Skip to content

feat(gdn) Add opt-in AITER FlyDSL GDN prefill on gfx942 for Qwen3.8 Flash Next - #62

Merged
sammysun0711 merged 17 commits into
qwen38-flash-next-amd-current-fix-installfrom
qwen38-aiter-gdn-prefill
Nov 4, 2026
Merged

sammysun0711 merged 17 commits into
qwen38-flash-next-amd-current-fix-installfrom
qwen38-aiter-gdn-prefill

Conversation

@apinge

@apinge apinge commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

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_o

This PR uses 3 aiter's kernel
gdn_prepare_kernel->chunk_gdn_fwd_h_flydsl_op->chunk_fwd_kernel_o_opt_vk

This feature can be enabled via --linear-attn-prefill-backend aiter
Be aware these prefill gdn kernels support both bf16 ssm state and f32 ssm state, use --mamba-ssm-dtype bfloat16 to speicify this feature (float32 is defualt)

Notice that this PR does not adopt all ATOM flow (last kernel of ATOM is chunk_fwd_kernel_o not chunk_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 default

bash run_gsm8k_qwen38.sh 
[aiter] import [module_aiter_core] under /opt/aiter/aiter/jit/module_aiter_core.so
ChatCompletionSampler initialized with self.system_message=None self.temperature=0.0 self.max_tokens=16384 self.reasoning_effort=None self.extra_body=None self.stop=None self.record_meta_info=True
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1314/1314 [10:34<00:00,  2.07it/s]
Total latency: 634.664 s
Score: 0.978
Output throughput: 1004.758 token/s
[METRIC] gsm8k_score=0.9779299847792998 labels={"model": "Qwen/Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16", "eval": "gsm8k"}
[METRIC] gsm8k_latency=634.66401382396 labels={"model": "Qwen/Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16", "eval": "gsm8k"}
====================
Speculative decoding: no per-request spec_accept_length in responses (non-speculative server, or --api completion which lacks return_meta_info).
====================
Writing report to /tmp/gsm8k_Qwen_Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16.html
{'score:std': np.float64(0.146911298574542), 'score': np.float64(0.9779299847792998), 'latency': 634.66401382396, 'output_throughput': 1004.7584014695336}
Writing results to /tmp/gsm8k_Qwen_Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16.json

gsm8k test in TP2 no mtp no radix cache, --mamba-ssm-dtype bfloat16

bash run_gsm8k_qwen38.sh 
[aiter] import [module_aiter_core] under /opt/aiter/aiter/jit/module_aiter_core.so
ChatCompletionSampler initialized with self.system_message=None self.temperature=0.0 self.max_tokens=16384 self.reasoning_effort=None self.extra_body=None self.stop=None self.record_meta_info=True
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 1314/1314 [10:51<00:00,  2.02it/s]
Total latency: 651.310 s
Score: 0.976
Output throughput: 1010.349 token/s
[METRIC] gsm8k_score=0.9764079147640792 labels={"model": "Qwen/Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16", "eval": "gsm8k"}
[METRIC] gsm8k_latency=651.3098946009995 labels={"model": "Qwen/Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16", "eval": "gsm8k"}
====================
Speculative decoding: no per-request spec_accept_length in responses (non-speculative server, or --api completion which lacks return_meta_info).
====================
Writing report to /tmp/gsm8k_Qwen_Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16.html
{'score:std': np.float64(0.15177449967020776), 'score': np.float64(0.9764079147640792), 'latency': 651.3098946009995, 'output_throughput': 1010.3485383146674}
Writing results to /tmp/gsm8k_Qwen_Qwen3.8-Flash-Next-PTPC-FP8-PLE-BF16.json
HIP_VISIBLE_DEVICES=0 CUDA_VISIBLE_DEVICES=0 \
GATED_DELTA_RULE_TRITON_AUTOTUNE=1 \
python -m pytest -q test/registered/attention/test_gdn_prefill_aiter.py \
  -k 'prefill_and_decode or radix_tracking_and_restore'

Speed Tests and Profiling

sglang benchmark

1conc 12k in 350out no mtp no radix cache, --mamba-ssm-dtype default

Before

#Input tokens: 384000
#Output tokens: 11200
Starting warmup with 10 sequences...
Warmup completed with 10 sequences. Starting main benchmark run...
100%|██████████| 32/32 [01:43<00:00,  3.24s/it]

============ Serving Benchmark Result ============
Backend:                                 sglang    
Traffic request rate:                    inf       
Max request concurrency:                 1         
Successful requests:                     32        
Benchmark duration (s):                  103.66    
Total input tokens:                      384000    
Total input text tokens:                 384000    
Total generated tokens:                  11200     
Total generated tokens (retokenized):    11179     
Request throughput (req/s):              0.31      
Input token throughput (tok/s):          3704.52   
Output token throughput (tok/s):         108.05    
Peak output token throughput (tok/s):    142.00    
Peak concurrent requests:                2         
Total token throughput (tok/s):          3812.57   
Concurrency:                             1.00      
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   3238.20   
Median E2E Latency (ms):                 3238.30   
P90 E2E Latency (ms):                    3243.98   
P95 E2E Latency (ms):                    3245.23   
P99 E2E Latency (ms):                    3248.03   
---------------Time to First Token----------------
Mean TTFT (ms):                          780.53    
Median TTFT (ms):                        781.07    
P90 TTFT (ms):                           786.60    
P95 TTFT (ms):                           787.74    
P99 TTFT (ms):                           790.93    
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          7.04      
Median TPOT (ms):                        7.04      
P90 TPOT (ms):                           7.05      
P95 TPOT (ms):                           7.05      
P99 TPOT (ms):                           7.05      
---------------Inter-Token Latency----------------
Mean ITL (ms):                           7.04      
Median ITL (ms):                         7.04      
P90 ITL (ms):                            7.06      
P95 ITL (ms):                            7.07      
P99 ITL (ms):                            7.23      
Max ITL (ms):                            8.19      
==================================================

After

#Input tokens: 384000
#Output tokens: 11200
Starting warmup with 10 sequences...
Warmup completed with 10 sequences. Starting main benchmark run...
100%|██████████| 32/32 [01:42<00:00,  3.20s/it]

============ Serving Benchmark Result ============
Backend:                                 sglang    
Traffic request rate:                    inf       
Max request concurrency:                 1         
Successful requests:                     32        
Benchmark duration (s):                  102.30    
Total input tokens:                      384000    
Total input text tokens:                 384000    
Total generated tokens:                  11200     
Total generated tokens (retokenized):    11181     
Request throughput (req/s):              0.31      
Input token throughput (tok/s):          3753.63   
Output token throughput (tok/s):         109.48    
Peak output token throughput (tok/s):    142.00    
Peak concurrent requests:                2         
Total token throughput (tok/s):          3863.11   
Concurrency:                             1.00      
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   3195.82   
Median E2E Latency (ms):                 3195.82   
P90 E2E Latency (ms):                    3201.08   
P95 E2E Latency (ms):                    3201.77   
P99 E2E Latency (ms):                    3203.09   
---------------Time to First Token----------------
Mean TTFT (ms):                          726.66    
Median TTFT (ms):                        726.53    
P90 TTFT (ms):                           732.02    
P95 TTFT (ms):                           733.18    
P99 TTFT (ms):                           734.87    
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          7.07      
Median TPOT (ms):                        7.08      
P90 TPOT (ms):                           7.08      
P95 TPOT (ms):                           7.08      
P99 TPOT (ms):                           7.08      
---------------Inter-Token Latency----------------
Mean ITL (ms):                           7.07      
Median ITL (ms):                         7.07      
P90 ITL (ms):                            7.09      
P95 ITL (ms):                            7.11      
P99 ITL (ms):                            7.23      
Max ITL (ms):                            7.74      
==================================================

kernel profile in 12k

Kernel execution time reduced by 49.7% (1.99x speedup)

Before

image

After

image

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@apinge apinge changed the title Add opt-in AITER FlyDSL GDN prefill on gfx942 feat(gdn) Add opt-in AITER FlyDSL GDN prefill on gfx942 Oct 22, 2026
@apinge apinge changed the title feat(gdn) Add opt-in AITER FlyDSL GDN prefill on gfx942 feat(gdn) Add opt-in AITER FlyDSL GDN prefill on gfx942 for Qwen3.8 Flash Next Oct 22, 2026
@apinge
apinge marked this pull request as ready for review October 26, 2026 02:37
)
except ModuleNotFoundError:
# AITER versions before the gated_delta_net directory rename.
from aiter.ops.triton._triton_kernels.gated_delta_rule.prefill.chunk_o import (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we report a error here or fallback to another kernel ?

@apinge apinge Oct 26, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we check the import of aiter at this stage as well ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Updated in c1783c7

):
from sglang.kernels.ops.attention.fla.l2norm import l2norm_fwd

_, prepare, recurrent, output = _aiter_ops()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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 ?

@yicyang yicyang Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the maintenance, its better to follow the format of other backend

@apinge apinge Oct 26, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the maintenance, its better to follow the format of other backend

Updated as suggested: added class AiterGDNKernel(LinearAttnKernelBase)

@apinge
apinge requested a balanced review from Copilot October 26, 2026 07:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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 behind SGLANG_USE_AITER_GDN_PREFILL.
  • Plumbs prefill metadata through ForwardMetadata, GDNAttnBackend, and TritonGDNKernel.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

@apinge
apinge requested a balanced review from Copilot October 26, 2026 13:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread python/sglang/srt/server_args.py Resolved
Comment thread python/sglang/srt/server_args.py Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need a fallback kernel ? As my understanding, the decode_kernel has been already wrapped here.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log added in b3dec9a


The forward metadata certifies real request rows.
"""
if q.ndim != 4 or k.shape != q.shape or v.ndim != 4:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall combine these 2 if check here ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 48ff3eb

@apinge
apinge force-pushed the qwen38-aiter-gdn-prefill branch from 48ff3eb to 1068f9f Compare November 4, 2026 05:35
@apinge
apinge requested a review from yicyang November 4, 2026 05:36
)


def _run_aiter_gdn_prefill(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I will open another pr to update it.

apinge and others added 15 commits November 4, 2026 08:57
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]>
@apinge
apinge force-pushed the qwen38-aiter-gdn-prefill branch from 1068f9f to 01ae2b3 Compare November 4, 2026 09:27
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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%

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding. I'll combined and added it in another pr.

@sammysun0711
sammysun0711 merged commit 4d63dea into qwen38-flash-next-amd-current-fix-install Nov 4, 2026
1 check failed
sammysun0711 added a commit that referenced this pull request Nov 10, 2026
* 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]>
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.

4 participants