Skip to content

Memory tiers (fast LoRA on a frozen deep one), varied training examples, AVX2 release builds - #6

Merged
FMXExpress merged 8 commits into
mainfrom
claude/optimistic-allen-i3bd3d
Oct 31, 2026
Merged

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

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Two memory tiers

With the in-process trainer ([consolidate] tiers=auto, the default), long-term memory has two LoRAs applied together:

tier holds trained
fast facts since the last deep sleep whenever the trainer is free and a fact is in no adapter yet: a fresh adapter on top of the frozen deep one, on the new facts plus a replay sample of deep facts; the gate probes both
deep every fact a deep sleep: once the fast LoRA holds deep_after (8) facts, or a fact was forgotten or changed (at most every interval_min), or /sleep; rebuilt from the base model as before, then the fast LoRA empties
  • Training yields to the chat: it runs one window at a time and waits while a turn is being answered.
  • Before the first deep sleep, every run is a deep one.
  • Commands:
    • /nap: start a fast run now.
    • /sleep: start a deep sleep, cancelling a run in progress.
    • /wait: wait until memory has caught up, including follow-up runs.
    • /status and /adapter: show both tiers.
  • Quitting cancels a fast run and waits for a deep one.
  • llama.cpp patch: adds llama_lora_train_init_adapter, which trains one adapter while the other attached adapters stay frozen, and sizes the graph budget per attached adapter.
  • New code:
    • TLlamaChat.GenerateWith applies several adapters.
    • TEngine gets LoadFastAdapter / ClearFastAdapter / FastAdapter.
    • TMemStore gets ApplyFastManifest and FastTierCount.
    • Fast adapters are fast-<ts>, and /rollback only goes back to deep (mem-) ones.

Varied training examples

Mem.Examples (ported to memlib.varied_qas) can turn each fact into several kinds of example instead of one answer string:

  • short and full answers to its paraphrased questions
  • the value asked from the other side
  • yes/no checks, including one with another fact's value
  • fill in the blank
  • two facts asked together

This follows Hatakeyama-Sato et al. 2023 and O'Neill et al. 2026. tiny now uses varied examples, 12 per fact, with adapters on v_proj, o_proj, gate_proj, up_proj (details in bench/README.md).

LoRA alone: accuracy LoRA + RAG: accuracy LoRA alone: confabulation drift
dev, before 0.75 0.883 0.80 1.29
dev, after 0.933 0.967 0.70 1.49
held-out, before 0.85 0.75 0.85 1.15
held-out, after 0.925 1.00 0.80 1.48
  • Accuracy: varied examples are worth 13–18 points from the weights alone.
  • Confabulation: unchanged within noise; the guard still handles it in the agent.
  • Drift: rises but stays well inside the 3.0 gate.

Benchmark harness

bench_memory.py --trainer llama [--set key=value] trains and answers through the new build/bench_llama, which uses the in-process trainer and engine, so the benchmark measures what the agent ships.

Release builds were plain SSE

LLAMA_PORTABLE=1, and the Windows release cmake call, set GGML_NATIVE=OFF but never enabled AVX2. ggml was therefore built for baseline x86-64, several times slower; 3 facts × 1 epoch took 357 s. Portable builds now enable AVX/AVX2/FMA/F16C/BMI2, which covers Haswell (2013) and later. The v0.2.0 binaries have the slow build.

Tests

  • make test: pass.
  • scripts/e2e_tiers.sh (make test-tiers, new): pass.
    • Deep LoRA with 3 facts, then two rolling fast runs (1 fact, then 2), each keeping 3/3 earlier facts.
    • The fast and deep tiers both answer from the weights.
  • MEMAGENT_ENGINE=llama scripts/e2e_demo.sh: pass with tiers on, covering supersede, /forget and /rollback through the tiers.

Generated by Claude Code

…es, AVX2 portable builds

- Tiers ([consolidate] tiers=auto): a fast LoRA retrains on the facts since
  the last deep sleep whenever the trainer is free, on top of the frozen deep
  LoRA, with a replay sample of deep facts; a deep sleep rebuilds the deep
  LoRA from every fact once the fast one holds deep_after facts, or a fact
  was forgotten or changed. Training waits between windows while a turn is
  answered. /nap, /sleep (cancels a run in progress), /wait until caught up.
- llama.cpp patch: llama_lora_train_init_adapter trains one adapter while
  the other attached adapters stay frozen; graph budget per attached adapter.
- Mem.Examples: templates (as before) or varied examples per fact (short and
  full answers, reverse questions, yes/no checks with another fact's value,
  fill in the blank, two facts together); ported to trainer/memlib.py.
- bench_memory.py --trainer llama with build/bench_llama: trains and answers
  with the in-process trainer and engine; --set overrides training settings.
- LLAMA_PORTABLE builds (and the Windows release) now enable AVX2/FMA/F16C:
  GGML_NATIVE=OFF alone compiled ggml for plain SSE, several times slower.
- scripts/e2e_tiers.sh (make test-tiers).

Benchmark runs B-D (varied examples) still in progress.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
Run C of the varied-examples benchmark (bench/README.md): LoRA accuracy
0.75 -> 0.93, interference 0.083 -> 0.05, drift 1.49 (gate 3.0).
Confabulation is unchanged within noise; the guard still handles it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
@FMXExpress
FMXExpress merged commit cde3b94 into main Oct 31, 2026
1 of 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