Skip to content

[Fix] lora: Preserve MoE projection identity and routing lifetimes - #45681

Merged
ch-wan merged 1 commit into
mainfrom
cheng/hot-fix/moe-lora-gated-virtual-projections
Oct 23, 2026
Merged

ch-wan merged 1 commit into
mainfrom
cheng/hot-fix/moe-lora-gated-virtual-projections

Conversation

@ch-wan

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

Copy link
Copy Markdown
Collaborator

This PR is part of a stack (oldest at bottom):

Motivation

Independent gate/up A factors require matching rank halves during expansion. The stock virtual-expert hook reused the gate half for the up output: with x=1, A_gate=2, A_up=3, B_gate=5, B_up=7, it produced [10,14] instead of [10,21]. Inactive routes and absent/disabled adapters also need complete private outputs without consuming stale or NaN payloads.

Changes

  • Keep one full-2R shrink and select the matching A half inside the existing expansion. Internal rank/half-width constants and half-local masks support ragged widths without another projection launch or tensor. The default expansion keeps its original formulas.

  • Bound raw virtual IDs and adapter slots before histogram, address or payload formation. Preserve borrowed inputs, valid adapter 0 and original-width int64 validity; shared routing retains negative routes. Missing, disabled and out-of-range adapters cannot read private deltas or contribute NaN scores.

  • Complete owned LoRA outputs in their existing kernels and guard capacity-grid programs before grouped division/modulo. Empty helpers preserve their return/output contracts. Activation and shared-outer rank reductions retain active arithmetic and rounding.

  • Prepare paired per-expert gate-B/down-A routing once on the main stream, aligning at each stage's actual block size. Release the shared raw owner before projection buffers and the side-stream fork. Existing cache contracts and staged fallbacks remain for unsupported pairings, including global-ID EP.

  • Remove unused expert-ID sanitizers and the unused metadata-bearing activation branch. Keep the production three-tensor activation and existing producer/reduction contracts.

CI cadence

The CUDA virtual-expert and experimental shared-outer LoRA suites now run in opt-in extra-a-test-1-gpu-small. CPU runtime checks and the core routing-kernel tests remain in base CI; the existing XPU 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

  • At integrated e6670af1ad, the focused native Marlin/LoRA route suite passes 14 tests on 1× B300 with the pinned providers, including changing padded routes and output completion.

  • Two additional direct Marlin output-ownership configurations did not complete within a 600-second cold-compilation budget on B300. No result is claimed for that extended run; it is separate from the completed route replay and producer-contract checks.

  • The focused production activation/reduction suite passes 10 tests on 1× B300 after cleanup. The deleted helpers had no production callers; retained production Triton kernel bodies are unchanged.

Performance comparisons use main b008ec3de6 before #44480, #44991, #44993 and #44994 merged. The integrated candidate also includes intervening main changes; the measured improvement is not attributed solely to this PR.

  • Configured hooks and runtime/policy CPU tests pass. 1× NVIDIA H200 nonzero-LoRA tests cover real stock, factored and three-adapter temporary paths, poisoned inactive data, mapping/enabled changes and valid → inactive → recovery CUDA graphs. Runner unit doubles are separate from native/full-entry evidence.
  • The final pre-rebase H200 comparison (3c486bd6 versus b008ec3d) completed 60 workers and 384 fixed rtol=0.01, atol=0.001 checks at M32/512, H256/I128/E8/topk2/rank8. Factored and multi-adapter outputs agree bitwise across revisions. Paired graph medians improve 1.82%/1.41% for factored and 4.72%/6.62% for multi-adapter paths; measured peaks do not increase. The nongated stock compatibility fixture retains bit instability on both revisions despite passing fixed-close checks; it does not prove a fully gated checkpoint.
  • Four H200 factored memory workers retain 2 MiB/4 MiB graph-pool reservations, lower capture allocated peaks by 512 bytes and preserve replay allocated peaks. These are allocator/current-pool observations, not historical per-pool peaks or non-PyTorch memory coverage.
  • B300 virtual-expert tests passed 19 cases/102 subtests, with five abstract-base skips. The final full-width route-factory suite passed six tests/12 subtests. Its new regression fails six builder combinations on the original helper and passes all 18 builder/state checks after repair. Three representative int32 shapes retain identical non-debug PTX tokens and queried resources for both standalone and inlined producers.

H200/B300 tests used PyTorch 2.14.1+cu130, Triton 3.8.0, sgl-kernel 0.4.10 and FlashInfer 0.7.2. The H200 performance/memory results precede the main rebase; no B300 full-runner LoRA performance, native MUSA or distributed-serving result is claimed.

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.

#45917 also updates the MoE CPU fixtures to use the production CompressedTensors/Quark method wrappers and to resolve the FP8 routing policy through the initialization hook. Existing backend, EP mapping and zero-valued/default routing assertions remain intact. The three original fixture failures were reproduced before the fix; both complete files now pass on CPU (26 tests, 55 subtests).

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 ac3db731b3 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 #40012205098
Latest PR Test (Extra): ❌ Run #40012205102
Latest PR Test (AMD ROCm 10): 🚫 Run #40012205313

@ch-wan
ch-wan force-pushed the cheng/hot-fix/moe-lora-gated-virtual-projections branch from e6670af to b62e3d7 Compare October 23, 2026 06:07
@ch-wan ch-wan added bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) parallel-stages CI: stages dispatch together instead of waiting on each other run-ci CI: run the baseline test suite on this PR labels Oct 23, 2026
@ch-wan
ch-wan force-pushed the cheng/hot-fix/cutlass-moe-complete-maps branch from 4532436 to 22687df Compare October 23, 2026 09:03
@ch-wan
ch-wan force-pushed the cheng/hot-fix/moe-lora-gated-virtual-projections branch from b62e3d7 to b400733 Compare October 23, 2026 09:03
@ch-wan
ch-wan force-pushed the cheng/hot-fix/cutlass-moe-complete-maps branch from 22687df to c8f926b Compare October 23, 2026 09:59
@ch-wan
ch-wan force-pushed the cheng/hot-fix/moe-lora-gated-virtual-projections branch from b400733 to df67b1a Compare October 23, 2026 09:59
@ch-wan
ch-wan force-pushed the cheng/hot-fix/cutlass-moe-complete-maps branch from c8f926b to 1aa9634 Compare October 23, 2026 11:36
@ch-wan
ch-wan force-pushed the cheng/hot-fix/moe-lora-gated-virtual-projections branch 2 times, most recently from dc9638c to 69c4b92 Compare October 23, 2026 19:21
@ch-wan
ch-wan force-pushed the cheng/hot-fix/cutlass-moe-complete-maps branch 2 times, most recently from d5ee31a to 491587f Compare October 23, 2026 19:31
Base automatically changed from cheng/hot-fix/cutlass-moe-complete-maps to main October 23, 2026 19:32
@ch-wan
ch-wan force-pushed the cheng/hot-fix/moe-lora-gated-virtual-projections branch from 69c4b92 to 5bcaf4d Compare October 23, 2026 19:32
@ch-wan
ch-wan merged commit d0022e1 into main Oct 23, 2026
49 of 62 checks passed
@ch-wan
ch-wan deleted the cheng/hot-fix/moe-lora-gated-virtual-projections branch October 23, 2026 19:32
@ch-wan
ch-wan restored the cheng/hot-fix/moe-lora-gated-virtual-projections branch October 23, 2026 19:33
jybsuper added a commit that referenced this pull request Oct 24, 2026
Main is at 6a319e7. One conflict: this branch moved
test/registered/lora/test_virtual_experts_kernels.py to
test/registered/kernels/ops/lora/ and replaced its align tests with an
exact-placement check, while d0022e1 (#45681) rewrote the old path,
removed fused_sanitize_expert_ids and made the CUDA-JIT align map
out-of-range IDs to the sentinel bucket by default.

Resolution in the moved file:
- main's topk-remap class as is (this branch never changed it), with its
  imports and without the removed sanitizer;
- this branch's exact-placement align check, plus main's used-count
  bounds (count >= 0, used blocks within expert_ids);
- both align paths get the same invalid IDs (-1 and >= num_experts),
  since main's JIT path now buckets out-of-range IDs itself; the note
  that such IDs can touch invalid memory is gone with it;
- the empty-input case main kept, through the same check;
- main's sanitizer-free JIT subclass;
- this branch's location and registration (base-b-kernel-unit on
  1-gpu-small); main had moved the old path to extra-a.

Auto-merged, worth a look: test_moe_lora_routing.py keeps this branch's
est_time (20) next to main's new cases;
test_experimental_sgl_marlin_runtime_unit.py keeps this branch's weekly
CPU registration while main added a prewarm regression test to it;
test_experimental_sgl_marlin_shared_outer_reduce.py is main's version
(both sides moved it to extra-a).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd apple-silicon blackwell SM100/SM120 bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) deepseek dependencies Pull requests that update a dependency file diffusion SGLang Diffusion documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang jit-kernel lora memory-pool mooncake mthreads Multi-modal multi-modal language model npu parallel-stages CI: stages dispatch together instead of waiting on each other quant LLM Quantization run-ci CI: run the baseline test suite on this PR sgl-kernel speculative-decoding unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant