Module lora_delta

Module lora_delta 

Source
Expand description

Runtime LoRA delta: y += scale * (x @ A^T) @ B^T, BF16 side-path. Zero new CUDA kernels — reuses dense_gemv_bf16 / dense_gemm_tc / dense_gemm_bf16 / bf16_scaled_add, all shipped in kernels/gb10/common/.

Structs§

LoraAttnWeights
Per-layer attention-side LoRA weights, installed by copy onto Qwen3AttentionLayer.
LoraFfnWeights
Per-layer dense-FFN LoRA weights, installed by copy onto DenseFfnLayer.
LoraKernels
Resolved once at adapter load (module names per common/KERNEL.toml: gemv=dense_gemv_bf16.cu, gemm_tc=dense_gemm_tc.cu, gemm=dense_gemm_bf16.cu, residual_add=residual_add.cu — stem, no override).
LoraPair
One adapted module. A/B are PEFT tensors VERBATIM (host F16->BF16 at load): a: [rank, k_in] row-major BF16 (PEFT lora_A [r, in_features] — already the B-operand [N,K] layout dense_* expect) b: [n_out, rank] row-major BF16 (PEFT lora_B [out_features, r] — likewise) Both are rank-padded to the pool’s max_rank (zero rows/cols beyond rank), so kernels may uniformly run at the pool rank — bit-identical to true rank. scale = lora_alpha/r, or lora_alpha/sqrt(r) under use_rslora — read per adapter at load, never defaulted. Do NOT pre-fold into B (keeps tensors verbatim for the M0 offline parity test); it rides the scaled_add for free.
LoraRoute
Frozen per-(layer,module) routing tables the bgmv reads: the [max_loras] device pointer tables (a_table/b_table, NULL=base) + the shared [max_loras] f32 scale_table, plus the projection dims. Load-time-fixed device addresses (built at pool pack time), so they are stable kernel args across CUDA-graph capture/replay — adapter identity flows ONLY through the per-step seq_slot buffer. Installed by copy onto the layer next to the active-slot LoraPair (which the single-seq n==1 path still uses).

Functions§

apply_lora_bgmv
M2 per-request routed LoRA delta over a batch of n decode rows, each naming its own adapter slot via seq_slot[n] (i32, <0 = base/no delta). Two launches — shrink then expand+fold — reading the module’s frozen route.a_table/route.b_table/route.scale_table ([max_loras] device arrays, NULL/0 = base-only slot) at the load-time-fixed pool addresses.
apply_lora_delta
lora_gemv_max_m
Row count at or below which the delta runs as m row-wise GEMVs instead of one GEMM (ATLAS_LORA_GEMV_MAX_M, default 8).
lora_no_apply
base_out[m, n_out] += scale * (x[m, k_in] @ a^T) @ b^T.
lora_no_ffn
ATLAS_LORA_NO_FFN=1 — skip the dense-FFN and GDN-out_proj deltas, keep the attention ones.