Skip to content

perf(b12x/moe): vectorize W4A8 M128 epilogue, add M96, skip tail barrier - #161

Closed
FujitsuPolycom wants to merge 1 commit into
local-inference-lab:mainfrom
FujitsuPolycom:perf/b12x-pcie-dma-priority-and-w4a8-m128
Closed

FujitsuPolycom wants to merge 1 commit into
local-inference-lab:mainfrom
FujitsuPolycom:perf/b12x-pcie-dma-priority-and-w4a8-m128

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Nov 28, 2026 •

Copy link
Copy Markdown

📌 Description

Why:
SM120 W4A8 M128 materialized MoE uses scalar shared loads and BF16
stores or atomic reductions in the down-projection epilogue. Tasks
with 65 to 96 valid rows pad to 128 rows, and the epilogue retains a
tail barrier when the pipeline has three or more stages.

What:

  • Load and write 128-bit vectors in W4A8MaterializedPhase2Kernel,
    using st_global_v4_u32 for deterministic output and
    red_add_global_v4_bf16x2 for routed accumulation when tile_n % 8 == 0,
    scatter_output base is 16-byte aligned, and scatter_n % 8 == 0,
    falling back to 4-byte st_global_u32 / red_add_global_bf16x2
    otherwise.
  • Guard Phase 0 st_global_v4_u32 zeroing and the monolithic
    MoEDynamicKernelBackend scatter_add_v4_bf16x2 epilogue on 16-byte
    base alignment (and scatter_N % 8 == 0 / tile_shape_mnk[1] % 8 == 0
    with a 4x scatter_add_bf16x2 fallback at +0/+4/+8/+12 bytes), lower
    scatter_output assumed_align to 4 in _get_dynamic_kernel and
    _launch_dynamic_flat so LLVM preserves the runtime checks, and enforce
    output alignment in b12x_moe_fp4 (4-byte for dynamic non-raw-route
    paths, 16-byte fail-closed for micro and raw-route paths).
  • Lower output assumed_align to 4 in W4A16TopKSumKernel (sum_launch.py),
    use 16-byte-aligned fc2_out for unused dummy pointer arguments, guard
    vec8_fast_path st_global_v4_u32 on 16-byte output alignment with a
    4x st_global_u32 fallback in sum.py, and bump the moe.w4a16.topk_sum
    compile spec from 7 to 8.
  • Add the compute_m=96 bucket in both materialized kernels (asserting
    compute_m % 8 == 0 in Phase 2 epilogue), skip the tail barrier when
    stages >= 3 (preload_slices = stages - 2 keeps next_stage disjoint
    from the prior compute stage), and bump the integration.tp_moe.dynamic
    compile spec from 22 to 23.
  • Add CPU invariant, direct Phase 2 alignment/bucket, monolithic NVFP4
    dynamic 4B/8B/12B alignment fallback, dynamic 4B/2B and micro 16B
    alignment, and direct W4A16TopKSumKernel 4B-aligned output tests in
    test_w4a8_prefill_m128.py and test_w4a16_route_sum.py.

Result:
Single-GPU NVIDIA GeForce RTX 5090 (SM120, driver 610.88, PyTorch
2.14.1+cu132, CUTLASS DSL 4.8.1) CUDA-graph A/B versus base 0ddf1a4
on W4A8 M128 prefill (E=384, H=5120, N=576, top-k 6, Zipf 1.1,
prequantized MXFP8 input, internal route planner, inline CSF scales,
3 interleaved trials x 30 replays with 128 MiB L2 flush; multi-GPU /
TP4 not exercised):

  • M=4096, det=False: 1808.35 us (trials 1807.33/1808.35/1809.41) ->
    1774.40 us (trials 1703.71/1774.40/1776.40), -33.95 us (-1.88%)
  • M=8192, det=False: 2596.64 us (trials 2591.71/2596.64/2632.18) ->
    2551.54 us (trials 2549.55/2551.54/2553.73), -45.10 us (-1.74%)
  • M=8192, det=True: 2993.09 us (trials 2990.13/2993.09/3004.70) ->
    2975.62 us (trials 2975.52/2975.62/2983.70), -17.47 us (-0.58%)
    Per-kernel CUDA profiler median on M=8192, det=False (15 L2-flushed
    runs): W4A8MaterializedPhase2Kernel 972.24 -> 931.87 us (-4.15%),
    W4A8MaterializedPhase1Kernel 1750.98 -> 1704.90 us (-2.63%).

Evidence:
Verified locally on single-GPU RTX 5090 (SM120, PyTorch 2.14.1+cu132,
CUTLASS DSL 4.8.1) from exact git archive HEAD (multi-GPU / TP4 not
exercised here):

  • tests/experimental/b12x/moe/test_w4a8_prefill_m128.py: 37 passed,
    0 failed (including test_w4a8_m128_validation_and_heuristics,
    test_w4a8_m128_compute_m96_and_no_tail_barrier_invariants,
    test_w4a8_m128_phase2_alignment_fallback_and_compute_m96_direct
    [False/True], test_w4a8_m128_output_2byte_alignment_rejected
    [dynamic 4B + micro 16B fail-closed],
    test_dynamic_monolithic_nvfp4_output_4byte_alignment_fallback
    [128-128, 512-16] across 4B/8B/12B mod-16 output offsets, and
    test_w4a8_m128_output_alignment_fallback_and_rejection [False/True]
    across 4B/8B/12B mod-16 output offsets)
  • tests/experimental/b12x/moe/test_w4a16_route_sum.py: 10 passed,
    0 failed (including test_route_sum_4byte_aligned_output [False/True])
  • tests/experimental/b12x/moe/test_route_sum_compile.py: 14 passed,
    0 failed
  • ruff 0.12.8 check clean across all 9 touched files;
    git merge-tree --write-tree 335459b HEAD clean;
    git diff --check clean.

Discord: Dooner

🧪 Tests

  • Tests have been added or updated as needed.

  • Exact-archive checks passed on candidate commit d8b6a60e24ed349c05f04e12484df0fbd3e0d56d: Verified on clean git archive (1x RTX 5090 SM120): ruff==0.12.8 clean, git merge-tree vs 335459b2 clean, test_w4a8_prefill_m128.py 37/37 passed, route_sum 24/24 passed, 0 unguarded 16B stores across dynamic/kernel.py/w4a8_phase2.py/sum.py, monolithic NVFP4 4B/8B/12B Probe C PASS, exact-SHA RTX 5090 CUDA-graph A/B -1.88% M=4096 / -1.74% M=8192 / -4.15% Phase 2.

    Suggested CI test targets: tests/experimental/b12x/moe/test_w4a8_prefill_m128.py tests/experimental/b12x/moe/test_w4a16_route_sum.py tests/experimental/b12x/moe/test_route_sum_compile.py

🔬 Experimental Track

Experimental b12x backend change. Scope and hardware limits are stated above.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 50fb064a-aee0-499a-b20c-005957e066f5
Commits

Reviewing files that changed from the base of the PR and between 335459b and d8b6a60.

Files selected for processing: 9

  • flashinfer/experimental/b12x/_lib/intrinsics/atomics.py
  • flashinfer/experimental/b12x/moe/_shared/kernels/dynamic/kernel.py
  • flashinfer/experimental/b12x/moe/_shared/kernels/w4a16/kernel/sum.py
  • flashinfer/experimental/b12x/moe/_shared/kernels/w4a16/kernel/sum_launch.py
  • flashinfer/experimental/b12x/moe/_shared/kernels/w4a8_phase1.py
  • flashinfer/experimental/b12x/moe/_shared/kernels/w4a8_phase2.py
  • flashinfer/experimental/b12x/moe/fused_moe/_impl.py
  • tests/experimental/b12x/moe/test_w4a16_route_sum.py
  • tests/experimental/b12x/moe/test_w4a8_prefill_m128.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Why:
SM120 W4A8 M128 materialized MoE uses scalar shared loads and BF16
stores or atomic reductions in the down-projection epilogue. Tasks
with 65 to 96 valid rows pad to 128 rows, and the epilogue retains a
tail barrier when the pipeline has three or more stages.

What:
- Load and write 128-bit vectors in W4A8MaterializedPhase2Kernel,
  using st_global_v4_u32 for deterministic output and
  red_add_global_v4_bf16x2 for routed accumulation when tile_n % 8 == 0,
  scatter_output base is 16-byte aligned, and scatter_n % 8 == 0,
  falling back to 4-byte st_global_u32 / red_add_global_bf16x2
  otherwise.
- Guard Phase 0 st_global_v4_u32 zeroing and the monolithic
  MoEDynamicKernelBackend scatter_add_v4_bf16x2 epilogue on 16-byte
  base alignment (and scatter_N % 8 == 0 / tile_shape_mnk[1] % 8 == 0
  with a 4x scatter_add_bf16x2 fallback at +0/+4/+8/+12 bytes), lower
  scatter_output assumed_align to 4 in _get_dynamic_kernel and
  _launch_dynamic_flat so LLVM preserves the runtime checks, and enforce
  output alignment in b12x_moe_fp4 (4-byte for dynamic non-raw-route
  paths, 16-byte fail-closed for micro and raw-route paths).
- Lower output assumed_align to 4 in W4A16TopKSumKernel (sum_launch.py),
  use 16-byte-aligned fc2_out for unused dummy pointer arguments, guard
  vec8_fast_path st_global_v4_u32 on 16-byte output alignment with a
  4x st_global_u32 fallback in sum.py, and bump the moe.w4a16.topk_sum
  compile spec from 7 to 8.
- Add the compute_m=96 bucket in both materialized kernels (asserting
  compute_m % 8 == 0 in Phase 2 epilogue), skip the tail barrier when
  stages >= 3 (preload_slices = stages - 2 keeps next_stage disjoint
  from the prior compute stage), and bump the integration.tp_moe.dynamic
  compile spec from 22 to 23.
- Add CPU invariant, direct Phase 2 alignment/bucket, monolithic NVFP4
  dynamic 4B/8B/12B alignment fallback, dynamic 4B/2B and micro 16B
  alignment, and direct W4A16TopKSumKernel 4B-aligned output tests in
  test_w4a8_prefill_m128.py and test_w4a16_route_sum.py.

Result:
Single-GPU NVIDIA GeForce RTX 5090 (SM120, driver 610.88, PyTorch
2.14.1+cu132, CUTLASS DSL 4.8.1) CUDA-graph A/B versus base 0ddf1a4
on W4A8 M128 prefill (E=384, H=5120, N=576, top-k 6, Zipf 1.1,
prequantized MXFP8 input, internal route planner, inline CSF scales,
3 interleaved trials x 30 replays with 128 MiB L2 flush; multi-GPU /
TP4 not exercised):
- M=4096, det=False: 1808.35 us (trials 1807.33/1808.35/1809.41) ->
  1774.40 us (trials 1703.71/1774.40/1776.40), -33.95 us (-1.88%)
- M=8192, det=False: 2596.64 us (trials 2591.71/2596.64/2632.18) ->
  2551.54 us (trials 2549.55/2551.54/2553.73), -45.10 us (-1.74%)
- M=8192, det=True:  2993.09 us (trials 2990.13/2993.09/3004.70) ->
  2975.62 us (trials 2975.52/2975.62/2983.70), -17.47 us (-0.58%)
Per-kernel CUDA profiler median on M=8192, det=False (15 L2-flushed
runs): W4A8MaterializedPhase2Kernel 972.24 -> 931.87 us (-4.15%),
W4A8MaterializedPhase1Kernel 1750.98 -> 1704.90 us (-2.63%).

Evidence:
Verified locally on single-GPU RTX 5090 (SM120, PyTorch 2.14.1+cu132,
CUTLASS DSL 4.8.1) from exact git archive HEAD (multi-GPU / TP4 not
exercised here):
- tests/experimental/b12x/moe/test_w4a8_prefill_m128.py: 37 passed,
  0 failed (including test_w4a8_m128_validation_and_heuristics,
  test_w4a8_m128_compute_m96_and_no_tail_barrier_invariants,
  test_w4a8_m128_phase2_alignment_fallback_and_compute_m96_direct
  [False/True], test_w4a8_m128_output_2byte_alignment_rejected
  [dynamic 4B + micro 16B fail-closed],
  test_dynamic_monolithic_nvfp4_output_4byte_alignment_fallback
  [128-128, 512-16] across 4B/8B/12B mod-16 output offsets, and
  test_w4a8_m128_output_alignment_fallback_and_rejection [False/True]
  across 4B/8B/12B mod-16 output offsets)
- tests/experimental/b12x/moe/test_w4a16_route_sum.py: 10 passed,
  0 failed (including test_route_sum_4byte_aligned_output [False/True])
- tests/experimental/b12x/moe/test_route_sum_compile.py: 14 passed,
  0 failed
- ruff 0.12.8 check clean across all 9 touched files;
  git merge-tree --write-tree 335459b HEAD clean;
  git diff --check clean.

Discord: Dooner
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
@FujitsuPolycom
FujitsuPolycom force-pushed the perf/b12x-pcie-dma-priority-and-w4a8-m128 branch from 295bb25 to d8b6a60 Compare November 29, 2026 04:13
FujitsuPolycom added a commit to FujitsuPolycom/flashinfer that referenced this pull request Nov 29, 2026
Why:
Static CTA strides leave a long tail with skewed expert routing in
SM120 W4A8 M128 prefill MoE. Four row buckets also pad sparse tiles,
and scalar epilogue loads add instructions on the M128xN64 path.

What:
Stacked on PR local-inference-lab#161 (d8b6a60).
- Claim tiles dynamically from atomic counters in
  W4A8MaterializedPhase1Kernel and W4A8MaterializedPhase2Kernel,
  group N64 tiles in strips of three for L2 reuse, dispatch to six
  row buckets (16, 32, 48, 64, 96, 128), and vectorize the M128xN64
  up-projection epilogue's shared loads.
- Guarantee both work-stealing counters (task_head and
  producers_done_count) are zeroed across every launch and CUDA-graph
  replay path:
  - Zero task_head and p2_task_head in _prequant_route_init_zero_kernel
    and _dynamic_route_plan_kernel (plus matching _preparation.py
    compile_dynamic_route_plan warmups) and under volatile_launch_state
    when external_route_plan is disabled.
  - Reset p2_task_head in W4A8MaterializedPhase1Kernel and symmetrically
    reset p1_task_head in W4A8MaterializedPhase2Kernel.
  - Guard Phase 2 dynamic work stealing on fused_groups == 1 (with
    explicit assertions against tile_m == 128 and fused_groups > 1).
  - Skip initial work-steal atomic increments when task_tail == 0 in
    both Phase 1 and Phase 2 while still executing the opposite-phase
    reset.
  - Advance the integration.tp_moe.dynamic compile spec from 23 to 24.
- Add CPU swizzle/bucket/reset-contract tests, direct Phase 1/2
  work-stealing and empty-launch tests, Triton route-plan counter-reset
  tests, and end-to-end poisoned-scratch replay tests covering
  mxfp8+triton+M128, bf16+triton+M16, and bf16+internal+M128 in
  tests/experimental/b12x/moe/test_w4a8_prefill_m128.py.

Result:
Single-GPU NVIDIA GeForce RTX 5090 (SM120) CUDA-graph comparison at
M=8192, H=5120, E=384, k=6, N=576, Zipf 1.1 with the Triton route
planner and inline scales (including the PR local-inference-lab#161 epilogue prerequisite)
previously recorded 2697.8 -> 2424.5 us mean median, with zero BF16
bit differences across 41,943,040 deterministic outputs versus M64.

Evidence:
Verified locally on single-GPU RTX 5090 (SM120, PyTorch 2.14.1+cu132,
CUTLASS DSL 4.8.1) from exact git archive HEAD (multi-GPU / TP4 not
exercised here):
- tests/experimental/b12x/moe/test_w4a8_prefill_m128.py: 47 passed,
  0 failed (including test_w4a8_m128_validation_and_heuristics,
  test_w4a8_m128_compute_m96_and_no_tail_barrier_invariants,
  test_w4a8_m128_worksteal_swizzle_buckets_and_reset_contracts,
  test_w4a8_m128_triton_route_plan_kernels_zero_worksteal_counters,
  test_w4a8_m128_phase1_worksteal_n3_swizzle_and_empty_direct,
  test_w4a8_m128_phase2_worksteal_counter_reset_and_empty_direct,
  test_w4a8_m128_phase2_alignment_fallback_and_compute_m96_direct
  [False/True], test_w4a8_m128_output_2byte_alignment_rejected,
  test_dynamic_monolithic_nvfp4_output_4byte_alignment_fallback
  [128-128, 512-16],
  test_w4a8_m128_output_alignment_fallback_and_rejection [False/True],
  and test_w4a8_m128_poisoned_scratch_replay across mxfp8-triton-m128,
  bf16-triton-m16, and bf16-internal-m128)
- compile_dynamic_route_plan warmups: 3/3 passed for
  (preq=False, full=False), (preq=True, full=False), and
  (preq=True, full=True)
- ruff 0.12.8 check clean across all 6 touched files;
  git merge-tree --write-tree 335459b HEAD clean;
  git diff --check clean.

Discord: Dooner
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>

@voipmonitor voipmonitor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified overnight commit d8b6a60e2 on RTX PRO 6000 Blackwell (SM120) — ready to merge (base for #168)!

  • no_tail_barrier = stages >= 3, M=96 tile bucket, and 128-bit st_global_v4_u32 / red_add_global_v4_bf16x2 epilogue with 16B alignment guards & 4B fallback are race-free and verified on SM120 (-1.9% to -2.4% standalone on skewed DeepSeek E=384, H=5120, N=576).
  • Merge order: Merge #161 first, then #168 on top.

4× RTX PRO 6000 Blackwell (SM120) E2E Stack Verification (gb202-preview, pure hyperflare-inference@19c098c8 + all 19 hardened PRs):

  • HF Preview Core: https://huggingface.co/local-inference-lab/DeepSeek-V4.1-Flash-1017-FLARE/tree/gb202-preview (e4ce7ebb)
  • Cold Prefill (wall / GPU vs gb202): 8K 47.6k / 50.4k (+9.4%), 16K 56.9k / 58.6k (+10.1%), 32K 62.5k / 63.7k (+10.7%), 64K 65.1k / 66.4k (+10.5%, 1.097s), 128K 64.4k / 65.9k (+10.4%)
  • Decode Concurrency (P=256 & P=2048): C=6 +7.5%, C=8 +4.0%, C=12 +11.2%, C=16 +14.2%, C=24 +4.8%, C=32 +4.2%, C=32@2K +5.4% (-5.8% step)
  • KV Cache / VRAM: 14.80 GiB/GPU (16,962,176 KV tokens = 99.64% of baseline 17,023,872) · -712 fewer kernels (40,347 vs 41,059) · 5/5 NIAH · 4/4 Vision · Greedy 391 PASS

lukealonso pushed a commit that referenced this pull request Nov 29, 2026
* perf(b12x/moe): vectorize the W4A8 M128 down-projection epilogue

Why:
SM120 W4A8 M128 materialized MoE uses scalar shared loads and BF16
stores or atomic reductions in the down-projection epilogue. Tasks
with 65 to 96 valid rows pad to 128 rows, and the epilogue retains a
tail barrier when the pipeline has three or more stages.

What:
- Load and write 128-bit vectors in W4A8MaterializedPhase2Kernel,
  using st_global_v4_u32 for deterministic output and
  red_add_global_v4_bf16x2 for routed accumulation when tile_n % 8 == 0,
  scatter_output base is 16-byte aligned, and scatter_n % 8 == 0,
  falling back to 4-byte st_global_u32 / red_add_global_bf16x2
  otherwise.
- Guard Phase 0 st_global_v4_u32 zeroing and the monolithic
  MoEDynamicKernelBackend scatter_add_v4_bf16x2 epilogue on 16-byte
  base alignment (and scatter_N % 8 == 0 / tile_shape_mnk[1] % 8 == 0
  with a 4x scatter_add_bf16x2 fallback at +0/+4/+8/+12 bytes), lower
  scatter_output assumed_align to 4 in _get_dynamic_kernel and
  _launch_dynamic_flat so LLVM preserves the runtime checks, and enforce
  output alignment in b12x_moe_fp4 (4-byte for dynamic non-raw-route
  paths, 16-byte fail-closed for micro and raw-route paths).
- Lower output assumed_align to 4 in W4A16TopKSumKernel (sum_launch.py),
  use 16-byte-aligned fc2_out for unused dummy pointer arguments, guard
  vec8_fast_path st_global_v4_u32 on 16-byte output alignment with a
  4x st_global_u32 fallback in sum.py, and bump the moe.w4a16.topk_sum
  compile spec from 7 to 8.
- Add the compute_m=96 bucket in both materialized kernels (asserting
  compute_m % 8 == 0 in Phase 2 epilogue), skip the tail barrier when
  stages >= 3 (preload_slices = stages - 2 keeps next_stage disjoint
  from the prior compute stage), and bump the integration.tp_moe.dynamic
  compile spec from 22 to 23.
- Add CPU invariant, direct Phase 2 alignment/bucket, monolithic NVFP4
  dynamic 4B/8B/12B alignment fallback, dynamic 4B/2B and micro 16B
  alignment, and direct W4A16TopKSumKernel 4B-aligned output tests in
  test_w4a8_prefill_m128.py and test_w4a16_route_sum.py.

Result:
Single-GPU NVIDIA GeForce RTX 5090 (SM120, driver 610.88, PyTorch
2.14.1+cu132, CUTLASS DSL 4.8.1) CUDA-graph A/B versus base 0ddf1a4
on W4A8 M128 prefill (E=384, H=5120, N=576, top-k 6, Zipf 1.1,
prequantized MXFP8 input, internal route planner, inline CSF scales,
3 interleaved trials x 30 replays with 128 MiB L2 flush; multi-GPU /
TP4 not exercised):
- M=4096, det=False: 1808.35 us (trials 1807.33/1808.35/1809.41) ->
  1774.40 us (trials 1703.71/1774.40/1776.40), -33.95 us (-1.88%)
- M=8192, det=False: 2596.64 us (trials 2591.71/2596.64/2632.18) ->
  2551.54 us (trials 2549.55/2551.54/2553.73), -45.10 us (-1.74%)
- M=8192, det=True:  2993.09 us (trials 2990.13/2993.09/3004.70) ->
  2975.62 us (trials 2975.52/2975.62/2983.70), -17.47 us (-0.58%)
Per-kernel CUDA profiler median on M=8192, det=False (15 L2-flushed
runs): W4A8MaterializedPhase2Kernel 972.24 -> 931.87 us (-4.15%),
W4A8MaterializedPhase1Kernel 1750.98 -> 1704.90 us (-2.63%).

Evidence:
Verified locally on single-GPU RTX 5090 (SM120, PyTorch 2.14.1+cu132,
CUTLASS DSL 4.8.1) from exact git archive HEAD (multi-GPU / TP4 not
exercised here):
- tests/experimental/b12x/moe/test_w4a8_prefill_m128.py: 37 passed,
  0 failed (including test_w4a8_m128_validation_and_heuristics,
  test_w4a8_m128_compute_m96_and_no_tail_barrier_invariants,
  test_w4a8_m128_phase2_alignment_fallback_and_compute_m96_direct
  [False/True], test_w4a8_m128_output_2byte_alignment_rejected
  [dynamic 4B + micro 16B fail-closed],
  test_dynamic_monolithic_nvfp4_output_4byte_alignment_fallback
  [128-128, 512-16] across 4B/8B/12B mod-16 output offsets, and
  test_w4a8_m128_output_alignment_fallback_and_rejection [False/True]
  across 4B/8B/12B mod-16 output offsets)
- tests/experimental/b12x/moe/test_w4a16_route_sum.py: 10 passed,
  0 failed (including test_route_sum_4byte_aligned_output [False/True])
- tests/experimental/b12x/moe/test_route_sum_compile.py: 14 passed,
  0 failed
- ruff 0.12.8 check clean across all 9 touched files;
  git merge-tree --write-tree 335459b HEAD clean;
  git diff --check clean.

Discord: Dooner
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>

* perf(b12x/moe): balance W4A8 M128 tiles with atomic work stealing

Why:
Static CTA strides leave a long tail with skewed expert routing in
SM120 W4A8 M128 prefill MoE. Four row buckets also pad sparse tiles,
and scalar epilogue loads add instructions on the M128xN64 path.

What:
Stacked on PR #161 (d8b6a60).
- Claim tiles dynamically from atomic counters in
  W4A8MaterializedPhase1Kernel and W4A8MaterializedPhase2Kernel,
  group N64 tiles in strips of three for L2 reuse, dispatch to six
  row buckets (16, 32, 48, 64, 96, 128), and vectorize the M128xN64
  up-projection epilogue's shared loads.
- Guarantee both work-stealing counters (task_head and
  producers_done_count) are zeroed across every launch and CUDA-graph
  replay path:
  - Zero task_head and p2_task_head in _prequant_route_init_zero_kernel
    and _dynamic_route_plan_kernel (plus matching _preparation.py
    compile_dynamic_route_plan warmups) and under volatile_launch_state
    when external_route_plan is disabled.
  - Reset p2_task_head in W4A8MaterializedPhase1Kernel and symmetrically
    reset p1_task_head in W4A8MaterializedPhase2Kernel.
  - Guard Phase 2 dynamic work stealing on fused_groups == 1 (with
    explicit assertions against tile_m == 128 and fused_groups > 1).
  - Skip initial work-steal atomic increments when task_tail == 0 in
    both Phase 1 and Phase 2 while still executing the opposite-phase
    reset.
  - Advance the integration.tp_moe.dynamic compile spec from 23 to 24.
- Add CPU swizzle/bucket/reset-contract tests, direct Phase 1/2
  work-stealing and empty-launch tests, Triton route-plan counter-reset
  tests, and end-to-end poisoned-scratch replay tests covering
  mxfp8+triton+M128, bf16+triton+M16, and bf16+internal+M128 in
  tests/experimental/b12x/moe/test_w4a8_prefill_m128.py.

Result:
Single-GPU NVIDIA GeForce RTX 5090 (SM120) CUDA-graph comparison at
M=8192, H=5120, E=384, k=6, N=576, Zipf 1.1 with the Triton route
planner and inline scales (including the PR #161 epilogue prerequisite)
previously recorded 2697.8 -> 2424.5 us mean median, with zero BF16
bit differences across 41,943,040 deterministic outputs versus M64.

Evidence:
Verified locally on single-GPU RTX 5090 (SM120, PyTorch 2.14.1+cu132,
CUTLASS DSL 4.8.1) from exact git archive HEAD (multi-GPU / TP4 not
exercised here):
- tests/experimental/b12x/moe/test_w4a8_prefill_m128.py: 47 passed,
  0 failed (including test_w4a8_m128_validation_and_heuristics,
  test_w4a8_m128_compute_m96_and_no_tail_barrier_invariants,
  test_w4a8_m128_worksteal_swizzle_buckets_and_reset_contracts,
  test_w4a8_m128_triton_route_plan_kernels_zero_worksteal_counters,
  test_w4a8_m128_phase1_worksteal_n3_swizzle_and_empty_direct,
  test_w4a8_m128_phase2_worksteal_counter_reset_and_empty_direct,
  test_w4a8_m128_phase2_alignment_fallback_and_compute_m96_direct
  [False/True], test_w4a8_m128_output_2byte_alignment_rejected,
  test_dynamic_monolithic_nvfp4_output_4byte_alignment_fallback
  [128-128, 512-16],
  test_w4a8_m128_output_alignment_fallback_and_rejection [False/True],
  and test_w4a8_m128_poisoned_scratch_replay across mxfp8-triton-m128,
  bf16-triton-m16, and bf16-internal-m128)
- compile_dynamic_route_plan warmups: 3/3 passed for
  (preq=False, full=False), (preq=True, full=False), and
  (preq=True, full=True)
- ruff 0.12.8 check clean across all 6 touched files;
  git merge-tree --write-tree 335459b HEAD clean;
  git diff --check clean.

Discord: Dooner
Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>

---------

Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
@voipmonitor

Copy link
Copy Markdown

Closing as already merged in #168 (3346959ac).

#168 (c9c5841aa) was stacked directly on top of #161's exact head (d8b6a60e2), so when #168 was squash-merged into main as 3346959ac, all 9 files and every change from #161 landed verbatim on main (verified programmatically: merging origin/main (0a40ff0eb) into #161 produces an empty diff — HEAD^{tree} == origin/main^{tree}).

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