Repository navigation
[ASM] Fix for num_local_tokens - #7110
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
df6278a to
eacdf93
Compare
* 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]>
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.
…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]>
…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]>
* 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]>
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