Skip to content

[Feat] lora: Add plan-driven dense and MoE LoRA engines - #45892

Merged
Fridge003 merged 21 commits into
mainfrom
lora-runtime-aggregate-20261022
Oct 22, 2026
Merged

Fridge003 merged 21 commits into
mainfrom
lora-runtime-aggregate-20261022

Conversation

@jybsuper

@jybsuper jybsuper commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Provide a single-PR alternative for merging the complete, currently published 21-part LoRA runtime stack. This is the same implementation and history, not a separate development variant.

The existing stacked PRs remain open and unchanged. Choose one merge route; this PR does not add a 22nd feature layer.

Modifications

  • Plan-driven dense LoRA execution through triton_v2, shared routing/workspace management, grouped and per-row shrink/expand kernels, and shipped SM90/SM100 plans.
  • LoRA-free decode graphs, absorbed-MLA corrections, and Inkling shared-sink integration.
  • Per-expert and shared-outer MoE LoRA execution, with Triton/CuTeDSL BF16 and FP8 providers and the Marlin NVFP4 provider.
  • The stack's existing correctness, CUDA-graph, numerical, serving-integration tests and runtime configuration tables.

This branch reuses the final stack commit directly: no squash, rebase, cherry-pick, source edit, or additional commit. Benchmark/tuning tools and the deferred Triton MoE tuning-table changes from the development branch are intentionally excluded, exactly as in the stack.

Exact identity

Item Value
Target branch sgl-project/sglang:main
Historical main base / merge-base c1c287a42928495166e14dbcef31b9e1f1dac199
Head, identical to lora-stack-20-nvfp4 c1f5d0a1ec12fdccd33986517daf98aec3110e6d
Tree 1d227b53a60d8d82e8c648d6b12f6bd77f92e29a
Commits above historical base 21
Changed files against historical base 141

GitHub targets the moving main branch; the historical base above is preserved rather than rebasing onto later main commits.

Accuracy Tests

Existing CI evidence verified for this exact head:

These are the final stack's runs, not new runs or transferred approvals on this PR. This publication adds no source changes and reruns no tests. PR-specific checks, merge-context validation and reviewer approvals remain separate requirements.

Speed Tests and Profiling

The runtime source and configuration tree are byte-identical to the published stack head. No new benchmark was run to create this alternative PR; existing benchmark conclusions and their limitations are unchanged.

Review and Merge Process

This is a ready-for-review alternative to merging the 21 parts individually. The existing stack is retained for detailed review. No run-ci or run-ci-extra label is added by this publication.


CI States

Latest PR Test (Base): ❌ Run #39848456564
Latest PR Test (Extra): ❌ Run #39848456457
Latest PR Test (AMD ROCm 10): ❌ Run #39848456257

Add the hooks the LoRA engines need in shared code, with no effect unless a
lora_* MoE runner or the triton_v2 LoRA backend is selected:
- MoeRunnerBackend gains LORA_CUTEDSL, LORA_TRITON and LORA_MARLIN with the
  is_lora() and is_lora_marlin() predicates.
- FusedMoE keeps DeepGEMM's resident weight layout for lora_* runners, and the
  NVFP4 routed-scaling decision treats the LoRA Marlin vendor like Marlin.
- ModelOptNvFp4FusedMoEMethod prepares Marlin weights for lora_marlin, rejects
  the other lora_* runners, and leaves execution to the LoRA wrapper.
- post_reorder_deepgemm accepts an optional per-pair lora_delta added before
  the route weights and routed scaling.
- The decode-graph "lora"/"nolora" label becomes the capture_lora_variant()
  context manager, so later captures cannot inherit it.
- The decode-graph batch-info init is renamed init_decode_cuda_graph_batch_info
  on LoRAManager, every backend and the decode runner's call, matching the
  prefill one.
- Both graph runners call LoRAManager.reset_routing_cache() before each
  capture; the backend default is a no-op until a backend caches routes.

Owners: srt/layers, srt/layers/quantization, kernels, srt/model_executor,
srt/lora.

Tests: the ModelOpt NVFP4 admission rules (lora_marlin only, Marlin weight
preparation); capture-variant labels and the graph-init keyword interface on
every backend; the two legacy backend tests that call the renamed init. The
existing runner-extension tests cover the registration hooks unchanged.
Add the route primitives both LoRA engines run on: RouteView, the sorted token
route builder (one route per forward and block size, capacity independent of
the request count), and LoraWorkspace, which keys routes, side streams and
events by the caller's stream. Register the route builder in the lora kernel
inventory.

Tests: route layouts against a host oracle on both builders, CUDA-graph
replay of changed inputs, workspace scratch reuse and stream keys, and the
host-level dispatch contracts.
Add the shared A/B Triton kernels: grouped and per-row shrink (serial split-K
with acquire/release counters, planes, windowed), grouped and per-row expand
with slice geometry tables cached per (rows, columns, tile width, device), and
the embedding LoRA-A lookup. Register them in the lora kernel inventory.

Tests: geometry caching and alignment. The 47-case bitwise kernel fixture
drives the kernels through the runner bridge and lands with the dense runner.
Add the dense plan model (DensePlan, DenseLoraKind, table rows named by their
match fields), the plan loader with load-time validation and in-code defaults
for devices without a table, the default table, and the
SGLANG_LORA_DENSE_CONFIG_DIR override. Phase and architecture_for_capability
move to lora/utils for both engines.

Tests: plan and tile validation, defaults without a table, in-order row
matching, geometry rows per site, windowed and all-slots row rules.
Add the tuned sm90 and sm100 dense plan tables. A device without a table keeps
the in-code defaults.

Tests: the shipped vocab plans keep the supported execution contract, the
Blackwell routed rows, and the H200 serial in_proj exceptions.
Add DenseLoraRunner (plan-driven A/B execution, split-K, base/LoRA overlap
on the workspace side stream) and the triton_v2 backend that drives it, and
wire the dense layers through BaseLoRABackend.forward_with_base: embedding,
lm_head, column/row/replicated projections. A dense layer stays on the base
path for a batch with no active adapter except while an adapter-capable graph
is captured. LoRAManager validates replicated-Q targets after the backend's
own target check, clears the route cache at capture boundaries, and reads DSA
indexer fusion from the model's indexers. Server args reject triton_v2 with
attention DP, PD-multiplexing, two-batch overlap, SGLANG_EXPERIMENTAL_LORA_OPTI
and ROCm.

Tests: dense backend and runner numerics (the 47-case bitwise fixture), the
runner's architecture resolution, inactive-batch rules under capture,
forward_with_base ordering, target validation, server-arg guards.
When the LoRA backend skips inactive dense batches, DecodeCudaGraphRunner
records a "nolora" graph per batch size for all-base batches.

Owner: srt/model_executor.

Tests: the backend flag and the decode runner's default.
Apply a kv_b_proj adapter as two corrections around the absorbed attention
BMMs (Q += Q @ B_k @ A, V += attention @ A.T @ B_v.T), routed by (slot, head)
with per-head B slices, built once per forward on the caller stream. The MLA
forward selects the correction through kv_b_lora_correction(): "v2" for
triton_v2 with an active adapter, "legacy" for the other backends, None
otherwise.

Owner: srt/models/deepseek_common (forward_mla.py).

Tests: correction numerics against a reference at both phases, the
v2/legacy/none selection under capture, the MLA forward's dense-import
contract, and the correction chain and pair routes under replayed graphs.
Add InklingBatchDenseMLPWithLoRAV2, which runs the shared sink on the pool
buffers through the dense runner, and keep the legacy wrapper for the other
backends. The model factory picks the class by backend; LoRAManager binds
only the sinks an adapter targets.

Tests: sink numerics, linearized-LoRA units (including the routed/sink overlap gate).
Add the MoE plan model (MoePlan, A/B families and specs, act and finalize
families, the ActivationFn enum), the plan loader with load-time validation,
the default table, and the SGLANG_LORA_MOE_CONFIG_DIR override. A device
without a tuned table serves the default plans.

Tests: spec and pipeline validation, fusion ownership, route-requirement
union, token-dense bridge ownership.
Add the MoE route factory: per-plan route bundles over the shared route
builder (aligned and raw views, shared-token routes, route PDL wiring keyed by
architecture).

Tests: PDL wiring, shared-token routes, launch-config route preflight.
Add the tuned sm90 and sm100 MoE plan tables.

