Fla kda

From fla-org/flash-linear-attention · View interactive version

Fla kda is an AI agent skill from the GitHub repository fla-org/flash-linear-attention. Modify or review KDA gates, chunk and recurrent kernels, backend routes, and their correctness coverage.

How to use this skill

Skill file

KDA

Use this skill for fla/ops/kda/ and its tests. Public entry points are chunk_kda and fused_recurrent_kda; inspect the affected entry point's signature before changing its implementation.

Code map

Gate contracts

chunk_kda takes log-space decay when use_gate_in_kernel=False. With it enabled, the caller supplies raw gates and optional bias:

safe_gate selects the intra-chunk implementation independently of gate activation. Safe in-kernel activation requires -5 <= lower_bound < 0. Pre-gated safe mode requires bounded log-space gates supplied by the caller; tests cover [-5, 0], but the wrapper does not validate tensor values.

Numerical invariants

The safe intra path uses 16-token diagonal blocks and midpoint offsets before exponentiation. At a lower bound of -5, a block can accumulate -80 in natural-log units; local offsets limit each exponent's span to about half that range. Preserve these offsets rather than exponentiating the full cumulative gate. Inter-block decay uses paired differences whose exponents remain non-positive for monotonic decay.

The non-safe path uses token-parallel diagonal computation. Both paths share inter-block and triangular-solve work, so changes there require coverage of both modes. Keep precision and tolerance changes within the design process in AGENTS.md.

Validation

Use correctness coverage for the test strategy. Select the KDA cases affected by the change:

For gate or decay changes, include the lower-bound limits, saturated gate inputs, extreme gate scales, long cumulative decay, and chunk or ragged-sequence boundaries. Test through the public entry point so the selected route and effective arguments are exercised.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.