Skip to content

perf(qlora): accelerate routed expert backward on CUDA - #697

Merged
xsuler merged 1 commit into
mainfrom
perf/spark-qlora-routed-backward
Nov 25, 2026
Merged

xsuler merged 1 commit into
mainfrom
perf/spark-qlora-routed-backward

Conversation

@xsuler

@xsuler xsuler commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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

  • Performance improvement

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.

Version Microbatch MST chunk Train step Peak allocated Peak reserved
Main at bc3ee6f 8 256 282.0 s 10.29 GiB 11.21 GiB
This change 8 256 156.3 s 10.29 GiB 11.16 GiB
This change 4 1,024 123.2 s 8.42 GiB 8.79 GiB

The kernel change alone gave a 1.80× speedup at the original settings. Setting ARENO_MST_CHUNK_SIZE=1024 and --mini-bs 4 brought 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.0 and 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.
  • The extended attention suite reported two FP32 SDPA comparison failures (full and windowed). Both reproduced on the base commit on the same Spark.

Checklist

  • Added regression coverage for the packed backward path.
  • Documented benchmark settings, hardware and correctness checks.

@xsuler
xsuler merged commit d9667ad into main Nov 25, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant