Repository navigation
[Fix] gguf: Preserve MoE routing, weighting and allocation budgets - #45916
Merged
Merged
Conversation
ch-wan
requested review from
Alisehen,
AniZpZ,
BBuf,
DarkSharpness,
Edwardf0t1,
FlamingoPg,
HaiShaw,
HydraQYH,
OrangeRedeng,
b8zhong,
celve,
ispobock,
merrymercy,
yizhang2077 and
yuan-luo
as code owners
October 22, 2026 23:45
This was referenced Oct 22, 2026
ch-wan
force-pushed
the
cheng/hot-fix/gguf-inactive-route-scratch
branch
from
October 23, 2026 05:44
b80e51a to
1fcde2c
Compare
ch-wan
force-pushed
the
cheng/hot-fix/decoder-tail-global-counter
branch
from
October 23, 2026 06:06
f3d331d to
804d22d
Compare
ch-wan
force-pushed
the
cheng/hot-fix/gguf-inactive-route-scratch
branch
2 times, most recently
from
October 23, 2026 09:01
15450d0 to
f10810c
Compare
ch-wan
force-pushed
the
cheng/hot-fix/decoder-tail-global-counter
branch
from
October 23, 2026 09:01
804d22d to
c05521b
Compare
ch-wan
force-pushed
the
cheng/hot-fix/gguf-inactive-route-scratch
branch
from
October 23, 2026 09:58
f10810c to
ab751a3
Compare
ch-wan
force-pushed
the
cheng/hot-fix/decoder-tail-global-counter
branch
from
October 23, 2026 11:35
c05521b to
b556b74
Compare
ch-wan
force-pushed
the
cheng/hot-fix/gguf-inactive-route-scratch
branch
2 times, most recently
from
October 23, 2026 19:21
ec03ed8 to
c283b5f
Compare
ch-wan
force-pushed
the
cheng/hot-fix/decoder-tail-global-counter
branch
from
October 23, 2026 19:27
b556b74 to
c6e2917
Compare
Base automatically changed from
cheng/hot-fix/decoder-tail-global-counter
to
main
October 23, 2026 19:28
ch-wan
force-pushed
the
cheng/hot-fix/gguf-inactive-route-scratch
branch
from
October 23, 2026 19:29
c283b5f to
6615752
Compare
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is part of a stack (oldest at bottom):
Motivation
GGUF MoE must discard padded and nonlocal routes without consuming their expert outputs or NaN scores. Preparing safe IDs and clearing intermediate tensors on every call adds allocations and launches, while an unguarded native projection can form a weight address from a negative ID.
This PR moves CUDA vector-route safety into a local native consumer, shares its format math with the AOT implementation, and preserves per-slot product rounding before the existing MoE reduction. It also restores lazy fallback accumulation and repairs the shared native MMQ bounds/scale indexing.
Changes
moe_sum.Review order
python/sglang/srt/layers/quantization/gguf.py: vector/MMQ/fallback selection, private-buffer lifetimes and final weighting/reduction.kernels/ops/moe/gguf_moe_vec.py,jit/csrc/moe/gguf_moe_vec.cuhand the shared GGUF headers: preserved format math and negative-ID access guards.aot/csrc/moe/moe_sum.cu,gguf_moe_weights.cuhand the weighting wrappers: validation, rounding and device registration.test_gguf_inactive_routes.py,test_gguf_moe_weights.py, thenpython/setup.pyfor standalone header packaging.CI cadence
The GGUF all-format/AOT numerical regression and weighting/vector microbenchmark now run in
nightly-test-1-gpu-large. The compact full-entry GGUF tests remain in base CI; the MUSA nightly registration is preserved.Across the stack, six existing CUDA file registrations move from base CI to extra/nightly, removing 854 estimated GPU-seconds from the default gate (registration estimates, not a measured wall-time saving). All test bodies, cases, inputs, assertions and tolerances are unchanged. Full before/after discovery validates 2,535 files and 3,077 registrations, with every moved file selected in its enabled destination suite. Configured hooks pass; native tests were not rerun for this registration-only update.
Validation
Final integrated
e6670af1adB300 MMQ comparison against reviewed stack5ece6073f3: Q4_0/Q8_0, M65/512, FP16 H256/I256/E4/topk2. Balanced ABBA workers with 32 captured calls × 8 replays × 9 samples show lower GPU time in all four cases: hot graph 10.1–27.7% and cold-L2 graph 11.4–18.7% (256 MiB flush excluded by events). Valid outputs are bitwise identical. Each entry removes 4 GPU launches; allocated peak decreases by 512 bytes at M65 and 2560 bytes at M512. This is a comparison to the reviewed stack; earlier original-main controls below retain their separate baseline and limitations.A native Q8_0 identity projection exposed a reference-only Q8_1 rounding-tie error: scalar division had become reciprocal multiplication. The test reference now uses tensor division, with the same inputs and numerical tolerance. No production numerical kernel or math setting changed.
At integrated
e6670af1ad, the alignment suite passes 89 tests on 1× H200 and 1× B300, covering count publication, signed IDs, complete expert-map capacity and combined options during graph replay. The GGUF native-entry suite passes 7 tests on B300 with sglang-kernel 0.4.10. H200 uses PyTorch 2.13.0+cu130 for the source-local JIT producer; this is not full native H200 GGUF admission.Based on #45915 above main
25ad569ff9. Blackwell checks ran on integrated sourcef3a116529a; the GGUF runtime, production weighting TU/header and registered kernel test match this PR'sb80e51a006exactly.On 1× NVIDIA B300, SM10.3, with PyTorch 2.14.1+cu130, Triton 3.8.0, sgl-kernel 0.4.10, FlashInfer 0.7.2 and NVCC 13.0.88:
moe_sum.cuwas separately compiled with the precise SM100-familycompute_100f/sm_100fflags. Dedicated process-local registration passed 2 tests / 44 subtests: native/Triton rounding cases plus native amplified-subnormal, subnormal-result and signed-zero cases, including poisoned inactive routes.mul.rn.f32without FTZ multiplication. Six graph captures passed 24 valid/partial/all-inactive/recovery replays with strided metadata. Ten invalid/overlap cases and three empty shapes passed; FP16 output[8192, 4096]required 0 extra allocated peak bytes for the warmed native weighting call.The dedicated weighting library does not establish full-provider or model compatibility: the installed provider was unchanged, and CUDA serving uses the local vector entry plus Triton weighting. Full rebuilt-wheel validation, native MUSA/MCC execution, distributed/model parity and GGUF serving performance remain untested. No universal performance claim follows from these operator checks; eager CPU submission overhead is excluded from the performance scope.
Rebase validation (before the CI registration fix)
This five-PR stack was rebased without conflicts onto main
8b9f72417f. All five patches retain their stable patch IDs relative to the preceding published stack; the newer main commits do not touch the stack's changed files. The existing removal of the unusedmaterialized_routingparameter and its three call-site arguments in #45917 is preserved.Each rebased PR commit passed its configured pre-commit checks independently. The final stack passes
git diff --check, and all 72 changed Python files parse successfully. CPU test suites, native GPU tests and performance measurements were not rerun for this rebase. Previously reported results, including those at integratede6670af1ad, remain evidence for those earlier revisions with their stated limits.Prior CI registration fix
The GGUF weighting test now uses the existing
nightly-musa-1-gpusuite withnightly=True; at that revision, its CUDA kernel-unit registration was unchanged. The previous nonexistent MUSA suite caused global registry validation to fail before CPU, CUDA and AMD tests could run.The original collection failure was reproduced. Full registration collection and suite validation now pass on the GGUF component (2,533 files / 3,075 registrations) and the integrated stack (2,535 files / 3,077 registrations), including enabled MUSA nightly and CUDA selection. Configured pre-commit checks pass for the corrected test. This update changes one registration line and is propagated through the existing stack.
CPU CI follow-up
Run 39935811691 exposed an upstream Flux2 import test registered in the CPU suite, whose environment lacks the diffusion dependencies. The import chain also queries the active GPU. #45915 moves that check to the existing CUDA diffusion unit suite, which installs those dependencies, while retaining its XPU registration and the real subprocess check that blocks Intel Triton imports. This registration fix is propagated through the stack.
The Flux2 import check passes on 1× NVIDIA B300 with PyTorch 2.14.1+cu130, Triton 3.8.0 and Diffusers 0.37.0; its five Intel-XPU numerical cases are skipped on CUDA and were not rerun on XPU. Full integrated registry collection validates 2,535 files / 3,077 registrations, including the enabled diffusion/XPU selections and the preceding GGUF MUSA fix. Configured checks pass for the changed files. Only three test files change across this follow-up; production code is unchanged. A fresh full CI result is not claimed.
Merge preparation
Rebased this component onto main
1340044e97for squash merge. The preceding stack components are already merged into main; only this component is replayed here. No test suites or performance measurements were rerun for this merge. Earlier validation sections describe their named revisions.CI States
Latest PR Test (Base): ❌ Run #40011796410
Latest PR Test (Extra): 🚫 Run #40011796238
Latest PR Test (AMD ROCm 10): ⏳ Run #40011796148