Skip to content

nki(linear_self_attention): NKI (Trainium) implementation - #287

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

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

Conversation

@bowencui123

@bowencui123 bowencui123 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

NKI (AWS Trainium) implementation of linear_self_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 #224 (older per-operator branch: legacy neuronxcc.nki imports; this is the migrated import nki version).

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

Status: imports and exposes run()/get_last_config() on trn2 (nki 0.6.0); not individually re-benchmarked in this split

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

🤖 Generated with Claude Code

https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL

Autotune (57a84ac)

NKI tunables Triton counterpart note
stageA_block_size_m/d, stageB_block_size_m/d (two tuners) BLOCK_M/BLOCK_N/BLOCK_K/BLOCK_D

autotune=False keeps the previous constants (default numbers unchanged). Validation on trn2, case 0 (default run + autotune code path with the candidate timer stubbed — no sweep; --autotune runs a real sweep):

# initial run
[linear_self_attention] default : verify=OK (2s) 
[linear_self_attention] autotune: verify=OK (0s) last_config={'stageA_block_size_m': 128, 'stageA_block_size_d': 128, 'stageB_block_size_m': 128, 'stageB_block_size_d': 128} trace_records=2 
STUB_EXIT=0
Params    |    Dtype |  Torch(ms) |      NKI(ms) |  Speedup(N)
n=32768   | fp32     |     0.0377 |       0.0616 |        0.61

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 #224 (older per-operator branch).

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
…/d`, `stageB_block_size_m/d`)

Tunables mirror the Triton search space (`BLOCK_M`/`BLOCK_N`/`BLOCK_K`/`BLOCK_D`); defaults are the previous constants,
so autotune=False is unchanged.

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.

2 participants