Skip to content

[Triton/Gluon] [FlyDSL] [MoE] Kimi-K3 HERD on gfx1250: K+1 sigmoid top-k and one route+psum kernel - #7494

Merged
coderfeli merged 7 commits into
mainfrom
cguo/k3-herd-main
Nov 6, 2026
Merged

coderfeli merged 7 commits into
mainfrom
cguo/k3-herd-main

Conversation

@charlieguo1106

@charlieguo1106 charlieguo1106 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Runs Kimi-K3 (E=896, K=16) HERD through fused_moe(herd_topk=K) on gfx1250, the way ATOM routes it (ROCm/ATOM#2713), and replaces the HERD route kernel at every expert count with one that finalizes, routes and prefix-sums in a single workgroup launch.

Motivation

  • Kimi-K3 routing fails on gfx1250. K3's router passes FP32 e_score_correction_bias with BF16 logits. Both the K3 decode routing (Top-16) and the HERD candidate routing (Top-17) take the HIP biased_grouped_topk on wave32, which aborts with Mixed bias dtype requires the register top-k path. The exact sigmoid top-k also admitted only K in {4, 8, 16}, not the K+1 widths HERD needs.
  • Wide MoEs paid four launches for HERD. fused_moe(herd_topk) dropped HERD candidates inside the grouped MoE route (moe_route_psum_herd) only up to 512 experts. K3's 896 experts were finalized up front (herd_finalize) and then took the counter fill, moe_route and psum_remap launches.

Changes

  • aiter/ops/topk.py
    • The gfx1250 exact sigmoid top-k admits K+1 widths 5, 9 and 17, and FP32 correction bias.
    • AITER_FLYDSL_HERD_MAX_M defaults to 1024, the most tokens fused_moe(herd_topk) takes.
  • aiter/ops/triton/.../topk_gating.py
    • Slots are padded to the next power of two and the stores are masked.
    • Unchanged for K = 4, 8, 16.
  • aiter/ops/flydsl/kernels/moe_herd_route_psum.py (new)
    • One workgroup does the HERD finalize, route, tile-aligned psum and row remap.
    • Handles up to 1024 experts and 1024 rows.
    • Routes and weights match herd_finalize_candidates bit for bit.
    • Candidates are staged in LDS with coalesced loads, kept routes are ordered with a sorting network, and the popularity and route counters are split by wave.
    • The builder rejects shapes over the LDS budget.
  • aiter/ops/flydsl/herd_topk.py
    • Adds the herd_route_psum() wrapper.
  • aiter/ops/flydsl/grouped_moe_gfx1250.py
    • The HERD route uses herd_route_psum at every expert count.
    • Removes herd_route_psum_remap and _get_compiled_route_psum_herd.
  • aiter/ops/flydsl/kernels/moe_contiguous_psum.py
    • Removes build_moe_route_psum_herd_module.
  • aiter/fused_moe.py

Behavior changes

All of these are on the opt-in HERD path (herd_topk / AITER_FLYDSL_USE_HERD=1), except the first.

  • gfx1250 biased_grouped_topk with K in {5, 9, 17} or an FP32 bias now takes the Triton exact sigmoid top-k. Previously it took HIP, which aborted for FP32 bias with BF16 logits.

  • HERD with E ≤ 512 (GPT-OSS, MiniMax-M3, DeepSeek-V4-Flash) now uses moe_herd_route_psum.

    • DeepSeek-V4-Flash-shaped fused_moe(herd_topk=6) (E=256, K=6, a8w4) gives bitwise-identical outputs to main at M = 16..1024.
  • fused_moe(herd_topk) on gfx1250 raises in two cases:

    • more than 1024 tokens;
    • the grouped MoE does not take the call.

    The second case already raised for E ≤ 512. For wider MoEs it previously finalized up front and fell back to the generic path.

  • AITER_FLYDSL_HERD_MAX_M now defaults to 1024, so ATOM's HERD decode window widens from 16..128 to 16..1024 for every model. Set AITER_FLYDSL_HERD_MAX_M=128 to keep the previous window.

  • gfx950: no behavior change.

    • Router-side HERD still caps at 128 tokens (_HERD_MAX_TOKENS).
    • fused_moe(herd_topk) is still rejected off gfx1250.

Performance (gfx1250)

Route kernel alone, uniform routing, moe_route_psum_herd → moe_herd_route_psum, us:

E, K M=16 M=128 M=512 M=1024
128, 4 3.5 → 3.0 3.8 → 3.1 6.7 → 3.7 10.6 → 4.9
256, 6 3.7 → 3.3 5.0 → 3.5 10.1 → 4.4 17.5 → 6.0
512, 8 4.1 → 4.0 6.2 → 4.2 15.9 → 5.3 28.5 → 7.1

Kimi-K3 TP8 MoE layer, HERD off → on. This is the sum of top-k, route, GEMM and gather/quant kernel time, median of 3 × 200 iterations, us (op_tests/test_flydsl_herd_k3_onoff.py):

M uniform skew 1.0
16 59.3 → 55.3 (-6.7%) 46.5 → 43.3 (-6.8%)
32 80.6 → 75.1 (-6.8%) 52.2 → 47.6 (-8.8%)
64 110.9 → 102.1 (-7.9%) 62.6 → 57.5 (-8.2%)
128 134.9 → 122.9 (-9.0%) 79.8 → 67.6 (-15.3%)
256 149.3 → 139.5 (-6.5%) 90.9 → 82.2 (-9.6%)
512 165.0 → 162.5 (-1.5%) 129.7 → 119.7 (-7.7%)
1024 187.5 → 186.7 (-0.4%) 159.4 → 147.2 (-7.6%)

The route stage goes from three kernels to one and is faster up to M=512 (for example 9.9 → 5.8 us at M=16).

Known limitation: at M=1024 the single-workgroup route is 1.5–2.4 us slower than HERD-off's multi-block route. The total MoE layer is still faster at M=1024 because of the GEMM saving.

Compatibility with ROCm/ATOM#2713

No ATOM change is needed:

  • Kimi-K3 routes Top-17 through biased_grouped_topk and calls fused_moe(herd_topk=16).
  • DeepSeek-V4-Flash routes Top-7 through topk_gating and calls fused_moe(herd_topk=6).

Checked with ATOM's call sequence: FP32 bias, renormalize=False, scale 1.0, no num_valid_rows / num_local_tokens, Situv2, a4w4 and a8w4, M = 16..1024, including CUDA graph replay. HERD-on outputs equal the K-route MoE over the HERD-kept routes.

Test

gfx1250, torch 2.11.0+rocm10.1.0a20260811, FlyDSL 0.4.1:

  • op_tests/test_flydsl_herd.py: 78 passed, 1 skipped (the gfx950 router-drop test)
  • op_tests/test_flydsl_herd_route_psum.py: 42 passed
  • op_tests/test_flydsl_herd_k3_onoff.py: 7 passed
  • op_tests/triton_tests/moe/moe_routing/test_topk_gating.py: 14 passed
  • op_tests/test_flydsl_moe_aux.py HERD route benchmark (gfx1250): checks pass
  • Benchmark: python op_tests/test_flydsl_herd_k3_onoff.py --kernels

…e+psum kernel

The gfx1250 exact sigmoid top-k produces the Top-(K+1) candidates
fused_moe(herd_topk=K) takes for Kimi-K3: it admits the K+1 widths 5, 9 and
17, padding its slots to a power of two and masking the stores, and
Kimi-K3's FP32 correction bias, which the wave32 HIP kernel rejects with
BF16 logits.

fused_moe(herd_topk) on gfx1250 dropped HERD candidates in the grouped MoE
route with moe_route_psum_herd only up to 512 experts; Kimi-K3's 896 were
finalized up front and then took the counter fill, route and psum remap
launches.

moe_herd_route_psum replaces moe_route_psum_herd at every expert count. One
workgroup does the HERD finalize, route, tile-aligned psum and row remap for
up to HERD_ROUTE_BLOCK (1024) experts and rows, with the routes and weights
of herd_finalize_candidates bit for bit. It picks each row's drop once,
where moe_route_psum_herd picked it again for each of the row's K routes: it
copies the candidates into LDS with coalesced loads and stages its outputs
there, orders the kept routes with a sorting network over id * 32 +
candidate keys, and splits the popularity and route counters into four
copies by wave so a hot expert does not serialize their atomics.

fused_moe(herd_topk) no longer finalizes the candidates ahead of the MoE at
any expert count. It takes at most 1024 tokens, and AITER_FLYDSL_HERD_MAX_M,
which bounds the steps ATOM routes with HERD on gfx1250, now defaults to it,
so larger batches route without HERD.

Kernel alone on gfx1250, uniform routing, moe_route_psum_herd ->
moe_herd_route_psum, us:
  E, K      M=16        M=128       M=512        M=1024
  128, 4    3.5 -> 3.0  3.8 -> 3.1   6.7 -> 3.7  10.6 -> 4.9
  256, 6    3.7 -> 3.3  5.0 -> 3.5  10.1 -> 4.4  17.5 -> 6.0
  512, 8    4.1 -> 4.0  6.2 -> 4.2  15.9 -> 5.3  28.5 -> 7.1
  896, 16      - -> 4.5    - -> 5.0     - -> 7.0     - -> 10.1

op_tests/test_flydsl_herd_route_psum.py checks fused_moe(herd_topk) against
the K-route MoE over the kept routes, with moe_herd_route_psum the only route
kernel launched. op_tests/test_flydsl_herd_k3_onoff.py benchmarks HERD off/on
for Kimi-K3 per stage and checks the on path's kernels and outputs.
@charlieguo1106
charlieguo1106 requested a review from a team November 5, 2026 05:46
@github-actions

github-actions Bot commented Nov 5, 2026

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 7494 --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.

@github-actions github-actions Bot changed the title [FlyDSL][MoE] Kimi-K3 HERD on gfx1250: K+1 sigmoid top-k and one route+psum kernel [Triton/Gluon] [FlyDSL] [MoE] Kimi-K3 HERD on gfx1250: K+1 sigmoid top-k and one route+psum kernel Nov 5, 2026
@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision e9c28d3e1124 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_herd.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_moe_aux.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/triton_tests/moe/moe_routing/test_topk_gating.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Resolve grouped_moe_gfx1250.py: keep the removal of herd_route_psum_remap,
which herd_route_psum replaces at every expert count, and carry #7271's
dispatch onto it: herd_route_psum launches through _run_compiled, so warmed
calls take the cached CompiledFunction, and passes current_stream_arg().
Remove op_tests/test_flydsl_herd_k3_onoff.py and
op_tests/test_flydsl_herd_route_psum.py, which do not follow
.claude/skills/aiter-op-test, and the tests this branch added to
test_topk_gating.py and test_flydsl_herd.py.

The tests of the removed herd_route_psum_remap / moe_route_psum_herd go as
well: test_grouped_route_psum_reuses_kernel_across_batches and
test_grouped_route_psum_skips_pad_rows in test_flydsl_herd.py, and
test_route_psum_herd with its run_torch_herd_drop reference in
test_flydsl_moe_aux.py. test_herd_topk_is_only_for_gfx1250 now expects the
grouped MoE to drop the candidates at any expert count.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Temporary normalized tensors can lose their last owner before the kernel launch, allowing storage reuse, while key routing, padding, and FP32-bias cases lack regression coverage.

5 open issues
What changed in this PR

This PR enables Kimi-K3 HERD routing on gfx1250 and replaces the grouped MoE HERD route with one FlyDSL kernel that finalizes candidates, routes tokens and computes prefix sums.

Changes:

  • Extends exact sigmoid top-k to K=5, 9 and 17 and FP32 correction bias.
  • Adds a fused HERD route for up to 1024 experts and rows, with cached launch dispatch.
  • Removes the previous HERD route implementation and up-front finalization for wide MoEs.
File Description
op_tests/​test_flydsl_moe_aux.py Removes the old HERD route benchmark and reference helper.
op_tests/​test_flydsl_herd.py Updates grouped-route expectations and removes old route-specific tests.
aiter/​ops/​triton/​moe/​moe_routing/​topk_gating.py Passes the padded top-k width to the kernel.
aiter/​ops/​triton/​_triton_kernels/​moe/​moe_routing/​topk_gating.py Pads selection slots and masks output stores.
aiter/​ops/​topk.py Expands sigmoid dispatch eligibility and the default HERD token window.
aiter/​ops/​flydsl/​kernels/​moe_herd_route_psum.py Adds the single-workgroup HERD finalize, route and prefix-sum kernel.
aiter/​ops/​flydsl/​kernels/​moe_contiguous_psum.py Removes the previous fused HERD route kernel.
aiter/​ops/​flydsl/​herd_topk.py Adds the herd_route_psum allocation and launch wrapper.
aiter/​ops/​flydsl/​grouped_moe_gfx1250.py Uses the new wrapper and removes the old launch helpers.
aiter/​fused_moe.py Enforces the 1024-token limit and removes wide-MoE up-front finalization.

Review effort: Balanced

Comment thread aiter/ops/flydsl/herd_topk.py Resolved
Comment thread aiter/ops/topk.py Resolved
…he launch

herd_route_psum gave ptr_arg the int32 / FP32 copies of the candidates as
temporaries. ptr_arg keeps only the address, so a copy was freed before the
launch, and the next copy could take its memory: with int64 ids and BF16
values the kernel read the values as ids. The copies now stay in local
variables until the launch is enqueued.
…oute kernels

The finalize kernel, _kept_routes (moe_sorting_herd) and moe_herd_route_psum
each had a copy of the drop selection and the kept-weight scale. _herd_drop
in kernels/herd_topk.py now holds the tie rules and the scale, and the three
kernels call it, so their routes and weights stay equal bit for bit. The
sorting network of moe_herd_route_psum stays local.
test_flydsl_herd.py checks herd_route_psum against the HERD finalize (bit
for bit) and the torch drop: kept ids, weights, per-expert counts, the
tile-aligned psum and that the rows fill each expert's band once. It covers
128 to 1024 experts, 1 to 1024 rows, tied values and a hot expert set, one
compiled kernel across batches, num_valid_rows changes under CUDA graph
replay, and int64 ids with BF16 values. test_herd_topk_is_only_for_gfx1250
checks that fused_moe(herd_topk) rejects 1025 tokens on gfx1250.

test_flydsl_moe_aux.py benchmarks herd_route_psum on gfx1250, eager and
graph replay, with a Kimi-K3 decode table (E=896, K=16, M=16..1024).
test_exact_sigmoid_topk_herd_widths runs K = 5, 9, 16 and 17 with BF16 and
FP32 correction bias, with and without renormalization, against the torch
reference. Rows past num_valid_rows must get ids -1 and weights 0, and
sentinels after each row's K slots must stay unchanged, so the padded slots
are not stored. BF16 bias also checks against the HIP kernel; FP32 bias does
not, because the wave32 HIP kernel aborts on a mixed bias dtype.
@coderfeli
coderfeli merged commit 7dcffae into main Nov 6, 2026
@coderfeli
coderfeli deleted the cguo/k3-herd-main branch November 6, 2026 03:53
yuychang added a commit to yuychang/aiter that referenced this pull request Nov 6, 2026
- Keep this PR's all-input output overlap check; drop main's hidden_states-only check and the unused bytes_overlap import
- Drop the HERD finalize block that main (ROCm#7494) moved out of _fused_moe_impl
- Hand the new caller-presort path kernel_output (16-byte rule) instead of its own 4-byte alignment check
- Keep both output-table rows: adaptive-aux sort now in place, caller presort zeroed unless the caller did
- test_presorted_moe_hook: 2- and 4-byte offsets now copy back; a 16-byte offset is used in place
RElbers added a commit that referenced this pull request Nov 6, 2026
- Restores the import of DROPPED_ROUTE_ROW from moe_route_maps, which the
  route remap uses for routes with no grouped row.

#7494 dropped the import on a branch where only comments still named the
constant; #7365, merged in between, had added a use in code, so the merged
file raised NameError and test_flydsl_moe_aux.py failed on main.
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
- Restores the import of DROPPED_ROUTE_ROW from moe_route_maps, which the
  route remap uses for routes with no grouped row.

#7494 dropped the import on a branch where only comments still named the
constant; #7365, merged in between, had added a use in code, so the merged
file raised NameError and test_flydsl_moe_aux.py failed on main.
charlieguo1106 added a commit to ROCm/ATOM that referenced this pull request Nov 11, 2026
…imi-K3

main (#2893) dropped FusedMoE.select_experts' mask_pad_rows, so the HERD
branch raised TypeError on its first decode step. Without it the Top-(K+1)
candidates route pad rows to -1 like _select_logical, and apply() passes the
same pass row count to fused_moe as num_local_tokens (#2905), which aiter's
herd_route_psum takes as num_valid_rows: the pad rows of a partly filled
graph bucket no longer vote in HERD's popularity.

The experts must run their pass's own rows. A DP-attention or PCP gather,
and simulated DP's repeat, interleave every rank's -1 pad rows, pass no count
and can exceed the 1024 rows fused_moe(herd_topk) takes, so use_flydsl_herd
stays off there.

HERD now serves DeepSeek-V4's sqrtsoftplus top-k and Kimi-K3's sigmoid
grouped top-k over one group only; both fold the routed scale in, which the
drop applies.

aiter's HERD constants import under a guard, and use_flydsl_herd needs
aiter v0.1.29 (ROCm/aiter#7494, probed by herd_route_psum): older aiter
aborts on Kimi-K3's Top-17 candidates with an FP32 bias.

test_flydsl_herd_routing binds the HERD candidate call to the real
FusedMoE.select_experts signature, and covers the routing set, the gather
guard, the aiter probe and the num_local_tokens hand-off.
test_flydsl_herd_graph_padding_gpu replays a bs=32 graph at 17, 1, 31 and 32
real rows against eager HERD over the real rows alone (gfx1250 only).
charlieguo1106 added a commit to ROCm/ATOM that referenced this pull request Nov 16, 2026
…2713)

* feat(moe): route FlyDSL MXFP4 decode through aiter HERD on gfx1250

With AITER_FLYDSL_USE_HERD=1, Mxfp4MoEMethod.apply() on gfx1250 picks the
Top-(K+1) sqrtsoftplus candidates with topk_gating and passes them to
fused_moe(herd_topk=K), which drops each token's least batch-popular
candidate, renormalizes and applies the routed scale (fused into the
route/prefix-sum kernel by default, AITER_HERD_FUSED_DROP=1).

Only decode steps whose batch is inside aiter's HERD window (16..128 tokens)
take this path, and only for TP (no EP or EPLB), GU-interleaved weights,
sqrtsoftplus routing with renormalization, no grouped top-k, no custom or
hash routing, no fused shared experts and no expert mask. Everything else
keeps select_experts.

* style(moe): sort the HERD import and use functools.cache

Fixes ruff I001 (aiter.ops.topk sorts after aiter.ops.shuffle) and UP033
(@cache instead of @lru_cache(maxsize=None)) on the FlyDSL HERD change.

* [MoE] Adapt FlyDSL HERD to aiter valid-row routing

* [MoE] Route FlyDSL HERD candidates through the layer's own top-k

The HERD branch of Mxfp4MoEMethod.select_experts forced a non-grouped
top-k, and _flydsl_herd_step admitted sqrtsoftplus only, so DeepSeek-V4
was the only model HERD could serve. Candidates now take the layer's own
routing at top_k + 1: topk_gating for sqrtsoftplus, fused_topk for
softmax (GPT-OSS) and biased_grouped_topk for a one-group grouped top-k
(Kimi-K3). Grouped top-k with more than one group keeps plain routes.

The drop applies the routed scale the layer's own routing folds in.
FusedMoE.routing_scale holds that rule and select_experts shares it:
grouped top-k and sqrtsoftplus fold the scale in, sigmoid only with a
fused shared column, softmax never.

Also sets use_flydsl_herd on the Mxfp4MoEMethod objects that
test_shared_expert_dispatch and test_mxfp4_triton_moe_decode build by
hand; the HERD hooks broke three of those tests.

* [MoE] Trim the FlyDSL HERD routing hooks

Cuts the HERD additions to atom/model_ops/moe.py from 134 to 71 lines
without changing behaviour:

- Drop the one-shot HERD batch log and FusedMoE.routing_scale; apply()
  takes the routed scale select_experts folds in (grouped top-k and
  sqrtsoftplus) inline, and select_experts is back to main.
- The HERD branch of select_experts leaves default arguments out.
- _flydsl_herd_step folds its checks into one condition and drops the
  expert_mask test, which use_flydsl_herd's not-EP check already covers.
- Shorter comments.

* [MoE] Route FlyDSL HERD pad rows like the plain routing

Since #2776, pure TP routes pad rows like real rows (mask_pad_rows=
layer.use_ep) and passes fused_moe no scheduled_tokens_gpu. The HERD
branch of select_experts kept the default mask, so its Top-(K+1)
candidates still carried -1 pad rows while fused_moe got no
num_local_tokens. aiter's HERD drop leaves -1 rows out only with that
count, so pure-TP HERD decode broke.

The HERD branch now takes the same mask_pad_rows as _select_logical:
pure TP routes its pad rows as real candidates, and a later change to
that policy applies to HERD as well.

* [MoE] Keep graph pad rows out of FlyDSL HERD; serve DeepSeek-V4 and Kimi-K3

main (#2893) dropped FusedMoE.select_experts' mask_pad_rows, so the HERD
branch raised TypeError on its first decode step. Without it the Top-(K+1)
candidates route pad rows to -1 like _select_logical, and apply() passes the
same pass row count to fused_moe as num_local_tokens (#2905), which aiter's
herd_route_psum takes as num_valid_rows: the pad rows of a partly filled
graph bucket no longer vote in HERD's popularity.

The experts must run their pass's own rows. A DP-attention or PCP gather,
and simulated DP's repeat, interleave every rank's -1 pad rows, pass no count
and can exceed the 1024 rows fused_moe(herd_topk) takes, so use_flydsl_herd
stays off there.

HERD now serves DeepSeek-V4's sqrtsoftplus top-k and Kimi-K3's sigmoid
grouped top-k over one group only; both fold the routed scale in, which the
drop applies.

aiter's HERD constants import under a guard, and use_flydsl_herd needs
aiter v0.1.29 (ROCm/aiter#7494, probed by herd_route_psum): older aiter
aborts on Kimi-K3's Top-17 candidates with an FP32 bias.

test_flydsl_herd_routing binds the HERD candidate call to the real
FusedMoE.select_experts signature, and covers the routing set, the gather
guard, the aiter probe and the num_local_tokens hand-off.
test_flydsl_herd_graph_padding_gpu replays a bs=32 graph at 17, 1, 31 and 32
real rows against eager HERD over the real rows alone (gfx1250 only).

* [MoE] Decide FlyDSL HERD in apply() as select_experts did, not by width

apply() told HERD's raw Top-(K+1) candidates from final routes by the ids'
width, which also had to rule out a fused shared column. It now asks the same
_flydsl_herd_step select_experts asked, over the same rows: HERD never runs on
gathered rows, so their count is the one routing saw. Nothing per step is kept
on the method.

No try around aiter: the HERD constants import directly, and the v0.1.29
check looks herd_route_psum up on aiter.ops.flydsl.herd_topk, which aiter has
had since those constants (v0.1.26). test_dp_gather_routed_rows stubs
aiter.ops.topk with the other aiter modules moe.py imports.
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.

5 participants