Repository navigation
Conversation
Triton LoRA kernel changes (all dense MLA + MoE virtual-expert paths): - SGLANG_LORA_ENABLE_PDL (EnvBool, default off): Programmatic Dependent Launch on the LoRA kernels — dense shrink (sgemm_lora_a, incl. split-K), expand (sgemm_lora_b / qkv_lora_b / gate_up_lora_b), absorbed kv_b correction (step_a/b_q/v), MoE virtual-expert shrink/expand, and the routing-prep kernels. Each issues its static loads (LoRA weights + routing metadata) in the prologue, then gdc_wait() before the dynamic activation, and gdc_launch_dependents() at the end. AND'd with is_arch_support_pdl() (Hopper+; no-op on HIP/MUSA). Helpers lora_pdl_enabled() / lora_pdl_launch_kwargs() in triton_ops/kernel_utils.py. Opt-in: measured ~neutral E2E at bs64, so it is off by default and exposed as a knob for further overlap work. - LoRA-B expand fused base-add via atomic_add: sgemm_lora_b is a single K-tile (BLOCK_K = next_pow2(rank) >= rank), so the loop is replaced by a straight line and the base read+add+store becomes a relaxed atomic_add. This drops the output-read stall from the critical path (~7-13% faster expand on B200); qkv_lora_b / gate_up_lora_b adopt the same atomic_add fused add. Correct in the dense path because each (token, n) output tile has a single writer. - Absorbed kv_b kernels: block sizes derived from the real per-step dims via next_power_of_2 (contraction K and output N) instead of fixed constants, with the wide contractions capped at 256; step_b kernels accumulate into base via atomic_add. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
LoRA Triton kernel changes — PDL (opt-in), atomic-add expand, adaptive
kv_bblock sizesScoped to one commit (
9c219ae) on top of thelora-splitk-pr8series. Base is thepre-session commit (
4b6a72a"manual tune") so the diff is only these kernelchanges (+320/−98, 10 files). It is not based on
sgl-project/sglang main: thisbranch is ~14 commits / 750 files behind/diverged from upstream main, so a real
upstream PR would need a rebase + extraction of just these hunks first.
What's here
1. Opt-in PDL —
SGLANG_LORA_ENABLE_PDL(EnvBool, default off)Programmatic Dependent Launch on the LoRA kernels: dense shrink (
sgemm_lora_a,incl. split-K), expand (
sgemm_lora_b/qkv_lora_b/gate_up_lora_b), absorbedkv_bcorrection (step_a/b_q/v), MoE virtual-expert shrink/expand, and therouting-prep kernels. Each loads its static inputs (LoRA weights + routing metadata)
in the prologue,
gdc_wait()s before the dynamic activation, andgdc_launch_dependents()s at the end. AND'd withis_arch_support_pdl()(Hopper+;no-op on HIP/MUSA). Helpers
lora_pdl_enabled()/lora_pdl_launch_kwargs()intriton_ops/kernel_utils.py.Measured ~neutral E2E (Kimi-K2.5-NVFP4, tp8, bs64: −0.26%, noise), so it ships
off as a knob for further overlap work (the genuine win needs a producer-only
shrink / consumer expand split, not the blanket gate).
2. LoRA-B expand fused base-add via
atomic_addsgemm_lora_bis a single K-tile (BLOCK_K = next_pow2(rank) ≥ rank), so the K-loopis replaced by a straight line and the base read+add+store becomes a relaxed
atomic_add. This drops the output-read stall from the critical path (~7–13% fasterexpand on B200).
qkv_lora_b/gate_up_lora_badopt the same fusedatomic_add.Correct in the dense path: each
(token, n)output tile has exactly one writer(ordered after the base GEMM on the same stream).
3. Absorbed
kv_badaptive block sizesstep_a/b_{q,v}deriveBLOCK_K/BLOCK_Nfrom the real per-step dims vianext_power_of_2(contraction K and output N), wide contractions capped at 256,instead of fixed constants;
step_baccumulates into base viaatomic_add.Testing
Correctness validated on B200 (PDL on == off, bit-identical, matches fp32 reference)
for the shrink and
step_akernels via a scratch harness (not included). No directunit test exists for the absorbed
kv_bkernels yet — only indirect E2E coverage viatest/registered/lora/test_lora_kimi_k25_logprob_diff.py. A direct registered kerneltest (à la
test_virtual_experts_kernels.py) is a recommended follow-up.🤖 Generated with Claude Code
Investigated (this session): does a
num_adapter==1cuBLAS fast path beat these Triton expands?For a single loaded adapter every token routes to slot 0, so the segmented SGMM
collapses to a plain dense GEMM. The pool already zeroes the B
[rank:]tail, so acuBLAS path contracting over the full padded
Ris bit-identical to Triton(
max_err = 0.0000everywhere below). Scaling is folded intoxon-device and sliceoffsets baked as host ints, so the path is CUDA-graph capturable (indexing the GPU
output_offsetforces an illegal capture-time sync). Benched triton-vs-cublas on B200with
do_bench(cuda-graph + L2-cold).speedup = triton_us / cublas_us(>1 ⇒ cuBLAS wins):sgemm_lora_b— cuBLAS LOSES across decode; keep Triton.The expand's contraction
K = rankis tiny (16–64), a "fat, tiny-K" GEMM thatunder-utilizes cuBLAS and pays its ~3.2 µs launch/heuristic floor — more than Triton's
whole ~1.9–2.6 µs runtime. (Opposite of the LoRA-A shrink, where the large-K
contraction lets
F.linearwin 1.2–1.7×.) No dispatch added —sgemm_lora_b.pyis unchanged; a
weights.shape[0]==1 → addmmbranch was prototyped then revertedbecause it regresses decode ~1.5–2×.
qkv_lora_b— shape-dependent; cuBLAS wins high-batch + prefill, loses low-bs decode.The fused qkv kernel tiles each length-1 decode segment independently (grid axis2 = bs,
BLOCK_S=16wastes 15/16 rows, ×n_slices×BLOCK_OUT=64fine N-tiles), so its realGPU time grows ~linearly with bs (45–81 µs at bs=128, N=6144) while the dense cuBLAS path
stays flat ~7 µs. A bs/seg-gated cuBLAS dispatch for
qkv_lora_bis a plausiblefollow-up (helps high-concurrency decode + prefill), but it is not a clean low-bs decode
win and is left out of this PR.
Benches added (standalone, not wired into CI):
bench_sgemm_lora_b_cublas.py,bench_qkv_lora_b_cublas.py(--slice-dims).CI States
Latest PR Test (Base): ❌ Missing
run-cilabel -- add it to run CI tests.Latest PR Test (Extra): ❌ Blocked --
run-ciis required first.