Skip to content

nki(weight_dequant): NKI (Trainium) implementation - #307

Open
bowencui123 wants to merge 8 commits into
mainfrom
bowen/nki/weight_dequant
Open

bowencui123 wants to merge 8 commits into
mainfrom
bowen/nki/weight_dequant

Conversation

@bowencui123

@bowencui123 bowencui123 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

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

Files: A benchmarks/operators/weight_dequant/impl_nki.py, M benchmarks/operators/weight_dequant/impl_torch.py

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

  • also carries the operator's impl_torch.py change from the NKI branch

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

🤖 Generated with Claude Code

https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL

Autotune (47dd19d)

NKI tunables Triton counterpart note
block_size (rows per tile inside a scale band, <=128) BLOCK_SIZE/TILE_SIZE TILE_SIZE is the quantization block (semantic, not tuned)

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
[weight_dequant] default : verify=OK (1s) 
[weight_dequant] autotune: verify=OK (0s) last_config={'block_size': 128} trace_records=1 
STUB_EXIT=0
Params     |    Dtype |  Torch(ms) |      NKI(ms) |  Speedup(N)
n=262144   | fp16     |     0.0304 |       0.0389 |        0.78

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 #192 (older per-operator branch).
- also carries the operator's `impl_torch.py` change from the NKI 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
bowencui123 and others added 2 commits August 29, 2026 08:38
Tunables mirror the Triton search space (`BLOCK_SIZE`/`TILE_SIZE`); defaults are the previous constants,
so autotune=False is unchanged. `TILE_SIZE` is the quantization block (semantic, not tuned)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Q38kGmXvyoeM1qtCbheSL
The non-XLA path is byte-identical to main; only the XLA device takes the
XLA-compatible variant. CPU equivalence of the two paths verified
(including non-divisible shapes); on trn2 case 0 still verifies and times
(torch 0.0232 ms, NKI 0.0349 ms).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Wvs1tztZTGQFD78YdZaha
@bowencui123

Copy link
Copy Markdown
Collaborator Author

Baseline policy (same rule applied across the NKI PRs): impl_torch.py is now device-dispatched instead of replacing the advanced-indexing gather globally — the non-XLA path is byte-identical to main, only XLA (where the gather faults at runtime with the DGE out-of-bound access) takes the repeat_interleave variant. CPU equivalence of the two paths verified incl. non-divisible M/N and TILE_SIZE > M; re-validated on trn2 (torch 0.0232 ms, NKI 0.0349 ms).

🤖 Generated with Claude Code

https://claude.ai/code/session_011Wvs1tztZTGQFD78YdZaha

Cecilia123li and others added 5 commits September 4, 2026 20:59
Merges NKI backend timing into results/csv/weight_dequant_default.csv, run
against this branch's impl_nki.py on trn2.3xlarge with the LNC2
execution contract (NEURON_LOGICAL_NC_CONFIG=2, NEURON_RT_NUM_CORES=1,
NEURON_CC_FLAGS="--target trn2 --lnc 2").

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AQseF7nyesBh8KZAp8g7Cm
…lock (broadcast per-tile scales), partition-stride-0 scale rows, no host pad; rerun default+autotune benchmarks

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ScXYNjrrKGgDUVNHxv7HJt
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