Skip to content

[GDN] [Backport] optimize: avoid fla l2-norm recompilation by token count (#31558) - #27

Open
sammysun0711 wants to merge 2 commits into
apinge:qwen3_5_v0.5.15_dflashfrom
sammysun0711:cherry-pick/gdn-l2norm-dynamic-token-count
Open

[GDN] [Backport] optimize: avoid fla l2-norm recompilation by token count (#31558)#27
sammysun0711 wants to merge 2 commits into
apinge:qwen3_5_v0.5.15_dflashfrom
sammysun0711:cherry-pick/gdn-l2norm-dynamic-token-count

Conversation

@sammysun0711

@sammysun0711 sammysun0711 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Backports upstream SGLang PR31558, PR33290 to the Qwen3.5 v0.5.15 branch.

Previous Qwen3.5_v0.5.9 branch used different, fused, already-warmed kernel fused_l2norm_qk

Current qwen3_5_v0.5.15_dflash branch call two l2norm_fwd for q and k.

Modifications

The change makes the L2Norm token count a runtime argument, preventing Triton from compiling a separate kernel for every unseen prefill length.

Accuracy Tests

Speed Tests and Profiling

Qwen3.5 397B PTPC FP8 TP8 Prefill 8K in/500 out, con=1 on MI308X, PTL:

  • L2Norm kernel variants: 15 -> 1
  • First-use cached-prefix TTFT median: 243.35 -> 177.72 ms (-27.0%)
  • Warm 64-token graph TTFT remains 53.9 - 54.3 ms
  • Outputs are identical across baseline and patched runs

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.

@sammysun0711
sammysun0711 force-pushed the cherry-pick/gdn-l2norm-dynamic-token-count branch from e0e9343 to bf765a0 Compare August 29, 2026 14:44
Reduce GDN prefill launches for benchmarked BF16/FP32 GPU shapes while preserving the original path on unsupported platforms, dtypes, layouts, and launch-bound wide shapes.

Signed-off-by: Xiake Sun <xiake.sun@amd.com>

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.

🟡 Changes recommended

The benchmark underreports memory traffic, and the fused implementation retains an unreachable kernel path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Backports runtime token-count handling and fused AMD Q/K L2 normalization to reduce Triton recompilation and launch overhead.

Changes:

  • Makes token counts runtime Triton arguments.
  • Adds fused HIP Q/K normalization with fallback dispatch.
  • Adds correctness, dispatch, and benchmark coverage.
File summaries
File Description
python/sglang/srt/layers/attention/fla/l2norm.py Updates and fuses L2Norm kernels.
python/sglang/srt/layers/attention/fla/chunk.py Adds HIP fused dispatch.
test/registered/jit/test_fused_gdn_l2norm.py Tests correctness and dispatch.
test/registered/jit/benchmark/bench_gdn_l2norm.py Benchmarks fused versus separate normalization.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

replay_iters=1200,
graph_clone_args=(0, 1),
memory_args=(q, k),
memory_output=None,
Comment on lines 145 to +146
else:
fused_l2norm_qk_kernel1[(tokens,)](
fused_l2norm_qk_kernel1[(max(TQ, TK),)](
Comment on lines +41 to +45
@pytest.mark.parametrize("dtype", [torch.bfloat16, torch.float32])
def test_fused_l2norm_qk_generic_d256(dtype):
torch.manual_seed(99)
q = torch.randn(257, 8, 256, dtype=dtype, device="cuda")
k = torch.randn(257, 8, 256, dtype=dtype, device="cuda")
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