fla-kda

Guides modification and review of KDA kernels in the Flash Linear Attention library.

Updated Sep 11, 2026
One-click install
npx skills add https://github.com/swiss-ai/flash-linear-attention --skill fla-kda-swiss-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fla-kda
Source: https://github.com/swiss-ai/flash-linear-attention/tree/main/.agents/skills/fla-kda
Command: npx skills add https://github.com/swiss-ai/flash-linear-attention --skill fla-kda-swiss-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Working on Kimi Delta Attention (KDA) kernels in the flash-linear-attention repository requires deep knowledge of gate modes, safe_gate numerical constraints, intra/inter chunk kernels, and backend variants. This Skill encodes that domain knowledge so changes to fla/ops/kda/** stay numerically correct and consistent across code paths. ## Core Features & Use Cases - Public code map: Locates the exact functions for chunk forward, intra/inter kernels, WY recompute, backward passes, gate helpers, and FlashKDA/TileLang backends. - Gate mode contracts: Documents the pre-gated vs in-kernel gate modes, safe_gate activation formulas, and the lower_bound constraints (-5 <= lower_bound < 0). - Numerical safety notes: Explains midpoint-offset exponentiation in intra sub-chunk kernels and paired-offset decay ratios in inter-solve kernels to avoid exp2 overflow. - Correctness checklist: Enumerates test axes to cover (varlen, forward/backward, gate modes, GVA, CP paths, gate numerical extremes) before finishing a KDA change. - Use Case: When modifying chunk_kda_fwd_kernel_intra_sub_chunk to change decay handling, use this Skill to verify the safe and non-safe paths stay consistent and to select the right test coverage. ## Quick Start Use the fla-kda skill to review my changes to the KDA safe_gate intra kernel and tell me which tests I need to run.

Frequently Asked Questions about fla-kda

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I modify KDA kernels in flash-linear-attention safely?

Identify the affected path (safe vs non-safe intra, inter-solve, or backward) and keep both paths consistent unless the change is explicitly scoped to one. Then run correctness tests covering only the axes your change touches, such as varlen layouts, gate modes, and numerical extremes.

What is the difference between safe_gate and non-safe gate modes in chunk_kda?

With safe_gate, activation is lower_bound * sigmoid(exp(A_log) * (g + dt_bias)), keeping per-token gates in [lower_bound, 0). Without it, activation is -exp(A_log) * softplus(g + dt_bias). safe_gate requires use_gate_in_kernel=True and -5 <= lower_bound < 0.

Why does the KDA intra kernel use a midpoint offset before exp2?

With lower_bound=-5, a 16-token sub-chunk can accumulate -80 in natural-log units, which would overflow exp2 if fed the full cumulative span. The midpoint offset b_gm = b_g - b_gn limits each exponent operand to about half the sub-chunk, staying below the kernel's exp2 safety threshold.

Does chunk_kda support pre-gated inputs without A_log?

Yes. With use_gate_in_kernel=False, g is already the log-space decay tensor and A_log, dt_bias, and lower_bound are not part of the gate activation. With use_gate_in_kernel=True, A_log is required and dt_bias is optional.

What tests should I run after changing KDA gate math?

Cover dense and varlen layouts, forward and backward, all three gate modes, raw and post-sigmoid beta, MHA and GVA, and gate numerical extremes including lower_bound=-5, extreme A_log, long-sequence cumulative decay, chunk boundaries, and ragged varlen boundaries.

Which backends does KDA support in flash-linear-attention?

KDA supports the FlashKDABackend and the KDATileLangBackend. Changes affecting either backend should include backend verifier behavior in the correctness checklist.