Archived
libref, libavx: lora_shrink and lora_expand, the per-row runtime LoRA ops
The two halves of y += scale * (B . (A . x)) at a trunk GEMM, with each row's adapter named by an
i32 `slot`:
lora_shrink t[m, j] = sum_k x(m, k) * lora_a[s, j, k]
lora_expand y[m, n] = y[m, n] + scale[s, n] * sum_j t[m, j] * lora_b[s, n, j]
A row whose slot is outside [0, S) is a base row and neither op touches it: shrink writes no `t`,
expand neither reads nor writes `y`, so a base row stays bit for bit what the GEMM wrote (y + 0
would already turn a -0 into +0). x(m, k) is gemm_nt_q's activation value, read through the same
make_scales; an fp8/i8 activation without its scale stream is refused. The dtype parameters carry
the tensor dtype names (rad_dtype_name). Sums are per row in a fixed order, so a row's bytes do
not depend on M or on its neighbours.
libref is the oracle (straight f32 loops, OpenMP over whole output elements); libavx covers both
at every ISA level with vectorised dots. ref_test gains hand-computed cases (column slices, -1 and
S as base slots, a -0 that must survive, the fp8 scale fold, the missing-scale and wrong-group
refusals); avx_check gains a case table; docs/OPS.md the two rows; rad-kbench and avx_check a
tolerance row for the shrink's f32 reduction.
This commit is contained in:
1 parent
48f7b8eb6d
commit
7864acf50a
13 files changed
+569
No files matched your search
@@ -71,6 +71,10 @@ const std::vector<TolRow> g_tol = {
|
||||
/* A dot product per candidate against the bf16 head: a GEMM's error. */
|
||||
{ "logit_rerank", "*", 8e-3 },
|
||||
{ "moe_gemm", "*", 3e-2 },
|
||||
/* Runtime LoRA's shrink is a K-long reduction into an f32 `t` whatever `a` is -- the codes are
|
||||
* decoded the same way on both sides, so only the summation order differs, and that is what
|
||||
* gemm_nt's f32 row allows. Expand's R-long sum lands in `y` and takes the dtype rows below. */
|
||||
{ "lora_shrink", "*", 2e-5 },
|
||||
/* Attention: a softmax over a long context plus a second reduction. */
|
||||
{ "attn_", "bf16", 2e-2 },
|
||||
{ "attn_", "f32", 1e-4 },
|
||||
|
||||
Reference in new issue
Block a user