Fuse gdr preprocess#4656
Open
grimoire wants to merge 3 commits into
Open
Conversation
094c02e to
4eecbd6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a fused “preprocess” path for Gated Delta Rule inputs (q/k replication + optional q/k L2-norm + beta/g computation + init-token masking), and wires models/backends to pass raw (b, a, dt_bias, a_log_exp) instead of precomputed (beta, g).
Changes:
- Added a Triton kernel (
gated_delta_preprocess) and CUDA-backend hook to fuse q/k/b/a preprocessing whenuse_qk_l2norm_in_kernelis enabled. - Updated
GatedDeltacall path + Qwen3 models to pass raw(b, a, dt_bias, a_log_exp)and rely on backend preprocessing. - Added new kernel tests covering both 3D/4D
(b, a)layouts and decoding/prefill behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/pytorch/kernel/test_gated_delta_preprocess.py | Adds tests validating fused preprocess outputs vs references/default prepare logic. |
| lmdeploy/pytorch/nn/gated_delta.py | Routes preprocessing through backend prepare_inputs; updates GatedDelta signature to accept raw (b, a, dt_bias, a_log_exp). |
| lmdeploy/pytorch/models/qwen3_next.py | Stops precomputing beta/g in-model; delegates to GatedDelta/backend. |
| lmdeploy/pytorch/models/qwen3_5.py | Stops precomputing beta/g in-model; delegates to GatedDelta/backend. |
| lmdeploy/pytorch/kernels/cuda/gated_delta_preprocess.py | New Triton-based fused preprocess kernel + Python wrapper. |
| lmdeploy/pytorch/backends/gated_delta_rule.py | Adds default prepare_inputs implementation to standardize preprocessing. |
| lmdeploy/pytorch/backends/cuda/gated_delta_rule.py | Overrides prepare_inputs to invoke fused preprocess kernel when enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fuse the preprocess of gated delta rule
Requirements