Skip to content

[ASM] Fix for num_local_tokens - #7110

Merged
JohnNikolay84 merged 4 commits into
mainfrom
fix/asm_num_local_tokens
Oct 30, 2026
Merged

JohnNikolay84 merged 4 commits into
mainfrom
fix/asm_num_local_tokens

Conversation

@JohnNikolay84

@JohnNikolay84 JohnNikolay84 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Asm is loading number of tokens it should process based on topk output M size, but aiter now wants to support feature where the number of local tokens can be less num_local_tokens=n<M which will cause memory faults due to OOB access.

Technical Details

Need to load tokens count from the XC buffer.

should be 1 line asm change

// Change from:
s_load_dword s_token_cnt, s[0:1], 0xE0 // host-passed M

// To:
s_load_dword s_token_cnt, s_regs(_s_Xc_buf, 0), 0x4 // device-side n

One exception would be flat/emsort kernels that do not run sorting and therefore do not get this data prepared, we will pass instead the pointer to the num_local_token tensor there instead to avoid GPU copies.

Test Plan

Re-run aiter tests for the affected kernels.

Test Result

Submission Checklist

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7110 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@JohnNikolay84 JohnNikolay84 self-assigned this Oct 28, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 29, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 29, 2026
@JohnNikolay84
JohnNikolay84 marked this pull request as ready for review October 29, 2026 19:05
@JohnNikolay84
JohnNikolay84 requested a review from a team October 29, 2026 19:05
@github-actions github-actions Bot changed the title Fix for num_local_tokens [ASM] Fix for num_local_tokens Oct 29, 2026
@github-actions github-actions Bot added the ASM label Oct 29, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 29, 2026
@JohnNikolay84
JohnNikolay84 force-pushed the fix/asm_num_local_tokens branch from df6278a to eacdf93 Compare October 29, 2026 23:40
@ROCm ROCm deleted a comment from aiter-bot Oct 29, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 30, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 30, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 30, 2026
@ROCm ROCm deleted a comment from aiter-bot Oct 30, 2026
@JohnNikolay84
JohnNikolay84 merged commit 145d062 into main Oct 30, 2026
33 of 34 checks passed
@JohnNikolay84
JohnNikolay84 deleted the fix/asm_num_local_tokens branch October 30, 2026 18:11
@ROCm ROCm deleted a comment from aiter-bot Oct 30, 2026
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
* Fix for num_local_tokens

* Fix GPU fault and fix num_local_tokens for mxfp4

* Fixup more kernels to support num_local_tokens

---------

Co-authored-by: JiaoliangYu <[email protected]>
ZhiweiYan-96 added a commit that referenced this pull request Nov 9, 2026
The token 1/2/4/8 FLAT rows carried us1/us = 0. Re-measured on this branch
(after #7110 rebuilt both FLAT kernels), per-layer chain on MI355X, warm
weights: 11.46 / 12.04 / 17.85 / 22.62 us, vs 27.42 / 29.31 / 32.95 / 41.56 us
for the heuristic chain; rel L2 against a bf16-activation reference is the
same as the heuristic's at every token count.
gyohuangxin pushed a commit that referenced this pull request Nov 12, 2026
…rows (#6981)

* [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows

is_mxfp4_moe_shape_supported dropped (513, 4096, 256, 11), so Qwen3.5-397B at
TP4 silently fell back to the heuristic expert chain, and no tuned table held
that key either: configs/tuned_fmoe.csv has no expert=513 row at all, and
model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv had only (256,512,10),
(512,512,10) and (512,513,11), i.e. TP2's 513/11 but not TP4's.

No kernels have to be generated for the gate entry. The auxiliary instances do
not depend on the intermediate dimension: gen_instances.py unpacks each shape as
'for ne, h, e, topk in SHAPES' and no generator uses e, every instance being
named aux_<kind>_NE{ne}_TOPK{topk}_MB{mb}_H{h}. The generator relies on that --
its comment at line 358 is 'so dedup across shapes that share an (h, topk)', and
SHAPES already holds pairs differing only in e, such as (512,4096,256,10) with
(512,4096,512,10). D_INTER is a runtime argument of mxfp4_moe_sort. Instances for
NE=513, TOPK=11, H=4096 are already compiled from (513,4096,512,11).

The 7 tuned rows come from the bpreshuffle tuner on MI355X (gfx950, 256 CU) for
this shape: token <= 8 select the FLAT 1-stage asm kernel, token >= 16 the FlyDSL
a4w4 port. Per-layer CUDA-graph replay at token=4 goes 35.2 -> 20.4 us cold and
31.3 -> 18.3 us warm against the heuristic chain.

Measured end to end on Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2, TP4, AgentX, 3600 s
per point: with three ATOM-side changes alongside it, p90 interactivity rose from
307.1 to 357.0 tok/s/user against a baseline on the same image. GSM8K FP4 300
questions 3-shot: 0.750 strict against 0.730, no regression.

* [MXFP4 MoE] keep the TP4 gate entry in sync with gen_instances SHAPES

op_tests/test_mxfp4_moe_aux_codegen.py::test_supported_shapes_have_generated_instances
requires every MXFP4_MOE_SUPPORTED_SHAPES entry to appear in the codegen SHAPES
list, and moe_mxfp4_aux.py says to keep the two synchronized. Add
(513, 4096, 256, 11) to SHAPES as well. Instances are deduplicated by name and
none depend on the intermediate dimension, so the generated set is unchanged
(446 instances before and after).

Also list the TP4 key at token 1-64 in qwen3_5_397b_fp4_untuned_fmoe.csv so a
retune of this table covers the rows that the tuned table now carries.

* [MXFP4 MoE] Qwen3.5-397B TP4: record the FLAT rows' measured time

The token 1/2/4/8 FLAT rows carried us1/us = 0. Re-measured on this branch
(after #7110 rebuilt both FLAT kernels), per-layer chain on MI355X, warm
weights: 11.46 / 12.04 / 17.85 / 22.62 us, vs 27.42 / 29.31 / 32.95 / 41.56 us
for the heuristic chain; rel L2 against a bf16-activation reference is the
same as the heuristic's at every token count.

---------

Co-authored-by: qichu <[email protected]>
vpietila-amd pushed a commit that referenced this pull request Nov 12, 2026
…rows (#6981)

* [MXFP4 MoE] cover Qwen3.5-397B TP4: shape gate entry and tuned rows

is_mxfp4_moe_shape_supported dropped (513, 4096, 256, 11), so Qwen3.5-397B at
TP4 silently fell back to the heuristic expert chain, and no tuned table held
that key either: configs/tuned_fmoe.csv has no expert=513 row at all, and
model_configs/qwen3_5_397b_fp4_tuned_fmoe.csv had only (256,512,10),
(512,512,10) and (512,513,11), i.e. TP2's 513/11 but not TP4's.

No kernels have to be generated for the gate entry. The auxiliary instances do
not depend on the intermediate dimension: gen_instances.py unpacks each shape as
'for ne, h, e, topk in SHAPES' and no generator uses e, every instance being
named aux_<kind>_NE{ne}_TOPK{topk}_MB{mb}_H{h}. The generator relies on that --
its comment at line 358 is 'so dedup across shapes that share an (h, topk)', and
SHAPES already holds pairs differing only in e, such as (512,4096,256,10) with
(512,4096,512,10). D_INTER is a runtime argument of mxfp4_moe_sort. Instances for
NE=513, TOPK=11, H=4096 are already compiled from (513,4096,512,11).

The 7 tuned rows come from the bpreshuffle tuner on MI355X (gfx950, 256 CU) for
this shape: token <= 8 select the FLAT 1-stage asm kernel, token >= 16 the FlyDSL
a4w4 port. Per-layer CUDA-graph replay at token=4 goes 35.2 -> 20.4 us cold and
31.3 -> 18.3 us warm against the heuristic chain.

Measured end to end on Qwen3.5-397B-A17B-MXFP4-AttnFP8-V2, TP4, AgentX, 3600 s
per point: with three ATOM-side changes alongside it, p90 interactivity rose from
307.1 to 357.0 tok/s/user against a baseline on the same image. GSM8K FP4 300
questions 3-shot: 0.750 strict against 0.730, no regression.

* [MXFP4 MoE] keep the TP4 gate entry in sync with gen_instances SHAPES

op_tests/test_mxfp4_moe_aux_codegen.py::test_supported_shapes_have_generated_instances
requires every MXFP4_MOE_SUPPORTED_SHAPES entry to appear in the codegen SHAPES
list, and moe_mxfp4_aux.py says to keep the two synchronized. Add
(513, 4096, 256, 11) to SHAPES as well. Instances are deduplicated by name and
none depend on the intermediate dimension, so the generated set is unchanged
(446 instances before and after).

Also list the TP4 key at token 1-64 in qwen3_5_397b_fp4_untuned_fmoe.csv so a
retune of this table covers the rows that the tuned table now carries.

* [MXFP4 MoE] Qwen3.5-397B TP4: record the FLAT rows' measured time

The token 1/2/4/8 FLAT rows carried us1/us = 0. Re-measured on this branch
(after #7110 rebuilt both FLAT kernels), per-layer chain on MI355X, warm
weights: 11.46 / 12.04 / 17.85 / 22.62 us, vs 27.42 / 29.31 / 32.95 / 41.56 us
for the heuristic chain; rel L2 against a bf16-activation reference is the
same as the heuristic's at every token count.

---------

Co-authored-by: qichu <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
* Fix for num_local_tokens

* Fix GPU fault and fix num_local_tokens for mxfp4

* Fixup more kernels to support num_local_tokens

---------

Co-authored-by: JiaoliangYu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants