Skip to content

update gated delta rule state layout#4636

Merged
lvhan028 merged 7 commits into
InternLM:mainfrom
grimoire:change-gdr-state-layout
Jun 8, 2026
Merged

update gated delta rule state layout#4636
lvhan028 merged 7 commits into
InternLM:mainfrom
grimoire:change-gdr-state-layout

Conversation

@grimoire

Copy link
Copy Markdown
Collaborator

Transposed state is more friendly than default layout.

Copilot AI review requested due to automatic review settings May 28, 2026 10:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for a transposed recurrent-state memory layout in the CUDA fused gated-delta-rule kernel and updates Qwen3.5/Qwen3-Next integration to use that layout (intended to be more hardware-friendly than the previous default layout).

Changes:

  • Add transpose_state_layout support to the TileLang fused recurrent gated-delta-rule kernel, including shape validation and a specialized direct load/store path for [V, K] state layout.
  • Update Qwen3.5/Qwen3-Next recurrent state shapes and the GatedDelta call sites to use the transposed layout.
  • Extend kernel tests to cover transposed state, transposed state + state_indices, and transposed circular-buffer behavior; adjust one circular-buffer tolerance.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/pytorch/kernel/test_gated_delta_rule.py Adds coverage for transposed-state layout (including state_indices and circular buffer) and adjusts tolerance.
lmdeploy/pytorch/nn/gated_delta.py Always enables transposed-state layout when invoking gated-delta kernels.
lmdeploy/pytorch/kernels/cuda/gated_delta_rule.py Implements transposed-state layout path and input shape validation in the fused recurrent kernel.
lmdeploy/pytorch/configurations/qwen3_next.py Swaps recurrent state shape to [V, K] for Qwen3-Next.
lmdeploy/pytorch/configurations/qwen3_5.py Swaps recurrent state shape to [V, K] for Qwen3.5 (including spec-decoding shape).
lmdeploy/pytorch/backends/gated_delta_rule.py Extends backend API to accept transpose_state_layout (and cache_seqlens for fused recurrent).
lmdeploy/pytorch/backends/cuda/gated_delta_rule.py Threads transpose_state_layout through CUDA backend calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 188 to 200
core_attn_out, last_state = self.chunk_func(
q,
k,
v,
g=g,
beta=beta,
scale=scale,
initial_state=init_state,
output_final_state=output_final_state,
use_qk_l2norm_in_kernel=False,
cu_seqlens=cu_seqlens,
transpose_state_layout=transpose_state_layout,
)
@grimoire grimoire mentioned this pull request Jun 8, 2026
1 task
@RunningLeon

Copy link
Copy Markdown
Collaborator

may need to merge latest main to fix ut

@grimoire

grimoire commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

may need to merge latest main to fix ut

It is already done. Main branch has same problem.

@RunningLeon RunningLeon left a comment

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.

LGTM

@lvhan028 lvhan028 merged commit 0459539 into InternLM:main Jun 8, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants