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
@@ -254,6 +254,22 @@ std::vector<Case> build_cases() {
|
||||
2.0 * M * 192 * 256);
|
||||
add("gemm_nt_q_gated", { HI("M", 7), HI("N", 512), HI("K", 256), HI("group", 128),
|
||||
HS("dtype", "fp8a8"), HS("act", "silu") }, 0, 2.0 * 7 * 512 * 256);
|
||||
/* Runtime LoRA. libref's description draws `slot` in [0, S], so S itself -- a base row --
|
||||
* comes up in every case of more than one row and the comparison covers rows neither op may
|
||||
* touch (a single row draws an adapter, or the case would compare nothing). M = 1 takes the
|
||||
* shrink's team-over-columns arm and 9 and 65 its team-over-rows one; K = 1000
|
||||
* leaves a partial scale group and a vector tail at every level; R = 48 is not a power of two.
|
||||
* The dtype is `a`'s for shrink -- the coded ones with their scale stream -- and `y`'s for
|
||||
* expand. */
|
||||
for (int M : { 1, 9, 65 }) {
|
||||
for (const char* dt : { "f32", "bf16", "f16", "fp8_e4m3", "i8" })
|
||||
for (int K : { 256, 1000 })
|
||||
add("lora_shrink", { HI("M", M), HI("K", K), HI("R", 48), HI("S", 4),
|
||||
HI("group", 128), HS("dtype", dt) }, 0, 2.0 * M * 48 * K);
|
||||
for (const char* dt : { "f32", "bf16", "f16" })
|
||||
add("lora_expand", { HI("M", M), HI("N", 645), HI("R", 48), HI("S", 4),
|
||||
HS("dtype", dt) }, 0, 2.0 * M * 645 * 48);
|
||||
}
|
||||
for (const char* dt : { "f32", "bf16" }) {
|
||||
add("embed_lookup", { HI("M", 9), HI("n_embd", 128), HI("n_vocab", 64), HS("dtype", dt),
|
||||
HI("vocab_offset", 0), HF("mult", 1) });
|
||||
|
||||
Reference in new issue
Block a user