Repository navigation
Small models learn in-process on CPU and GPU: Qwen3-0.6B, LFM2, LFM3, Gemma 4 E2B (0.80–0.90 from the weights) - #23
Merged
Conversation
Four pieces: SSM_CONV backward into its input (d_conv shifted multiplies of the transposed gradient), CONCAT backward (the gradient split back), TRANSPOSE's gradient made contiguous (LFM's transposed b*x fed binary ops a strided first operand), and for recurrent/hybrid models each training window is one sequence (their ubatches need equal sequences; attention models keep masked packing). Also llm_graph_input_mem_hybrid skips the cache idxs when training bypasses the KV cache, as llm_graph_input_attn_kv already did. gradtest.cpp checks SSM_CONV and CONCAT against finite differences (14 checks, all pass). LFM2-1.2B now completes a deep sleep on the CPU (243 s with minimal settings); how well it learns is not measured yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…eval (30 facts, untuned); write up LFM training Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…rofile's) for the learning test; they stay chat-only Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…, drift 0.995 (undertrained; its short-conv projections are not LoRA targets yet) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…4 epochs at lr 6e-4: 0.80 from the weights, recall 1.00, drift 1.02 10 facts on the CPU: the small settings gave 0.15 (drift 0.995: barely trained); adding shortconv.in_proj/out_proj alone 0.20; with 4 epochs at lr 6e-4, 0.80, gate recall 1.00, drift 1.02, 17 min. The lfm2-1.2b and lfm3-1.7b profiles take those settings; both stay chat-only until LFM3 is measured. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…erences Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…d from the weights (10 facts, CPU) LFM3 with the LFM2 settings (short-conv projections as LoRA targets, 4 epochs at lr 6e-4): gate recall 1.00, drift 0.98, 0.85 from the weights and 1.00 with retrieval, 32 min on 4 cores. Both profiles switch from chat-only to "trainer": "llama"; README lists the small CPU profiles. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…s never in CPU_REPACK; no repack when training through quantized weights on the CPU llama.cpp patch: GELU (the tanh approximation ggml_gelu computes), TANH (Gemma's logit soft-capping) and GEGLU (split and fused) backward, built from forward ops. gradtest.cpp checks GELU and GEGLU's gate against the exact derivative (the CPU forward GELU is an fp16 table, so finite differences are noise there) and TANH and GEGLU's up path against finite differences: 19 checks pass. A Q4_0 base on the CPU lives in CPU_REPACK buffers. New LoRA tensors went there too (that buffer only holds repacked quantized tensors: an access violation), and OUT_PROD cannot read repacked weights (no backend for the backward). LoRA pairs now take the plain CPU buffer for any CPU-side weight, and with train_base = model on a CPU trainer the model loads without repacking (Mem.LlamaChat). Gemma 4 E2B then completes a deep sleep on the CPU (372 s, minimal settings, drift 1.10); how well it learns is not measured, so its profile stays chat-only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…ights, gate recall 0.97, drift 1.35); write up Gemma 4 training Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…4 E2B trainable (0.90 from the weights, drift 0.95) RTX PRO 4000 (24 GB), 15 min, about $0.14: gradtest and cudacmp pass on the card; Qwen3-0.6B, LFM2-1.2B and LFM3-1.7B give the CPU's answers from the weights (0.883, 0.80, 0.85) and drift within 0.01, deep sleeps of 17-32 s. Gemma 4 E2B with the small settings answers 0.90 from the weights (its retrieval 0.75: it refuses with the fact in the prompt), recall 0.90, drift 0.95, 16 s; its profile becomes trainable. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
memagent's own llama.cpp trainer now trains three new model families: Liquid AI's LFM2 and LFM3, and Gemma 4. All four small profiles are trainable and tuned, and each has been measured on the CPU and on a GPU. The write-up is in
bench/README.md, in the sections "Training the small CPU models" and "The small models on a GPU".llama.cpp patch
SSM_CONV(into its input),CONCATandSIGMOID;TRANSPOSEnow produces a contiguous gradient;llm_graph_input_mem_hybridskips the cache idxs that training leaves unallocated.GELU(the tanh approximation),TANH(soft-capping) andGEGLU(split and fused).CPU_REPACK. That buffer holds only repacked quantized tensors, and putting LoRA tensors there caused an access violation.OUT_PRODcannot read repacked weights.gradtest.cpppasses all 19 checks, andcudacmp.cpppasses on the GPU.Profiles
qwen3-0.6blfm2-1.2blfm3-1.7blfm2-1.2bgemma4-e2bsmallsmallsettings, LFM2 scored 0.15 from the weights, and Qwen3-0.6B scored 0.667 with drift 1.56.Test plan
make test-pascalgradtest.cpppasses all 19 checks on the CPU and on the GPUcudacmp.cpppasses on the GPUbench_memory.py --trainer llamafor all four profiles, on the CPU (except Gemma) and on an RTX PRO 4000 (bench/results/memory-*-{cpu,gpu}*.json)🤖 Generated with Claude Code
https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn