Skip to content

fix: pad MoE expert GEMMs to the chip's smallest MMA shape - #2

Closed
travispchen wants to merge 3 commits into
sailresearchco:mainfrom
the-farm-system:mma-shapes
Closed

fix: pad MoE expert GEMMs to the chip's smallest MMA shape#2
travispchen wants to merge 3 commits into
sailresearchco:mainfrom
the-farm-system:mma-shapes

Conversation

@travispchen

Copy link
Copy Markdown
Contributor

Summary

  • Add ChipSpec.mmaShapes: the chip's MMA row shapes and the fraction of peak each sustains.
  • A grouped GEMM pads each active expert to the cheapest shape (m / rate) instead of matmulSatRows (unset on every NVIDIA/AMD chip, so DEFAULT_MATMUL_SAT_ROWS = 128). Dense GEMMs (groups = 1), N/K padding and chips without mmaShapes are unchanged.- H100/H200: m64 @ 1.0, m16 @ 0.67 (Luo et al. 2024). B200/B300/GB200: m128 @ 1.0, m64 @ 0.5 (PTX tcgen05), so no change. MI300X/MI325X/MI355X: m16 @ 1.0.

Why

Compared against SemiAnalysis InferenceX's public single-node rows, HTDYM is a ceiling for LLaMA, R1, Kimi and GLM-5 as intended, but engines beat it by up to 2x on gpt-oss-120b decode. gpt-oss has 128 small experts (top-4), so at 64 concurrent requests each active expert sees ~2 rows, and tileUtil bills each one a 128-row tile: 256 real rows become 111 x 128 = 14k and decode flips to compute-bound. Real kernels size the tile from the token count: vLLM's Marlin MoE (what InferenceX runs on H200) picks block 8 here from [8, 16, 32, 48, 64] (marlin_moe.py#L334-L336) on an mma.sync m16 kernel (marlin_mma.h#L39); its tuned Triton config for this shape uses BLOCK_SIZE_M=16 up to 256 tokens and 128 only from 2048 (E=128,N=2880 config). 128 is right for dense GEMMs and prefill, wrong as the per-expert floor at decode.

H200 TP=1, 1k/1k, conc 64: HTDYM 37.4 ms/step before (compute-bound), 14.0 ms after (memory-bound); InferenceX TRT-LLM measures 22.5 ms and I got 23.7 ms rerunning their gptoss_fp4_h200.sh (vLLM v0.22.0) on a rented Vast.ai H200. gpt-oss violations go 114 -> 48 (H100/H200/MI300X/MI325X to 0), Kimi 4 -> 0, others unchanged. The 48 left are B200 (preset prices bf16 activations/KV, InferenceX runs MXFP8 + fp8 KV) and 3 memory-bound MI355X rows at <= 1.11x, both separate issues. The rates are from the literature, not fitted.

Tests

In tests/run.test.ts:

  • a grouped GEMM pads each group to the cheapest MMA instruction: Hopper, Blackwell and the no-mmaShapes fallback.
  • gpt-oss-120b decode on one H200 stays under the measured step time: 1k/1k conc 64 decodes under the measured 22.5 ms and memory-bound, and fails both without mmaShapes.

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

@travispchen is attempting to deploy a commit to the Sail Research Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T06:08:46.580080Z 3b447e5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b447e54cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/core/hardware/chips.ts Outdated
Comment thread src/core/engine/sim/cost/helpers/naiveOpCost.ts Outdated
…ding

- A100, RTX 4090, RTX 5090, RTX PRO 6000 get [{m: 16, rate: 1}]: mma.sync is
  their only tensor-core path and runs at full rate, as on CDNA.
- groupedRows rounds rows up to the chosen shape, so a one-group GEMM
  (EP = experts) never prices below the identical dense GEMM.
- Doc: rate is relative to the full-rate shape (stacks on
  realizableFlopsFrac); matmulSatRows/realizableFlopsFrac docs mention
  mmaShapes.
- Test that every chip's mmaShapes is non-empty with rates in (0, 1].
- Drop the H200 test assertion that pinned the pre-fix model's wrongness.
@transmissions11

Copy link
Copy Markdown
Collaborator

Good work, def really bad if we're reporting "upper bounds" which are below real engine perf. I took this a bit further and made it more comprehensive across chips + not just apply to group gemms in #4 (sorry would have done it on this PR but couldn't edit it, credited it you as an author)

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