Skip to content

[Fix] gguf: Preserve MoE routing, weighting and allocation budgets - #45916

Merged
ch-wan merged 1 commit into
mainfrom
cheng/hot-fix/gguf-inactive-route-scratch
Oct 23, 2026
Merged

ch-wan merged 1 commit into
mainfrom
cheng/hot-fix/gguf-inactive-route-scratch

Conversation

@ch-wan

@ch-wan ch-wan commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • CUDA MMVQ uses a local JIT entry with negative-ID checks before expert-address formation. Ordinary contiguous int32 routes retain their storage; exceptional layouts/widths normalize explicitly. The quantize/project structure and zeroed projection output remain intact.
  • CUDA weighting excludes inactive outputs and scores inside its product kernel, removing activation-sized input copies and separate intermediate clears. Products still round to the output dtype before native moe_sum.
  • Shared native GGUF code checks MMQ slack bounds before access and indexes Q8_1 scales with the same routed row as the values. Rebuilt MUSA providers can use the native in-place weighting operator; older providers retain their compatibility path.
  • The slow fallback adopts the first valid expert result, adds later contributions in order, and zeros the existing final row only when all routes are inactive.
  • A local non-flushing FP32 multiply preserves subnormal operands/results and signed zero in CUDA weighting, including SM90 fast-math builds. MUSA multiplication and the reducer are unchanged.
  • Shared GGUF headers have one AOT source owner, with JIT forwarding links. Source-distribution staging materializes those headers so the runtime package remains self-contained.

Review order

  1. python/sglang/srt/layers/quantization/gguf.py: vector/MMQ/fallback selection, private-buffer lifetimes and final weighting/reduction.
  2. kernels/ops/moe/gguf_moe_vec.py, jit/csrc/moe/gguf_moe_vec.cuh and the shared GGUF headers: preserved format math and negative-ID access guards.
  3. aot/csrc/moe/moe_sum.cu, gguf_moe_weights.cuh and the weighting wrappers: validation, rounding and device registration.
  4. test_gguf_inactive_routes.py, test_gguf_moe_weights.py, then python/setup.py for standalone header packaging.
  • Define unused CUDA MMQ expert-map capacity in the existing alignment producer. This removes the per-call arange, multiply, comparison and masked-fill sequence while retaining the released provider and buffer sizes.

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 e6670af1ad B300 MMQ comparison against reviewed stack 5ece6073f3: 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 source f3a116529a; the GGUF runtime, production weighting TU/header and registered kernel test match this PR's b80e51a006 exactly.

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:

  • The registered vector-format/Triton-weighting checks passed 2 tests / 45 subtests. Vector coverage compares 19 formats against the existing native provider, with FP16/BF16/FP32 coverage for selected formats and inactive/recovery graph states.
  • The exact production moe_sum.cu was separately compiled with the precise SM100-family compute_100f/sm_100f flags. 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.
  • All 18 generated weighting specializations contain mul.rn.f32 without 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 seven GGUF unit tests, including fallback operation budgets and borrowed input/ID preservation, passed within the combined CPU suite. Normal configured pre-commit hooks passed.

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 unused materialized_routing parameter 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 integrated e6670af1ad, 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-gpu suite with nightly=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 1340044e97 for 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

@ch-wan
ch-wan force-pushed the cheng/hot-fix/gguf-inactive-route-scratch branch 2 times, most recently from 15450d0 to f10810c Compare October 23, 2026 09:01
@ch-wan
ch-wan force-pushed the cheng/hot-fix/decoder-tail-global-counter branch from 804d22d to c05521b Compare October 23, 2026 09:01
@ch-wan
ch-wan force-pushed the cheng/hot-fix/gguf-inactive-route-scratch branch from f10810c to ab751a3 Compare October 23, 2026 09:58
@ch-wan
ch-wan force-pushed the cheng/hot-fix/decoder-tail-global-counter branch from c05521b to b556b74 Compare October 23, 2026 11:35
@ch-wan
ch-wan force-pushed the cheng/hot-fix/gguf-inactive-route-scratch branch 2 times, most recently from ec03ed8 to c283b5f Compare October 23, 2026 19:21
@ch-wan
ch-wan force-pushed the cheng/hot-fix/decoder-tail-global-counter branch from b556b74 to c6e2917 Compare October 23, 2026 19:27
@ch-wan
ch-wan requested a review from hnyls2002 as a code owner October 23, 2026 19:27
Base automatically changed from cheng/hot-fix/decoder-tail-global-counter to main October 23, 2026 19:28
@ch-wan
ch-wan force-pushed the cheng/hot-fix/gguf-inactive-route-scratch branch from c283b5f to 6615752 Compare October 23, 2026 19:29
@ch-wan
ch-wan merged commit e6451c1 into main Oct 23, 2026
87 of 103 checks passed
@ch-wan
ch-wan deleted the cheng/hot-fix/gguf-inactive-route-scratch branch October 23, 2026 19:29
@ch-wan
ch-wan restored the cheng/hot-fix/gguf-inactive-route-scratch branch October 23, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file jit-kernel mthreads quant LLM Quantization sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant