Skip to content

nki(flash_attention): NKI (Trainium) implementation - #276

Open
bowencui123 wants to merge 2 commits into
mainfrom
bowen/nki/flash_attention
Open

bowencui123 wants to merge 2 commits into
mainfrom
bowen/nki/flash_attention

Conversation

@bowencui123

@bowencui123 bowencui123 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

NKI (AWS Trainium) implementation of flash_attention, split out of the consolidated NKI branch cecilia/feature/nki-vector-add (nki-all-operators, #259) so each operator can be reviewed independently. Supersedes #220 (older per-operator branch: legacy neuronxcc.nki imports; this is the migrated import nki version).

Files: A benchmarks/operators/flash_attention/impl_nki.py

Status: verified on trn2 (default + autotune; full-unroll winner, NKI 9.26 ms @ b4 h32 s1024 d128 fp16)

  • includes NkiAutotuner wiring (search space over the kernel's tile/loop parameter; defaults unchanged)

Implementation by @Cecilia123li. Timing/identity infrastructure: #261; Trainium peak/roofline infra: #262.

🤖 Generated with Claude Code

https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL

Autotune (already on this branch)

NKI tunables Triton counterpart note
min_dynamic_iters (dynamic-loop vs unroll threshold) BLOCK_M/BLOCK_N q/kv blocks are fixed at 128 partitions

autotune=False keeps the previous constants. Validation on trn2, case 0:

# initial run
[flash_attention] default : verify=FAIL (288s) Comparing
[flash_attention] autotune: verify=FAIL (0s) last_config={'min_dynamic_iters': 3} trace_records=1 Comparing
STUB_EXIT=1
Params       |    Dtype |  Torch(ms) |      NKI(ms) |  Speedup(N)
n=16777216   | fp16     |     6.6620 |      44.3511 |        0.15
ALL_DONE
# re-validation (tolerance parsing fixed in the checker; engine line above stands)
[flash_attention] default : verify=OK (2s) 
[flash_attention] autotune: verify=OK (0s) last_config={'min_dynamic_iters': 3} trace_records=1 
STUB_EXIT=0

Split out of the consolidated NKI branch cecilia/feature/nki-vector-add
(nki-all-operators, PR #259) so each operator can be reviewed on its own.
Supersedes PR #220 (older per-operator branch).
- includes `NkiAutotuner` wiring (search space over the kernel's tile/loop parameter; defaults unchanged)

Co-Authored-By: Cecilia123li <68335867+Cecilia123li@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants