FLA Correctness & Coverage Skill
Use this skill when adding or modifying a kernel in fla/ops/ (e.g., KDA, GDN,
GLA, DeltaNet, NSA, etc.) and you need to verify correctness or close a coverage
gap.
Workflow
- List the current coverage matrix for the op you are touching.
- Compare against the axes below.
- Add tests for missing combinations that are reachable by user code.
- Run the relevant tests and make sure they pass.
Public reference docs
When a task needs operator math or protocol details, read only the relevant
reference file:
references/cp.md — context parallelism for linear attention, including KDA/GDN CP formulation.
references/delta-rule.md — Delta Rule operator background.
references/generalized-delta-rule.md — Generalized Delta Rule operator background.
references/simple-gla.md — Simple GLA operator background.
Do not load every reference by default; use these only when the touched code or
test depends on that operator's math or distributed protocol.
Coverage axes
For each kernel, check coverage across these dimensions:
| Axis |
Values to cover |
| Sequence layout |
dense, variable-length (varlen) |
| Direction |
forward, backward |
| Gate mode |
safe gate, non-safe gate (if applicable) |
| Beta mode |
raw beta, post-sigmoid beta (if applicable) |
| QK normalization |
with L2 norm, without L2 norm |
| State |
initial state, final state (if the op supports state passing) |
| GVA |
grouped value attention (GVA) enabled vs disabled |
| Head dimensions |
D != Dv (different qk and v head dims) |
| Backend verifier |
reference implementation, torch.autograd.gradcheck, and backend-specific sanity checks |
Kernel implementation safety checks
Before adding or changing a Triton kernel, check these implementation details in
addition to numerical tests:
- Treat program IDs and grid-derived values as potentially narrow. On NVIDIA,
non-first grid dimensions may be narrow; on AMD, Ascend, or other non-NVIDIA
backends, every grid dimension may be narrow. Cast to
tl.int64 before using
them in address arithmetic.
- Keep tensor address arithmetic in
tl.int64, including block bases, strides,
varlen sequence offsets, head offsets, and element offsets. Do not rely on
int16 or int32 overflow behavior.
- Do not introduce new
tl.make_block_ptr use. Triton marks it deprecated; use
TensorDescriptor / tl.make_tensor_descriptor when descriptor semantics are
needed, or explicit tl.load / tl.store pointer arithmetic following an
existing validated kernel pattern.
- If a change touches grid shape, program-id mapping, varlen offsets, or pointer
math, run a shape that exercises the changed path on NVIDIA and any supported
non-NVIDIA backend, or add a precise verifier/skip for unsupported platforms.
Code style constraints
- Use
fla.utils.device and fla.utils.device_platform in tests instead of
adding new hard-coded device strings.
- Use
IS_NVIDIA, IS_NVIDIA_HOPPER, IS_NVIDIA_BLACKWELL, IS_AMD, and
IS_INTEL from fla.utils for platform-specific skips or branches.
- Do not add new direct
torch.cuda platform checks in correctness tests. If no
existing helper covers the condition, add a small helper in fla.utils first.
Default open-source test paths
Use these paths when looking for existing tests or deciding where to add new ones:
tests/ops/test_kda.py — KDA kernel tests
tests/context_parallel/ — context-parallel variants (e.g., test_cp_kda.py, test_cp_gdn.py)
tests/models/test_modeling_kda.py — end-to-end model tests for KDA
Adapt the path to the specific op you are working on (replace kda with gdn,
gla, nsa, delta, etc.).
What NOT to put in this skill
- Internal-only test paths, local machine paths, private model names, and
private workload identifiers.
- The open-source skill only points to public tests and public operator docs.
Running tests
# Single op test
pytest tests/ops/test_kda.py -v
# Context parallel tests for the same op
pytest tests/context_parallel/test_cp_kda.py -v
# Model-level test
pytest tests/models/test_modeling_kda.py -v
# All dependent tests (see fla-mr-readiness skill)
python scripts/find_dependent_tests.py <changed_files>
1---2name: fla-correctness-coverage3description: Guidelines for kernel correctness testing and coverage in fla/ops/** and related modules, including common Triton grid/addressing pitfalls. Helps decide what tests to add or run before an MR.4---56# FLA Correctness & Coverage Skill78Use this skill when adding or modifying a kernel in `fla/ops/` (e.g., KDA, GDN,9GLA, DeltaNet, NSA, etc.) and you need to verify correctness or close a coverage10gap.1112## Workflow13141. **List the current coverage matrix** for the op you are touching.152. **Compare** against the axes below.163. **Add tests** for missing combinations that are reachable by user code.174. **Run** the relevant tests and make sure they pass.1819## Public reference docs2021When a task needs operator math or protocol details, read only the relevant22reference file:2324- `references/cp.md` — context parallelism for linear attention, including KDA/GDN CP formulation.25- `references/delta-rule.md` — Delta Rule operator background.26- `references/generalized-delta-rule.md` — Generalized Delta Rule operator background.27- `references/simple-gla.md` — Simple GLA operator background.2829Do not load every reference by default; use these only when the touched code or30test depends on that operator's math or distributed protocol.3132## Coverage axes3334For each kernel, check coverage across these dimensions:3536| Axis | Values to cover |37|------|-----------------|38| **Sequence layout** | dense, variable-length (`varlen`) |39| **Direction** | forward, backward |40| **Gate mode** | safe gate, non-safe gate (if applicable) |41| **Beta mode** | raw beta, post-sigmoid beta (if applicable) |42| **QK normalization** | with L2 norm, without L2 norm |43| **State** | initial state, final state (if the op supports state passing) |44| **GVA** | grouped value attention (GVA) enabled vs disabled |45| **Head dimensions** | `D != Dv` (different qk and v head dims) |46| **Backend verifier** | reference implementation, `torch.autograd.gradcheck`, and backend-specific sanity checks |4748## Kernel implementation safety checks4950Before adding or changing a Triton kernel, check these implementation details in51addition to numerical tests:5253- Treat program IDs and grid-derived values as potentially narrow. On NVIDIA,54 non-first grid dimensions may be narrow; on AMD, Ascend, or other non-NVIDIA55 backends, every grid dimension may be narrow. Cast to `tl.int64` before using56 them in address arithmetic.57- Keep tensor address arithmetic in `tl.int64`, including block bases, strides,58 varlen sequence offsets, head offsets, and element offsets. Do not rely on59 `int16` or `int32` overflow behavior.60- Do not introduce new `tl.make_block_ptr` use. Triton marks it deprecated; use61 `TensorDescriptor` / `tl.make_tensor_descriptor` when descriptor semantics are62 needed, or explicit `tl.load` / `tl.store` pointer arithmetic following an63 existing validated kernel pattern.64- If a change touches grid shape, program-id mapping, varlen offsets, or pointer65 math, run a shape that exercises the changed path on NVIDIA and any supported66 non-NVIDIA backend, or add a precise verifier/skip for unsupported platforms.6768## Code style constraints6970- Use `fla.utils.device` and `fla.utils.device_platform` in tests instead of71 adding new hard-coded device strings.72- Use `IS_NVIDIA`, `IS_NVIDIA_HOPPER`, `IS_NVIDIA_BLACKWELL`, `IS_AMD`, and73 `IS_INTEL` from `fla.utils` for platform-specific skips or branches.74- Do not add new direct `torch.cuda` platform checks in correctness tests. If no75 existing helper covers the condition, add a small helper in `fla.utils` first.7677## Default open-source test paths7879Use these paths when looking for existing tests or deciding where to add new ones:8081- `tests/ops/test_kda.py` — KDA kernel tests82- `tests/context_parallel/` — context-parallel variants (e.g., `test_cp_kda.py`, `test_cp_gdn.py`)83- `tests/models/test_modeling_kda.py` — end-to-end model tests for KDA8485Adapt the path to the specific op you are working on (replace `kda` with `gdn`,86`gla`, `nsa`, `delta`, etc.).8788## What NOT to put in this skill8990- Internal-only test paths, local machine paths, private model names, and91 private workload identifiers.92- The open-source skill only points to public tests and public operator docs.9394## Running tests9596```bash97# Single op test98pytest tests/ops/test_kda.py -v99100# Context parallel tests for the same op101pytest tests/context_parallel/test_cp_kda.py -v102103# Model-level test104pytest tests/models/test_modeling_kda.py -v105106# All dependent tests (see fla-mr-readiness skill)107python scripts/find_dependent_tests.py <changed_files>108```