Skip to content

[Feat] paged-experts: AWQ, compressed-tensors, MXFP4, NVFP4, W8A8 and block-INT8 experts - #45787

Merged
BBuf merged 2 commits into
sgl-project:mainfrom
N3mezis:feature/paged-experts-compatibility
Oct 25, 2026
Merged

BBuf merged 2 commits into
sgl-project:mainfrom
N3mezis:feature/paged-experts-compatibility

Conversation

@N3mezis

@N3mezis N3mezis commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

[Feature] Paged Experts: AWQ, compressed-tensors, MXFP4, NVFP4, W8A8 and block-INT8 experts

Motivation

This PR aims at improving Paged Experts' (#42557) format compatibility. It currently only supports unquantized, block-FP8 and GPTQ experts.

These formats will be supported:

Experts MoE runner Notes
unquantized (bf16/fp16) triton already supported
block-quantized FP8 triton already supported
GPTQ int4/int8 Marlin already supported
AWQ int4 Marlin new
compressed-tensors W4A16/W8A16 Marlin new
compressed-tensors NVFP4 Marlin new; weight-only (nvfp4a16, or w4a4 before Blackwell)
MXFP4 (gpt-oss) Marlin new; --moe-runner-backend marlin
ModelOpt NVFP4 Marlin new; --moe-runner-backend marlin, runs W4A16
compressed-tensors FP8, per-channel or block, dynamic activations triton new (e.g. FP8-dynamic checkpoints)
W8A8 FP8 (--quantization w8a8_fp8) triton new
W8A8 INT8 (--quantization w8a8_int8) triton new
block-quantized INT8 triton new

Modifications

Derived formats (formats.py, runners.py). #42557 declares each format by hand: which tensors are loaded and paged, whether the post-load step repacks, which runner contract applies. Adding the five Marlin formats in that style showed it fails silently:

  • an unlisted tensor is not paged, so paged-in experts run with another expert's values (AWQ control with the zero points unpaged: median 1.67 nats, against 0.003 paged);
  • the declared runner can differ from the one the layer builds (ModelOpt NVFP4 defaults to FlashInfer CUTLASS, which sums the top-k inside the kernel; compressed-tensors int4 defaults to Triton WNA16 on SM100);
  • each repacking format needed a hook to reset its "already converted" flag (ModelOpt _w13_deinterleaved, compressed-tensors is_marlin_converted), or every chunk after the first stayed in the checkpoint layout;
  • repacking K experts at a time was assumed valid, never checked.

Paged experts now derives these from the layer, as SGLang already does elsewhere (EPLB's filter_moe_weight_param_global_expert; the runner backend as execution contract):

  • Expert tensors: every w13_*/w2_* parameter with one row per local expert. Tensors sized for all experts (_sglang_require_global_experts) stay whole on the GPU. Biases, zero points and kernel padding need no code.
  • Runner contract: from the runner the base method builds (its own, its scheme's, or its scheme kernel's). Triton → masked waves; Marlin → compacted waves, with the post-load repack run over the host store K experts at a time. Any other runner is rejected at startup with a message naming it and --moe-runner-backend.
  • Repack state: the layer's attributes are snapshotted before the first chunk and restored before each later one.
  • Independence check: one more chunk, experts 1..K, must reproduce their bytes from the first pass; startup fails if the post-load step mixes experts.
  • Format classes: every format, main's three included, is a supports check (8–19 lines), plus an unpaged or freed tuple for three of them and a runner route for compressed-tensors W4A16. formats.py is 340 lines for twelve formats (main: 184 for three; the declared version: 389 for eight). The four triton formats were added after the refactor as a test of it; they needed one shared fix, letting the triton contract find a runner held on the layer's scheme.

Loading (method.py):

  • Stacked checkpoint tensors (all experts in one tensor, e.g. gpt-oss) go to the layer's native loader on the whole host store, as called.
  • Loaders of vLLM-style parameters (read-only weight_loader property) are redirected through _weight_loader.
  • The host store starts from each parameter's created values instead of uninitialized memory, so what a loader leaves unwritten matches the GPU. No format on main loads partially, but Marlin pads gpt-oss-20b's MXFP4 experts (2880 → 2944 / 3072) and its loader fills only the checkpoint's part: without this, paged gpt-oss-20b scores GSM8K 0.000 with every answer truncated; with it, 0.960 (unpaged 0.975). test_host_store_starts_from_the_created_values fails without it.
  • compressed-tensors W4A16/W8A16 waves run through the scheme's Marlin runner: the scheme's own apply calls the kernel directly and sums the top-k outputs.

Prefill capture: the paged break skips its waves while a breakable graph captures it (a capture_stub), since the routing ids are not computed yet then; warmup and replay run them as before. Without it, gpt-oss-20b paged an out-of-range expert id at capture and failed to start.

Kernel (paged_experts.cuh): the gather copies rows of any even byte size (16-, 4- or 2-byte loads). NVFP4 on Marlin keeps one bf16 global scale per expert, a 2-byte row.

Runner output: the top-k sum is trimmed to the input's hidden size (MXFP4 Marlin pads it, 2880 → 3072 on gpt-oss-20b).

Accuracy Tests

Repack, byte oracle. The real post-load step on a full layer vs K experts at a time through _repack: byte-identical in all 8 cases (AWQ; compressed-tensors int4 symmetric, asymmetric, act-order, and int8; compressed-tensors NVFP4 with and without w4a4 input scales; MXFP4).

Paged vs unpaged, 4-layer test models (E=32, top-4, K=8; prompt and greedy decode logprobs, without deterministic inference; RTX 5070 Ti):

model runner prompt median / max decode max
Qwen3-MoE bf16 triton identical identical
Qwen2-MoE bf16 (shared expert) triton identical identical
gpt-oss bf16 (biases) triton identical identical
compressed-tensors FP8, per-channel triton identical identical
compressed-tensors FP8, block 128×128 triton identical identical
W8A8 FP8 (same checkpoint, --quantization w8a8_fp8) triton identical identical
W8A8 INT8 triton identical identical
block INT8 triton identical identical
gpt-oss MXFP4 Marlin identical identical
AWQ int4 Marlin 0.0033 / 0.012 0.015
compressed-tensors W4A16, symmetric Marlin 0.029 / 0.64 0.12
compressed-tensors W4A16, asymmetric Marlin 0.021 / 1.02 0.20
compressed-tensors NVFP4 Marlin 0.044 / 1.20 0.99

Marlin is not batch-invariant, and on SM90+ not run-to-run reproducible, so its formats are judged against controls with one tensor deliberately not paged:

model paged median diff control: tensor not paged control median diff
AWQ 0.0033 zero points 1.67
compressed-tensors int4 0.021–0.029 zero points 2.06
compressed-tensors NVFP4 0.044–0.058 (unpaged vs unpaged: 0.004–0.026) global scales 0.47

GSM8K (200 questions), RTX 5070 Ti 16 GB:

model experts resident main this PR, paged unpaged
Qwen3-30B-A3B-GPTQ-Int4 92 of 128 0.935 0.945 — (does not fit)
Qwen3-30B-A3B-FP8 (block) 40 of 128 0.955 0.950 — (does not fit)
gpt-oss-20b MXFP4 16 of 32 not supported 0.960 / 0.970 / 0.960 (3 runs) 0.975
Qwen3-30B-A3B ModelOpt NVFP4 (--moe-runner-backend marlin) 85 of 128 not supported 0.935 — (does not fit)

Speed Tests and Profiling

Output tok/s, paged, RTX 5070 Ti 16 GB:

model bs=1 4 concurrent 2k prompt, bs=1 weight load
Qwen3-30B-A3B-GPTQ-Int4, K=92 main 190.3 372.2 152.3 32.2 s
this PR 190.5 373.1 152.4 37.4 s
Qwen3-30B-A3B-FP8, K=40 main 80.3 84.8 78.8 54.5 s
this PR 80.5 82.5 79.0 49.2 s
gpt-oss-20b MXFP4, K=16 this PR 107.7 140.1 96.2 18.8 s

Weight load on the Marlin runner grows by the independence check, one extra repack chunk per layer: 32.2 → 37.4 s on Qwen3-30B-A3B-GPTQ-Int4.

CI

test_paged_experts.py gets a fourth case, gpt-oss-20b MXFP4 on the Marlin runner (compared like GPTQ). It covers what no other real checkpoint does: stacked checkpoint tensors, per-expert biases, and padding by the runner (host store init, output trim). openai/gpt-oss-20b is already used by six registered tests. est_time goes from 360 to 450 s; the 360 s was measured (313 s warm on an H100), the new case's ~90 s is an estimate. Other new coverage: the CPU unit test (23 tests, 15 on main) and the kernel test (2- and 6-byte rows).

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ⏳ Run #39951056279
Latest PR Test (Extra): ❌ Run #39951056293
Latest PR Test (AMD ROCm 10): ❌ Run #39951056248

… block-INT8 experts

New expert formats for paged experts:
- on the Marlin runner: AWQ int4, compressed-tensors W4A16/W8A16,
  compressed-tensors NVFP4 (weight-only), MXFP4 (gpt-oss) and ModelOpt NVFP4;
- on the triton runner: compressed-tensors FP8 (per-channel or block, dynamic
  activations), W8A8 FP8, W8A8 INT8 and block INT8.

To support them, paged experts now derives what it needs from the layer
instead of naming it per format: the expert tensors are the per-expert
parameters (as EPLB finds them), and the runner contract (triton masking or
Marlin compaction, and whether the post-load step repacks) follows from the
runner the base method builds. A format names only tensors its runner never
reads or that serve other runners. The repack runs K experts at a time with the
layer's state reset per chunk, and is checked on one extra chunk.

Also:
- per-expert biases are paged; stacked checkpoint tensors go to the native
  loader;
- the host store starts from the values the base method created, so what a
  loader leaves unwritten (MXFP4 Marlin padding) matches the GPU;
- the gather kernel copies rows of any even size, for NVFP4's 2-byte global
  scales;
- the paged break skips its waves while breakable prefill capture records it,
  as the routing ids are not computed yet then; warmup and replay run them;
- the e2e test gets a gpt-oss-20b MXFP4 case.
@mintlify

mintlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit c3dd708.

Approve preview

@github-actions github-actions Bot added documentation Improvements or additions to documentation jit-kernel labels Oct 22, 2026
@BBuf

BBuf commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Could we initialize the unused slots in the final _repack chunk from a valid expert before calling process_weights_after_loading?

For compressed-tensors NVFP4, when E % K != 0, this loop only overwrites [:n]; the remaining slots retain the template values. w13_weight_global_scale is created with torch.empty, but the post-load gate/up scale check checks all K slots, including the unused ones. Depending on their contents, a valid checkpoint can fail to load with a misleading scale-mismatch error.

I reproduced this in an isolated CPU harness using this PR's _repack and the actual NVFP4 post-load routine, with the final CUDA packing helper stubbed out. All real experts had valid, matching scales:

  • E=8, K=4: passes.
  • E=9, K=4, unused template scales filled with NaNs: fails on unused slots 1–3.
  • Same case with valid padding scales: passes.

Please fill the unused rows with a valid expert's data, including its quantization metadata, and add a regression test with a non-divisible expert count. The scale validation for real checkpoint experts should remain intact.

…8A8 and block-INT8 experts

Pad a short last repack chunk with real experts.

The repack runs the base method's post-load step K experts at a time. In a
short last chunk (E % K != 0), the rows past it kept the values the base
method created, which are torch.empty for most schemes. A step that validates
every row then rejected a valid checkpoint: compressed-tensors NVFP4A16 raised
"gate and up projections ... differ" for the unused rows, although every
expert's gate and up global scales matched. The rows now hold experts from the
start of the store, with all their tensors (weights and scales); they are
discarded after the step as before.
@N3mezis

N3mezis commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, good catch! Fixed.

The Regression test test_a_short_last_chunk_is_padded_with_experts runs the actual CompressedTensorsW4A16Nvfp4MoE.create_weights / process_weights_after_loading (Marlin packing stubbed) with NaN templates, E=17, K=4.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix! The partial-chunk case now passes the isolated CPU repro, and invalid checkpoint scales are still rejected. Let’s wait for CI.

@BBuf

BBuf commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 24, 2026
@BBuf

BBuf commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@BBuf
BBuf merged commit 2d3de82 into sgl-project:main Oct 25, 2026
388 of 447 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants