Skip to content

[FlashInfer v0.7.1] Add opt-in NVFP4 W4A16 support to FlashInfer MegaMoE - #39210

Closed
zianglih wants to merge 23 commits into
sgl-project:mainfrom
zianglih:feat/flashinfer-megamoe-nvfp4-w4a16
Closed

zianglih wants to merge 23 commits into
sgl-project:mainfrom
zianglih:feat/flashinfer-megamoe-nvfp4-w4a16

Conversation

@zianglih

@zianglih zianglih commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

@HumansAnd

Add NVFP4 W4A16 to the existing FlashInfer MegaMoE backend for serialized ModelOpt
checkpoints and nvfp4_online. Reuse SGLANG_FLASHINFER_CUTEDSL_NVFP4_W4A16=1
from #35120; the default NVFP4
MegaMoE path remains W4A4.

Dependency: uses upstream's released FlashInfer
0.7.1 pin from
#43494, including
FlashInfer #5019.
This PR does not change Dockerfiles or dependency pins.

Modifications

  • Backend and precision: extend the existing MegaMoE preparation/forward path
    and use FlashInfer's native config, preprocessing and pooled workspace APIs.
    W4A16 uses packed NVFP4 weights/block scales, per-expert FP32 weight scales,
    BF16 expert activations/EP transport/combine and post-FC2 routing. Checkpoint
    activation scales are neutralized; online quantization retains its source
    precision and excluded-layer semantics. No new opt-in or quantization interface.
  • Topology and models: SM100/SM103 with attention-DP=TP=EP. GLM DSA/MTP keeps
    synchronized DP token counts and graph buckets while expert inputs remain local.
    Resolve the EP process group through the active runtime context.
    Kimi K3 NVFP4 W4A4/W4A16 uses standard TopK and local EP/shared-expert handling;
    SiTU maps GEMM1 alpha/clamp fields to beta/linear-beta, separately from SwiGLU
    clamps. MXFP8/DeepGEMM reject unwired SiTU; Nemotron ReLU-squared is unsupported.
  • Reduction and output: default SGLANG_FLASHINFER_MEGAMOE_IN_KERNEL_FC2_REDUCE=0
    uses external FP32 accumulation. Setting it to 1 permits nondeterministic
    BF16 atomic candidates; tuning may still select external reduction. Use native
    supports_output_view to distinguish W4A4's borrowed output from W4A16's owned output.
  • Reload and dummy weights: restore canonical W4A16 loading views and copy
    prepared weights into existing buffers. Retain the live layer, workspace owner
    and captured addresses; stage runtime scales on every forward. Initialize dummy
    weight_scale_2 to one while preserving ordinary random-weight initialization.
    Serialized W4A16 reload is covered; W4A4 reload and online RL reload are outside scope.

Startup tuning and cache ownership

  • Tune once per geometry and capacity before graph capture and prepare pooled
    workspaces: powers-of-two decode profiles cover captured, eager and adaptive-MTP
    bounds, plus the per-rank prefill ceiling from the shared runtime helper.
    All ranks choose the smallest capacity covering synchronized DP counts,
    including empty ranks; reject overflow.
  • Tune representative capacity-sized inputs, then install fixed workspaces.
    Native first-forward AUTO alone would tune the first live input while caching
    under workspace capacity. FlashInfer owns namespaced persistence; stage each
    profile once across layers and preserve session winners for pooled workspaces.
  • Scope the target rank-cache filename by physical GPU UUID so engines on disjoint
    GPUs do not overwrite each other's records. Same-GPU engines need separate
    SGLANG_CACHE_DIR roots. Cache-disabled runs use unique output filenames.
    Cache naming adds no forward-path work.
  • Use the existing target startup autotune lifecycle; do not enable
    SGLANG_FLASHINFER_AUTOTUNE_EXTEND implicitly. Skipped/disabled tuning retains
    the default native path. Native tuning requires EP=WORLD; draft MegaMoE profiles
    and new deterministic-mode behavior are outside scope.

Single-node NVSHMEM defaults

For supported single-node FlashInfer MegaMoE formats with no speculative decoding
or draft A2A none, set these defaults before NVSHMEM initialization, preserving
explicit environment overrides:

NVSHMEM_REMOTE_TRANSPORT=none
NVSHMEM_IB_ENABLE_IBGDA=0
NVSHMEM_DISABLE_LOCAL_ONLY_PROXY=1

