Skip to content

feat(kda): add KDA attention components#1051

Merged
aolemila merged 1 commit into
sgl-project:mainfrom
MokusMokun:feat/kda-components
May 13, 2026
Merged

feat(kda): add KDA attention components#1051
aolemila merged 1 commit into
sgl-project:mainfrom
MokusMokun:feat/kda-components

Conversation

@MokusMokun
Copy link
Copy Markdown
Contributor

Summary

Adds the KDA (Kimi Delta Attention) inference components for sglang-jax, enabling hybrid linear-attention model serving (e.g. Kimi-Linear, #937). Includes DP support via shard_map.

Changes

Kernels (srt/kernels/kda/)

  • kda.py — chunked Pallas forward (gate cumsum → intra-chunk delta-rule solve → inter-chunk state propagation → output computation), varlen alignment helpers
  • naive.py — step-by-step recurrent reference, used as decode path and test baseline

Layers (srt/layers/attention/linear/)

  • short_convolution.py — stateless depthwise causal conv1d with EXTEND (cu_seqlens-aware) and DECODE (rolling cache) paths
  • kda_backend.pyKDAAttnBackend extending LinearRecurrentAttnBackend: conv → L2 norm → recurrent kernel dispatch, conv state pack/unpack, pool gather/scatter via shard_map for DP

Tests (test/)

  • test_short_conv.py — 24 tests, conv correctness vs nnx.Conv baseline (fp32 + bf16)
  • test_kda_attention.py — 9 backend tests at TP=4 (rtol/atol = 2e-2 / 1e-2)
  • test_kda_attention_dp.py — 9 DP tests covering DP=4/TP=1 and DP=2/TP=2 (sparse ranks, unbalanced batches, mixed has_initial_state, multi-round prefill→decode)

Test plan

  • pytest python/sgl_jax/test/test_short_conv.py → 24/24 (TPU v6e-4)
  • pytest python/sgl_jax/test/test_kda_attention.py → 9/9 (TPU v6e-4)
  • pytest python/sgl_jax/test/test_kda_attention_dp.py → 9/9 (TPU v6e-4)

References

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates Kimi Delta Attention (KDA) into the sglang-jax framework, enabling efficient hybrid linear-attention model serving. The implementation provides high-performance Pallas kernels for the forward pass, a dedicated attention backend, and robust support for data parallelism, ensuring the model scales effectively across distributed hardware configurations.

Highlights

  • KDA Implementation: Added Kimi Delta Attention (KDA) inference kernels and backend support to sglang-jax.
  • Convolution Support: Implemented a stateless depthwise causal conv1d layer (short_convolution) supporting both extend and decode paths.
  • Data Parallelism: Enabled DP support using shard_map for efficient scaling across multiple devices.
  • Testing: Added a comprehensive test suite covering KDA backend correctness and DP integration.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@MokusMokun MokusMokun force-pushed the feat/kda-components branch from 4d23248 to d009bbf Compare May 10, 2026 12:34
Comment thread python/sgl_jax/test/test_kda_attention.py
Comment thread python/sgl_jax/test/test_kda_attention_dp.py Outdated
Comment thread python/sgl_jax/test/test_kda_attention.py Outdated
Comment thread python/sgl_jax/test/test_kda_attention.py
Comment thread python/sgl_jax/test/test_kda_attention.py
Comment thread python/sgl_jax/test/test_kda_attention.py Outdated
Comment thread python/sgl_jax/test/test_kda_attention.py Outdated
Comment thread python/sgl_jax/test/test_kda_attention.py Outdated
Comment thread python/sgl_jax/test/test_kda_attention.py
Comment thread python/sgl_jax/test/test_kda_attention.py
Comment thread python/sgl_jax/test/test_kda_attention_dp.py
Comment thread python/sgl_jax/test/test_kda_attention_dp.py
Comment thread python/sgl_jax/test/test_kda_attention_dp.py
Comment thread python/sgl_jax/test/test_kda_attention_dp.py
Comment thread python/sgl_jax/test/test_kda_attention_dp.py
Comment thread python/sgl_jax/srt/layers/radix_linear_attention.py Outdated
@MokusMokun MokusMokun mentioned this pull request May 13, 2026
2 tasks
Comment thread python/sgl_jax/srt/layers/attention/linear/kda_backend.py
Comment thread python/sgl_jax/srt/kernels/kda/kda.py
@MokusMokun MokusMokun force-pushed the feat/kda-components branch from 644687e to 6e3801a Compare May 13, 2026 06:40
- Add KDA Pallas kernel (python/sgl_jax/srt/kernels/kda/) with naive reference
- Add KDA attention backend (linear/kda_backend.py) and short convolution layer
- Wire KDA into hybrid_linear_attn_backend and radix_linear_attention
- Add unit tests for TP and DP paths (test_kda_attention*.py, test_short_conv.py)
- Register tests in unit-test-tpu-v6e-4 suite
@MokusMokun MokusMokun force-pushed the feat/kda-components branch from 6e3801a to 6131a09 Compare May 13, 2026 07:41
@aolemila aolemila merged commit 666a1c9 into sgl-project:main May 13, 2026
17 of 18 checks passed
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.

3 participants