llama: inkling2_loop - per-pass views of host weights for the later loop passes (F13)
Knobs LLAMA_LOOP_HOST_VIEWS=0 (upstream's shared tensors) and LLAMA_LOOP_FULL_COPY=0 (skip upstream's #32807 full-copy guard, which the views make redundant; set in production). Squashed from 2 fork commits (original subjects and messages below). ---- llama: inkling2_loop - per-pass views of host weights for the later loop passes (was53d2828bb) inkling2_loop runs the core layers (6..17 on Inkling-2-Mini) three times, and post_arch_tensors makes every cache slot share the tensors of its physical layer. With the experts in host memory (--n-cpu-moe, -ot exps=CPU) the scheduler makes one device copy per (host tensor, backend) per graph, at the first split that reads it, and keeps it until the last reader. So: - the expert copies of all 12 loop layers are alive at once (about 6.5 GiB on UD-Q4_K_XL), which is most of the ~7 GiB Vulkan0 compute buffer; - sched_copy_experts runs only for the first reader. When it reads the ids back (ubatches of 32-63 tokens: MUL_MAT_ID is offloaded from 32 tokens, the F1 skip starts at 4*n_expert ids), it uploads only the experts that pass 0 selected, and passes 1 and 2 read stale VRAM for the others (upstream issue #32755, "GGGG" output). Add a post_load_tensors hook to llama_model (called after the weights are loaded, and on the no_alloc path after the dummy buffers are set). In inkling2_loop it replaces, for each slot of a later pass, every tensor in a host buffer with a view of it (name "<name>.visit<pass>", buffer and data of the original). The scheduler hashes tensors by pointer, so each pass gets its own copy, freed after that pass, and the copy callback sees the ids of that pass. Weights in device buffers and CPU extra buffers (CPU_REPACK, not host) stay shared. The pointer-keyed weight maps (w_scales, prec_policy, hdmd.rot) get entries for the views. The views live in a model-owned context outside ctxs_bufs, so the F4 release/restore, tensor counts and the memory breakdown do not see them; they point only at host buffers, which F4 never releases. LLAMA_LOOP_HOST_VIEWS=0 keeps the shared tensors (A/B knob). Not built or run yet. ---- llama: env knob LLAMA_LOOP_FULL_COPY=0 to skip upstream's inkling2_loop full-copy guard (#32807) (was5f88124b3) Upstream #32807 makes sched_copy_experts return false for inkling2_loop, so the scheduler copies every expert of a host weight it shares across the loop passes (the fix for #32755). With the F13 per-pass views each pass has its own device copy and its own ids, so the partial copy (routing readback below the F1 skip threshold, 32-63-token ubatches on Inkling-2-Mini) is correct again and the guard only costs uploads. LLAMA_LOOP_FULL_COPY=0 skips the guard for an A/B; the default keeps upstream's behaviour. With LLAMA_LOOP_HOST_VIEWS=0 the knob brings #32755 back, do not combine them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PZz44SLQvTXMyWGio6t9DZ
This commit is contained in:
1 parent
ea2f537287
commit
3f9b79b45a
5 files changed
+120
-1
No files matched your search
@@ -2253,6 +2253,7 @@ bool llama_model_base::load_tensors(llama_model_loader & ml) {
|
||||
}
|
||||
|
||||
if (ml.no_alloc) {
|
||||
post_load_tensors(ml);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2283,6 +2284,8 @@ bool llama_model_base::load_tensors(llama_model_loader & ml) {
|
||||
|
||||
load_tensors_hadamard();
|
||||
|
||||
post_load_tensors(ml);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user