These select the direct-P2P path and avoid the uninitialized proxy global-exit
state corrected by NVIDIA/nvshmem commit af9e2391a849.
NVIDIA/nvshmem#110 is closed; its
description and discussion provide additional background.
All EP GPUs must support peer memory access. Proxy-based global exit/timeout
polling and remote IB/UCX transport are disabled; NCCL/UID bootstrap networking
is unaffected. Multi-node jobs and drafts using other A2A backends receive no
automatic defaults. No dedicated environment-variable behavior tests are added.

Example on four Blackwell GPUs with FlashInfer 0.7.1:

SGLANG_FLASHINFER_CUTEDSL_NVFP4_W4A16=1 python -m sglang.launch_server \
  --model-path Qwen/Qwen3-30B-A3B-Instruct-2507-FP8 \
  --quantization nvfp4_online --dtype bfloat16 \
  --moe-runner-backend flashinfer_megamoe \
  --moe-a2a-backend flashinfer_megamoe \
  --tp-size 4 --attn-dp-size 4 --ep-size 4 \
  --cuda-graph-backend-prefill disabled

Accuracy Tests

Validation target: SGLang 8d25027c9f2f5d714fee8b85f4c721ec68a54430, rebased onto
upstream 166b4ae7fcd78f7547e9e8fcc866f587b35b793d with FlashInfer 0.7.1.
GPU validation is deferred; previous-head GPU results are not claimed for this
revision.

  • All 19 changed Python files parse; git diff --check passes.
  • All applicable pre-commit checks pass across the 20 changed files.
  • Local CPU harnesses: 26 adapter tests pass; autotune/cache suite runs 16 tests,
    with one CUDA-only skip and all runnable tests passing. Serving/native imports
    are stubbed; these do not establish CUDA kernel or full-model correctness.
  • Released 0.7.1 API/config probes: eight W4A4/W4A16 SwiGLU/SiTU cases and four
    unsupported-format checks pass.
  • Existing legacy-accessor source check passes via AST-scoped execution of its
    unchanged test class. Full local module collection is blocked by missing
    orjson; this is not a pass of the full runtime-context suite.
  • Deferred GPU checks: registered units, native SwiGLU/SiTU EP4 cold/warm,
    online NVFP4 W4A16 GSM8K, serialized W4A16 reload, and W4A16/W4A4 dummy generation.
    No full K3 E2E, W4A4 reload, online RL reload, or serving-performance claim.

Raw local summaries:

Adapter harness: 26 passed, 1 warning in 0.89s
Autotune/cache harness: Ran 16 tests in 2.938s; OK (skipped=1)
Released API/config probes: 8 activation cases and 4 unsupported-format checks passed
Existing accessor source check (AST-scoped): Ran 1 test in 20.606s; OK
Python AST: 19 changed files parsed
Pre-commit: exit 0; all applicable checks passed

Static checks from the repository root:

git diff --check 166b4ae7fcd78f7547e9e8fcc866f587b35b793d...HEAD
git diff --name-only 166b4ae7fcd78f7547e9e8fcc866f587b35b793d...HEAD | xargs pre-commit run --files

Speed Tests and Profiling

End-to-end serving performance has not been measured on the current head.

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 #38216266799
Latest PR Test (Extra): ❌ Run #38216266298
Latest PR Test (AMD ROCm 10): ❌ Run #38216266886

@github-actions github-actions Bot added documentation Improvements or additions to documentation quant LLM Quantization blackwell SM100/SM120 labels Sep 12, 2026
@ziang-and
ziang-and force-pushed the feat/flashinfer-megamoe-nvfp4-w4a16 branch from 0abbb91 to e21e193 Compare September 20, 2026 23:27
@ziang-and
ziang-and force-pushed the feat/flashinfer-megamoe-nvfp4-w4a16 branch from 16c1b86 to 05627ff Compare September 29, 2026 03:46
@zianglih zianglih changed the title Add opt-in NVFP4 W4A16 support to FlashInfer MegaMoE [FlashInfer v0.7.1] Add opt-in NVFP4 W4A16 support to FlashInfer MegaMoE Sep 29, 2026
@zianglih
zianglih marked this pull request as ready for review September 29, 2026 04:56
@ziang-and
ziang-and force-pushed the feat/flashinfer-megamoe-nvfp4-w4a16 branch from 3811493 to 9f22780 Compare October 12, 2026 06:48
@zianglih

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

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

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@zianglih

Copy link
Copy Markdown
Contributor Author

Superserded by #43789 #44036

@zianglih zianglih closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 documentation Improvements or additions to documentation quant LLM Quantization run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant