Repository navigation
perf(qlora): accelerate routed expert backward on CUDA - #697
Merged
Merged
Conversation
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.
What does this PR do?
The native CUDA Ling QLoRA path previously expanded each frozen NF4 expert bank during backward and dispatched separate gradient GEMMs for each expert. This change reuses the forward routing indices to compute input gradients directly from packed NF4 tiles. It also batches the LoRA input and weight gradients on the GPU. The regression test fails if routed backward calls full-bank dequantization.
Type of change
How was it tested?
Single NVIDIA GB10 (DGX Spark), Ling-3.0-tiny, GSPO, native CUDA attention, rank-16 QLoRA and 4-bit Adam. One training step used 64 fixed sequences, each with 128 prompt tokens and 1,024 response tokens, after warmup. Times exclude rollout.
bc3ee6fThe kernel change alone gave a 1.80× speedup at the original settings. Setting
ARENO_MST_CHUNK_SIZE=1024and--mini-bs 4brought the measured speedup to 2.29×. These are single-step measurements. Multi-GPU performance was not measured.In a separate on-policy run after an optimizer update, rollout generated 64 × 1,024 response tokens. The tuned training step took 124.5 s, with
logp_abs_diff_mean == 0.0and gradient norm 0.0970. The microbenchmark produced bitwise-identical forward outputs. BF16 backward uses a different reduction order and the largest per-tensor relative L2 gradient difference measured against the previous kernels was 0.46%.pytest -q tests/test_qlora.py tests/test_logprobs_cpu.py tests/test_mst_cpu.py— 51 passed on Spark.Checklist