Skip to content

[HIP] [FlyDSL] Register top-k for E % 4 and mixed-dtype bias, a16w4 stage2 reduce mode, tuned tables - #7067

Merged
valarLip merged 1 commit into
mainfrom
topk-reg-path-a16w4-stage2-reduce
Oct 28, 2026
Merged

valarLip merged 1 commit into
mainfrom
topk-reg-path-a16w4-stage2-reduce

Conversation

@valarLip

Copy link
Copy Markdown
Collaborator

Summary

Top-k routing and a16w4 MoE changes on gfx950, with tuned-table updates.

Top-k routing

  • topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased top-k path now admits num_experts % 4 == 0 (lanes past the last expert in the final round are masked) and a correction bias whose dtype differs from the gating output (e.g. an fp32 bias with bf16 logits). emit_legacy_ordered_topk ranks candidates with one per-lane key (score, then legacy tie rank) instead of topk serial ballots.
  • topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 / weight 0 and returns before selection.
  • topk.py: biased_grouped_topk always takes biased_grouped_topk_hip; moe_fused_gate leaves routed_scaling_factor to the caller and measured slower at every row count.

MoE

  • fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the table's reduce mode, as a16wi4 already did; sorting allocates the matching output layout.
  • gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048.

Tuned tables

  • kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from atomic to reduce, tiles unchanged.
  • glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal or faster keep the new entries; rows that measured slower stay at their current entries.

Measurements (gfx950, MI355X, run_perftest; both arms identical except the CSV)

  • a16w4 fused_moe, reduce vs atomic stage2: 2-6% slower; mean relative error against an FP32 torch reference 5.1e-3 -> 2.8e-3; the reduce output is bit-identical across runs, while atomic varies between runs on the same input.
  • BF16 GEMM tables: no changed row is slower than the current table; some rows are about 5% faster, and one row's error drops from 2.2e-3 to 1.4e-3.

Test plan

  • black / ruff on the changed Python files
  • clang-format adds no new warning to warp_sort.h (the other two C++ files were not clang-format clean before this change either)
  • Kernel-level A/B above (fused_moe and tgemm.mm)
  • op_tests for biased grouped top-k with num_experts not a multiple of 64 and a bias dtype that differs from the gating output
  • op_tests/test_moe_2stage.py on the a16w4 reduce path

…tage2 reduce mode, tuned tables

Top-k routing
- topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased
  top-k path now admits num_experts % 4 == 0 (lanes past the last expert in
  the final round are masked) and a correction bias whose dtype differs from
  the gating output (e.g. an fp32 bias with bf16 logits).
  emit_legacy_ordered_topk ranks the candidates with one per-lane key
  (score, then legacy tie rank) instead of topk serial ballots.
- topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 /
  weight 0 and returns before selection.
- topk.py: biased_grouped_topk always takes biased_grouped_topk_hip;
  moe_fused_gate leaves routed_scaling_factor to the caller and measured
  slower at every row count.

MoE
- fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the
  table's reduce mode, as a16wi4 already did; sorting allocates the matching
  output layout.
- gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048, so the
  fixed buffers stay stable across graph captures and cover larger split-K
  grids.

Tuned tables
- kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from
  atomic to reduce with unchanged tiles. Measured on gfx950 (fused_moe,
  run_perftest): the output becomes bit-reproducible, mean relative error
  against an FP32 reference drops from 5.1e-3 to 2.8e-3, and time rises
  2-6%.
- glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal
  or faster keep the new entries; rows that measured slower stay at their
  current entries.
@valarLip
valarLip requested a review from a team October 28, 2026 05:33
@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 7067 --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.