Tests: every shipped table loads and resolves across the supported
geometries; the split-K launch ladder pinned to the shipped rows.
Add the Triton stages of the MoE engine: dispatch into masked and contiguous
row domains with FP8 row quantization, the activation delta, fused B +
activation, the materialized and shared finalizes, the MoE grouped B and the
down-B-into-base epilogue, and row alignment helpers. Register them in the
lora kernel inventory.

Tests: activation-quant fusion, the contiguous FP8 gather, per-row B numerics
and routing-graph replay. The B + activation, down-B-into-base and finalize
stages are exercised through the runner in the MoE runner part.
Add the provider contract (MoeBaseProvider, prepare/gateup/act/down over a
row domain), the masked and contiguous row domains, input alignment, the
BF16 quant info, and the Triton BF16 vendor. Vendors are selected per weight
family.

Tests: provider contracts and fused dispatch numerics.
Add MoeLoraRunner, which binds plans and providers once per layer and runs the
LoRA stages inside FusedMoE.run_moe_core, and wire it in: FusedMoEWithLoRA
takes the lora_* path, LoRAManager rejects target sets that leave MoE layers
without a runner, the memory pool refuses shared-expert weights without a
destination, and server args admit lora_cutedsl, lora_triton and lora_marlin
(triton_v2 only; standard dispatch; trivial expert placement; draft models
default to the ordinary runner). The runner admits BF16 experts; quantized
layers are rejected with a clear error until their vendors land.

Tests: runner attach and binding, the runtime contract, shared-outer
numerics, stage dispatch, the prefill-graph contract and e2e prefill graphs,
server-arg guards, model overrides. The runner-level numeric oracles run the
CuTeDSL vendor and land with it.
Add the dual-stage schedule builder (one int64 per tile) and the persistent
tile scheduler the CuTeDSL grouped GEMMs consume, plus the small masked
preparation that builds them in one launch.

Tests: schedule packing and builder boundaries. The small masked preparation
is exercised by the CuTeDSL BF16 part's tests.
Add the SM90 (WGMMA) and SM100 (tcgen05) BF16 grouped GEMM kernels, the
compile-and-prepare API, the CuTeDSL BF16 providers for both row domains, the
shared tile logic, and the per-geometry GEMM config store. The BF16 grouped
GEMMs are inventoried for SM90+, and CuTeDSL becomes the BF16 default vendor.

Tests: the runner-level numeric oracles (selected pipelines against an FP32
reference and in replayed graphs, B + activation, down-B-into-base), masked
capacity, contiguous row domain, small-preparation paths and blocks, provider
contracts, the GEMM config store.
Add the block-FP8 quant info and admission (128-block weights, resident
float8 bytes) and the Triton FP8 provider; the runner admits FP8 experts.

Tests: Triton FP8 provider numerics against an FP32 reference at hidden 512
and 7168, FP8 admission (weight family and geometry).
Add the SM90 and SM100 FP8 grouped GEMM kernels, the FP8 prepare entry points
and their inventory entries, and the CuTeDSL FP8 providers with 128x128 block
scales for both row domains. CuTeDSL becomes the FP8 default vendor.

Tests: CuTeDSL FP8 numerics, scale-epilogue tile rejection, the SM90
heuristic, masked-capacity graph replay, prepared-input reuse, FP8 vendor
selection.
Add the tuned CuTeDSL FP8 tile tables for B200, GB300 and H200 (masked and
contiguous row domains). A geometry without a table keeps the heuristic
tiles.

Tests: every shipped table loads under another package version.
Add the Marlin NVFP4 provider over prepared Marlin weights, the NVFP4 quant
info, the legacy hook's Marlin weight lookup, and the server-arg rule that
NVFP4 MoE LoRA requires lora_marlin.

Tests: NVFP4 provider numerics and the server-arg guard.
@Fridge003 Fridge003 added the release-highlight Candidate PR for release note highlight label Oct 22, 2026
@Fridge003
Fridge003 merged commit 1399967 into main Oct 22, 2026
739 of 840 checks passed
@Fridge003
Fridge003 deleted the lora-runtime-aggregate-20261022 branch October 22, 2026 20:41
This was referenced Oct 22, 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 jit-kernel lora npu quant LLM Quantization release-highlight Candidate PR for release note highlight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants