Skip to content

SM90 grouped 1D2D heuristics, thread-local alignment, MoE precompile, and #455/#478 - #8

Merged
kevmo314 merged 4 commits into
ninetyfive-wheelsfrom
fix/sm90-grouped-heuristics-and-tls
Nov 11, 2026
Merged

kevmo314 merged 4 commits into
ninetyfive-wheelsfrom
fix/sm90-grouped-heuristics-and-tls

Conversation

@kevmo314

Copy link
Copy Markdown
Owner

Summary

Updates ninetyfive-wheels with fixes for SM90 grouped MoE heuristics, free-threaded Python 3.14t alignment safety, ahead-of-time precompilation of Qwen4's MoE down / LoRA gate_up grouped GEMMs, and two upstream bugfix cherry-picks (#455, #478).

Changes

  1. SM90 Grouped 1D2D Heuristics (csrc/jit_kernels/heuristics/sm90.hpp):
    • Generalize #6 (disable_multicast) from desc.gemm_type == GemmType::Normal and desc.m <= 2048 to desc.get_expected_m() <= 2048 (identical on Normal, and disables 2-CTA clusters on MGroupedContiguousWithPsumLayout when per-expert expected_m <= 2048 where num_m_blocks <= 1 or odd dynamically disables multicast in scheduler/gemm.cuh while still paying 2-CTA cluster barrier waits).
    • Generalize #7 (kShouldOptimize block_n filter) from desc.m > 64 (padded buffer capacity) to desc.get_expected_m() * desc.get_expected_num_groups() > 64.
  2. Thread-Local Contiguous Alignment (csrc/jit_kernels/heuristics/runtime.hpp):
    • Make mk_alignment_for_contiguous_layout inline static thread_local int so concurrent Python 3.14t threads calling set_mk_alignment_for_contiguous_layout(align) cannot race (allowing _DG_ALIGN_LOCK in ninetyfive to be dropped once upgraded).
  3. Ahead-of-Time Grouped MoE Precompilation (sm90_fp8_gemm_1d2d.hpp, gemm.hpp, ninetyfive-wheels.yml):
    • Add precompile_m_grouped_fp8_gemm_nt_contiguous and precompile Qwen4's [512, 2560, 640] (down) and [512, 1280, 2560] (LoRA gate_up) across block_m (32, 64, 128) so cold FP8 MoE startup requires zero runtime nvcc invocations.
  4. Upstream Bugfix Cherry-Picks:
    • deepseek-ai/DeepGEMM#455: Guard block_m 16, 32 candidates against Kernel1D1D (DG_STATIC_ASSERT(kNumMWaves == 2) on small-M FP8 wgrad backward).
    • deepseek-ai/DeepGEMM#478 (5081f8513a): Tag mega_mhc split barriers with an epoch instead of %gridid to fix stale split-barrier reads under CUDA graph replay.

lightseek-bot and others added 4 commits November 11, 2026 01:43
A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>
The SM90 layout heuristic adds block M candidates of 16 and 32 for small M,
but the SM90 FP8 1D1D kernel (FP32-output / k-grouped GEMMs) only supports
block M of 64 or 128 (single or double math warpgroups). For M <= 32, the
cost model prefers the smaller tile and the JIT compilation then fails on the
kernel's static assertion, so e.g. `fp8_gemm_nt` with an FP32 accumulator and
`k_grouped_fp8_gemm_nt_contiguous` cannot run for M <= 32 on Hopper.

Restrict the 16/32 candidates to the kernels that support them (1D2D and
BF16), and add small-M weight-gradient shapes to the test enumeration.

Signed-off-by: RunguoLi <[email protected]>
…case

- Name the small-M weight-gradient shape next to the other shape tables
  and reword its comment (the heuristic must not pick block M 16/32).
- Add a small-M (m=16) shape to the k-grouped enumeration on SM90, with 8
  groups so that TMA multicast stays disabled.

Signed-off-by: RunguoLi <[email protected]>
…ecompile

- sm90.hpp: use desc.get_expected_m() <= 2048 for 1D2D multicast cluster
  disable (matching dense Normal behavior while avoiding unpaired 2-CTA
  clusters on 512-expert grouped GEMMs where per-expert expected_m <= 2048),
  and use expected_m * expected_num_groups > 64 rather than padded desc.m > 64
  for the kShouldOptimize block_n filter.
- runtime.hpp: make mk_alignment_for_contiguous_layout thread_local so
  free-threaded Python 3.14t callers do not race on contiguous grouped
  layout alignment.
- sm90_fp8_gemm_1d2d.hpp / gemm.hpp / ninetyfive-wheels.yml: add
  precompile_m_grouped_fp8_gemm_nt_contiguous and precompile Qwen4's 512-expert
  down ([512, 2560, 640]) and LoRA gate/up ([512, 1280, 2560]) shapes.
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.

3 participants