@valarLip
valarLip merged commit 633bea1 into main Oct 28, 2026
36 checks passed
@valarLip
valarLip deleted the topk-reg-path-a16w4-stage2-reduce branch October 28, 2026 06:10
vpietila-amd pushed a commit that referenced this pull request Oct 28, 2026
…tage2 reduce mode, tuned tables (#7067)

Top-k routing
- topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased
  top-k path now admits num_experts % 4 == 0 (lanes past the last expert in
  the final round are masked) and a correction bias whose dtype differs from
  the gating output (e.g. an fp32 bias with bf16 logits).
  emit_legacy_ordered_topk ranks the candidates with one per-lane key
  (score, then legacy tie rank) instead of topk serial ballots.
- topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 /
  weight 0 and returns before selection.
- topk.py: biased_grouped_topk always takes biased_grouped_topk_hip;
  moe_fused_gate leaves routed_scaling_factor to the caller and measured
  slower at every row count.

MoE
- fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the
  table's reduce mode, as a16wi4 already did; sorting allocates the matching
  output layout.
- gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048, so the
  fixed buffers stay stable across graph captures and cover larger split-K
  grids.

Tuned tables
- kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from
  atomic to reduce with unchanged tiles. Measured on gfx950 (fused_moe,
  run_perftest): the output becomes bit-reproducible, mean relative error
  against an FP32 reference drops from 5.1e-3 to 2.8e-3, and time rises
  2-6%.
- glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal
  or faster keep the new entries; rows that measured slower stay at their
  current entries.
josh-schell-amd added a commit to josh-schell-amd/aiter that referenced this pull request Oct 28, 2026
Conflict: gemm_a16w16_gfx950_utils.py, where ROCm#7067 raised
SPLIT_K_SEMAPHORE_MAX_LEN to 2048 next to the new
GFX950_FLAT_BUFFER_LIMIT_BYTES; both kept.
zhiding512 added a commit that referenced this pull request Oct 29, 2026
No conflicts, but main changed code the deployment replay runs through:

- #7020: the MXFP4 inline sort takes num_local_tokens and skips expert
  ids outside [0, E), as the sentinel ids of EP callers are.
- #7067: the a16w4 stage-2 reduce mode in fused_moe.py and Kimi-K3's
  a16w4 table.
- #7068, #6668: gfx1250 grouped tables for DeepSeek-V4.1 MegaMoE EP and
  MiniMax-M3.
- #7055: the OPUS CO tests read local kernel IDs; this branch's 1-GPU CI
  shards failed on the global ones.

Co-authored-by: Cursor <[email protected]>
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
…tage2 reduce mode, tuned tables (#7067)

Top-k routing
- topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased
  top-k path now admits num_experts % 4 == 0 (lanes past the last expert in
  the final round are masked) and a correction bias whose dtype differs from
  the gating output (e.g. an fp32 bias with bf16 logits).
  emit_legacy_ordered_topk ranks the candidates with one per-lane key
  (score, then legacy tie rank) instead of topk serial ballots.
- topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 /
  weight 0 and returns before selection.
- topk.py: biased_grouped_topk always takes biased_grouped_topk_hip;
  moe_fused_gate leaves routed_scaling_factor to the caller and measured
  slower at every row count.

MoE
- fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the
  table's reduce mode, as a16wi4 already did; sorting allocates the matching
  output layout.
- gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048, so the
  fixed buffers stay stable across graph captures and cover larger split-K
  grids.

Tuned tables
- kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from
  atomic to reduce with unchanged tiles. Measured on gfx950 (fused_moe,
  run_perftest): the output becomes bit-reproducible, mean relative error
  against an FP32 reference drops from 5.1e-3 to 2.8e-3, and time rises
  2-6%.
- glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal
  or faster keep the new entries; rows that measured slower stay at their
  current entries.
zhiding512 added a commit that referenced this pull request Nov 4, 2026
No conflicts, but main changed code the deployment replay runs through:

- #7020: the MXFP4 inline sort takes num_local_tokens and skips expert
  ids outside [0, E), as the sentinel ids of EP callers are.
- #7067: the a16w4 stage-2 reduce mode in fused_moe.py and Kimi-K3's
  a16w4 table.
- #7068, #6668: gfx1250 grouped tables for DeepSeek-V4.1 MegaMoE EP and
  MiniMax-M3.
- #7055: the OPUS CO tests read local kernel IDs; this branch's 1-GPU CI
  shards failed on the global ones.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant