This document is relevant for: Trn2, Trn3
Kernel implementations#
Some of the performance in this plugin comes from NKI kernels that are vendored into the repository and modified for a specific model, rather than imported unchanged from the NKI Library. The pages in this section document those kernels: what each one computes, the design decisions behind its shape, its calling interface, and what changes when you map the same pattern onto a different model.
Kernel reference pages#
Exact FlashAttention-2 over a paged KV cache for chunk-causal DiTs (LingBot-World). Reads the history through a per-head block table with an on-chip sink + window mask, all-gathers the chunk’s K/V over CP inside the history pass, and writes the commit into the pool in place, block by block, so one graph serves every chunk; runs on Trainium 2 and Trainium 3 at LNC 1 and LNC 2.
Fine-grained collective compute for sequence-parallel projections on Trainium2. Chunks the all-gather before an all-gather + matmul or SwiGLU projection, and the reduce-scatter after a matmul + reduce-scatter projection, and issues them from inside the kernel so each chunk moves behind the matmuls, starting on the rank’s own rows.
Wan2.2 vendors other kernels — the MLP variants and the distributed VAE components — that are not documented here yet.
When a kernel belongs here#
These pages are for kernels you are expected to read and adapt. If you only want to call an operation as it ships, the NKI Library’s API reference is the right place, and adapting a vendored copy is the wrong move — you would be forking away from upstream fixes for no benefit.
A page in this section exists because the kernel embodies a design decision worth reusing. It is written to be useful even if you never run the kernel itself.