Commit Graph
3 Commits
Author SHA1 Message Date
baKon 39dfaf6368 core/lora: LoRA sites from the declared program, and a PEFT adapter packed per rank
build_sites() walks one rank's Program after declare and makes a Site of every LoRA-capable
trunk GEMM (gemm_nt, gemm_nt_bias without act, gemm_nt_q without pb1/pb2 and with K equal to the
weight's, gemm_nt_q_bias) whose `b` weight a target leaf names. The geometry is read off what the
plugin recorded on the weight -- shard mode, row parts, shard and per-part spans, name-map
sources -- and is checked against weight_share() on a plain view of the weight, so the LoRA slice
and the loader's slice cannot disagree. Sites of one declared weight share one pool.

weight_targeted() is the one predicate (scope rule in lora.h), usable mid-declare.
find_unsupported_uses() lists every live op that reads a targeted weight and is not a site: a
fused gated fold, a routed expert, a weight stored in a transform basis, a rotated or widened
gemm_nt_q. Unresolved ops the builder recorded are never issued and are skipped.

load_adapter() reads adapter_config.json and adapter_model.safetensors, refuses what is not
plain linear LoRA (DoRA, other peft types, modules_to_save, trained or lora biases, embedding
LoRA, fan_in_fan_out, parameter LoRA, rank above the cap, rank/shape mismatches, an ambiguous
VLM spelling), computes alpha/r or alpha/sqrt(r) with rank_pattern/alpha_pattern searched as
rad-export does, converts BF16/F16/F32 to bf16 RNE and packs one slot per pool. A fused weight
whose sources are fewer than its row parts (the delta net's ssm_inz) is laid out from the
adapter's B rows. A module no site on this rank takes is listed, not refused -- an
attention-zero rank declares no q/k/v/o -- and check_placed() refuses one no rank took.

tests/lora_test.cpp declares with the real Builder and arch/common's LinearFP8 (fused qkv and
gate_up; gated attention with an attention-zero rank and KV replication; the delta net's uneven
2/2/1 head split) at worlds 1-4 and holds every rank's slot product to the dense delta. It
loads no kernel plugin, so it never reaches the device layer.
2026-10-16 20:52:09 -05:00
baKon 0fce4d4e21 tests: the kernel ops' test is lora_ops_test; lora_test is the loader's 2026-10-16 20:52:09 -05:00
baKon 51293b269c tests: lora_test and r4d_emu_lora over one shared case matrix
lora_cases.h holds the matrix (M 1/3/17/64/130, R 16/32/48, S 4, K and N 64/256/1000, a bf16 or
E4M3 with a 128-column scale, y bf16/f32, f16/f32/E5M2/i8 once; a, a_scale and y as column
slices; slots -1, -5, 0..3 and S) and the checks: base rows untouched by bytes (a sentinel NaN in
t, -0 in y), adapter rows against an f64 sum within (K + 2) 2^-24 sum|terms| (shrink) and half an
ulp of y plus 4 (R + 2) 2^-24 (|y| + |scale| sum|terms|) (expand).

lora_test runs libref and libavx at every ISA level through rad_plugin_open (libavx builds its fp8
decode table there). r4d_emu_lora runs libr4d's source on the SIMT emulator beside ref_host.cpp
and libref, expand bit for bit.
2026-10-16 20:52:09 -05:00