[examples] Apply the KDA input preamble in the kernels - #3288
Draft
tarinduj wants to merge 1 commit into
Draft
Conversation
FlashKDA and vLLM both fold KDA's input preamble into the kernel: the q/k L2 norm, the gate activated from a raw projection, and the beta sigmoid. The engine required all three already applied. `helion_chunk_kda` now folds them in too, behind the same three flags FLA uses. The flags are forward only: FlashKDA implements no backward, and vLLM is an inference engine. ## What's here - **`use_qk_l2norm_in_kernel`** normalizes q and k in a new kernel, `l2norm_fwd_helion`. - **`use_gate_in_kernel`** applies the gate inside `chunk_cumsum_gc_helion`, in fp32 before the sum. - **`use_beta_sigmoid_in_kernel`** applies `torch.sigmoid` on the host. - **`naive_recurrent_reference`** applies all three transforms itself, so it checks the kernels on the same pre-activation inputs. ## Tests `test_linear_kda_fused_preamble` runs the flags through the same harness as `test_linear_kda`. A `kda_fused` variant in `benchmarks/run_linattn.py` benchmarks it on the same shapes as `kda`; being forward-only it emits no `-bwd` dashboard row, and the linattn benchmark matrix goes from 7 shards to 8. ## Benchmarks `%FLA = 100 * fla_ms / helion_ms` on H100, autotuned with `HELION_AUTOTUNE_EFFORT=full`. **Higher is faster than FLA.** `kda` takes the transformed inputs, `kda_fused` the raw ones with the flags on. Forward: | variant | B1_T8192_H96_D128 | B2_T16384_H16_D128 | B4_T2048_H16_D128 | B4_T4096_H64_D128 | B8_T2048_H32_D256 | B8_T1024_H8_D64 | |---|---|---|---|---|---|---| | kda | 119% | 116% | 104% | 117% | 109% | 98% | | kda_fused | 116% | 114% | 123% | 113% | 107% | 127% | Forward + backward: | variant | B1_T8192_H96_D128 | B2_T16384_H16_D128 | B4_T2048_H16_D128 | B4_T4096_H64_D128 | B8_T2048_H32_D256 | B8_T1024_H8_D64 | |---|---|---|---|---|---|---| | kda | 118% | 113% | 113% | 117% | 109% | 120% | stack-info: PR: #3288, branch: tarinduj/stack/2
tarinduj
force-pushed
the
tarinduj/stack/2
branch
from
August 5, 2026 22:34
bddd4bf to
7f77070
Compare
This was referenced Aug 5, 2026
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.
Stacked PRs:
[examples] Apply the KDA input preamble in the kernels
FlashKDA and vLLM both fold KDA's input preamble into the kernel: the q/k L2 norm, the gate activated from a raw projection, and the beta sigmoid. The engine required all three already applied.
helion_chunk_kdanow folds them in too, behind the same three flags FLA uses. The flags are forward only: FlashKDA implements no backward, and vLLM is an inference engine.What's here
use_qk_l2norm_in_kernelnormalizes q and k in a new kernel,l2norm_fwd_helion.use_gate_in_kernelapplies the gate insidechunk_cumsum_gc_helion, in fp32 before the sum.use_beta_sigmoid_in_kernelappliestorch.sigmoidon the host.naive_recurrent_referenceapplies all three transforms itself, so it checks the kernels on the same pre-activation inputs.Tests
test_linear_kda_fused_preambleruns the flags through the same harness astest_linear_kda. Akda_fusedvariant inbenchmarks/run_linattn.pybenchmarks it on the same shapes askda; being forward-only it emits no-bwddashboard row, and the linattn benchmark matrix goes from 7 shards to 8.Benchmarks
%FLA = 100 * fla_ms / helion_mson H100, autotuned withHELION_AUTOTUNE_EFFORT=full. Higher is faster than FLA.kdatakes the transformed inputs,kda_fusedthe raw ones with the flags on.Forward:
Forward + backward: