-
Notifications
You must be signed in to change notification settings - Fork 193
perf: use fused gdn gating for qwen3.5 prefill. #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -393,15 +393,16 @@ torch::Tensor Qwen3GatedDeltaNetBaseImpl::forward( | |||||||||
|
|
||||||||||
| // Compute gated delta net decay and beta terms. | ||||||||||
| if (attn_metadata.is_prefill) { | ||||||||||
| beta = torch::sigmoid(b); | ||||||||||
| torch::Tensor A_log_exp = A_log_.exp(); | ||||||||||
| torch::Tensor a_float = a.to(torch::kFloat32); | ||||||||||
| torch::Tensor a_plus_dt = a_float + dt_bias_; | ||||||||||
| torch::Tensor softplus_out = torch::nn::functional::softplus( | ||||||||||
| a_plus_dt, | ||||||||||
| torch::nn::functional::SoftplusFuncOptions().beta(1.0).threshold(20.0)); | ||||||||||
| g = -A_log_exp * softplus_out; | ||||||||||
| g = g.to(a.dtype()).contiguous(); | ||||||||||
| xllm::kernel::FusedGdnGatingParams gdn_params; | ||||||||||
| gdn_params.A_log = A_log_; | ||||||||||
| gdn_params.a = a.contiguous().view({-1, a.size(-1)}); | ||||||||||
| gdn_params.b = b.contiguous().view({-1, b.size(-1)}); | ||||||||||
| gdn_params.dt_bias = dt_bias_; | ||||||||||
| gdn_params.beta = 1.0f; | ||||||||||
| gdn_params.threshold = 20.0f; | ||||||||||
| std::tie(g, beta) = xllm::kernel::fused_gdn_gating(gdn_params); | ||||||||||
| g = g.squeeze(0).contiguous().view({batch_size, seq_len, a.size(-1)}); | ||||||||||
| beta = beta.squeeze(0).contiguous().view({batch_size, seq_len, b.size(-1)}); | ||||||||||
|
Comment on lines
+404
to
+405
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The calls to
Suggested change
|
||||||||||
| } else { | ||||||||||
| xllm::kernel::FusedGdnGatingParams gdn_params; | ||||||||||
| gdn_params.A_log = A_log_; | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using
.reshape()over the.contiguous().view()pattern.reshape()is more idiomatic in PyTorch; it returns a view if the tensor is already contiguous and only performs a copy if necessary. This avoids redundant operations and potential memory allocations if the input tensorsaandbare already contiguous.