Skip to content

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
FMXExpress merged 10 commits into
mainfrom
claude/optimistic-allen-i3bd3d
Nov 11, 2026
Merged

FMXExpress merged 10 commits into
mainfrom
claude/optimistic-allen-i3bd3d

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

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

  • LFM2/LFM3 (short convolutions):
    • backward passes for SSM_CONV (into its input), CONCAT and SIGMOID;
    • TRANSPOSE now produces a contiguous gradient;
    • recurrent and hybrid models train each window as one sequence;
    • llm_graph_input_mem_hybrid skips the cache idxs that training leaves unallocated.
  • Gemma 4: backward passes for GELU (the tanh approximation), TANH (soft-capping) and GEGLU (split and fused).
  • Quantized weights on the CPU:
    • LoRA tensors never go in CPU_REPACK. That buffer holds only repacked quantized tensors, and putting LoRA tensors there caused an access violation.
    • When training runs through quantized weights on the CPU, the model loads without repacking, because OUT_PROD cannot read repacked weights.
  • Tests: gradtest.cpp passes all 19 checks, and cudacmp.cpp passes on the GPU.

Profiles

profile settings facts from the weights with retrieval gate recall drift deep sleep: GPU / 4 CPU cores
qwen3-0.6b 3 epochs, 32 anchors 30 0.883 0.95 0.97 1.35 23 s / 21 min
lfm2-1.2b short-conv targets, 4 epochs, lr 6e-4 10 0.80 0.95 1.00 1.03 17 s / 17 min
lfm3-1.7b same as lfm2-1.2b 10 0.85 1.00 1.00 0.99 32 s / 32 min
gemma4-e2b small 10 0.90 0.75 0.90 0.95 16 s / not run
  • CPU and GPU agree. The GPU (RTX PRO 4000, 24 GB, 15 minutes, about $0.14) gives the CPU's answers from the weights, with drift within 0.01. It trains 55–60× faster.
  • Gemma 4's trained memory beats its retrieval. With the fact in the prompt it often refuses, scoring 0.75 with retrieval against 0.90 from the weights.
  • The defaults were weak. With the small settings, LFM2 scored 0.15 from the weights, and Qwen3-0.6B scored 0.667 with drift 1.56.

Test plan

  • make test-pascal
  • gradtest.cpp passes all 19 checks on the CPU and on the GPU
  • cudacmp.cpp passes on the GPU
  • The patch applies cleanly to llama.cpp b11985
  • bench_memory.py --trainer llama for all four profiles, on the CPU (except Gemma) and on an RTX PRO 4000 (bench/results/memory-*-{cpu,gpu}*.json)
  • Gemma 4 completes a deep sleep on the CPU, through Q4_0 weights loaded without repacking

🤖 Generated with Claude Code

https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn

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
…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
…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
@FMXExpress FMXExpress changed the title LFM2/LFM3 train in-process (short-conv backward in the llama.cpp patch); Qwen3-0.6B trains on the CPU LFM2-1.2B and LFM3-1.7B learn in-process (short-conv backward in the llama.cpp patch); Qwen3-0.6B trains on the CPU Nov 10, 2026
…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
@FMXExpress FMXExpress changed the title LFM2-1.2B and LFM3-1.7B learn in-process (short-conv backward in the llama.cpp patch); Qwen3-0.6B trains on the CPU Small CPU models learn in-process: LFM2/LFM3 (0.80/0.85), Qwen3-0.6B tuned (0.883); Gemma 4 trains end to end Nov 11, 2026
…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
@FMXExpress FMXExpress changed the title Small CPU models learn in-process: LFM2/LFM3 (0.80/0.85), Qwen3-0.6B tuned (0.883); Gemma 4 trains end to end Small models learn in-process on CPU and GPU: Qwen3-0.6B, LFM2, LFM3, Gemma 4 E2B (0.80–0.90 from the weights) Nov 11, 2026
@FMXExpress
FMXExpress merged commit 53c18af into main Nov 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants