Skip to content

Memory loop 1–7 and the integration experiment: extraction, guard, retrieval, drift, binding check - #10

Merged
FMXExpress merged 23 commits into
mainfrom
claude/optimistic-allen-i3bd3d
Nov 6, 2026
Merged

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

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

This PR has the memory benchmark loop (iterations 1–7) and the small-profile integration experiment. Each change was measured with the bench/ scripts, and every iteration is written up in bench/README.md.

Changes

Extraction

  • Rule extraction stores 65–100% of naturally phrased facts; it stored 22–25% before.
  • It now also keeps facts about named people ("Ana's city is Lisbon."), in both trainer/memlib.py and memagent/Mem.Extract.pas. The extract cases pass 710/710.

Guard

  • It no longer withholds right answers.
  • The owner in a question must match the fact's owner: "my partner's birthday" is not "my birthday".
  • New binding check (Unbound in Mem.Guard): a value stored about a named person only supports answers about that person. On the retrieval-only answers from the integration run, wrong stored values dropped from 17 to 8. It blocked 9 answers, none of them correct.

Memory store

  • Similar subjects are no longer merged when the owner or the attribute differs (DistinctSubjects). Before, 14 of 112 facts were overwritten ("Tomas's job" replaced "Tomas's city"); now all 112 are kept.

Retrieval

  • Facts about someone the question doesn't name rank last. With 2,000 look-alike facts, hit@3 went from 0.833 to 0.967.

Training drift

  • Drift is now measured on a fixed held-out set of prompts in both trainers.
  • 24 general-text anchors cut tiny-model drift from 1.39 to 1.01 with the same accuracy. In the stream benchmark, deep-sleep drift growth went from 1.27→1.76 to 1.01→1.12 over 10–30 facts.

Trainer

  • Per-phase timing in the log and the manifest.
  • train.max_windows caps optimizer steps per epoch.
  • train.replay sets how many deep facts a fast run replays. Replaying all of them made no difference (loop 7), so the default stays at 1.
  • The llama.cpp patch now lets the f32 training copy be built from a q8_0 model (allow_requantize).

Benchmarks

  • New integration set and runner: bench/gen_integration.py, bench/bench_integration.py.
  • --set overrides profile settings for one run in bench_stream.py and bench_integration.py.

Integration experiment (Qwen2.5-1.5B, 112 facts, CPU)

The question: does a deep sleep teach the model to combine facts that retrieval alone can't?

  • Retrieval only: direct 24/24, bridge 3/24, inverse 7/24, verify 10/24 (12 is chance). Most two-step failures attach a value to the wrong person.
  • Training: at the drift limit of 1.5, the model learned which values exist but not whose each one is.
    • Default learning rate: recall 0.37.
    • Higher learning rate: recall 0.93, drift 2.07. It was accepted only because the drift limit was raised to 3 for this experiment.
  • Retrieval plus the trained memory: 28/53 against 29/53 for retrieval only; bridge fell from 3 to 1 of 24. The 2-hour task limit stopped this arm after 53 of 96 questions, so it never reached the verify questions, and the weights-only arm did not run. 33 of the 53 answers ran on with invented "User:/Assistant:" turns, which is what a drift of 2.07 looks like.

Verdict: on CPU, the 1.5B model's trained memory is a backup for facts retrieval misses, not a way to reason across facts. The useful gains came from the memory store and the guard.

Not done yet

  • build/memagent has not been rebuilt with the binding check and the merge fix, so no live benchmark run uses them yet. The guard numbers above come from re-checking saved answers offline.
  • The llama.cpp allow_requantize patch passes git apply --check, but llama.cpp has not been rebuilt to confirm the q8_0 → f32 conversion.

Generated by Claude Code

claude added 23 commits October 31, 2026 06:59
…cts (was 22-25%)

bench/facts_natural.json (40 dev + 40 held-out facts as people say them) and
bench/chatter.json (40 lines that state no fact) measure extraction coverage
and false memories; build/bench_extract scores the Pascal extractor.

28 rules from the dev misses (memlib.EXTRA_RULES, generated into
memagent/Mem.ExtractRules.inc so the Pascal and Python extractors share one
table), "my son Leo ..." relation + name, "my birthday's on", "I've been
working at". Value checks keep chat out: no pronoun/filler-led values, and a
proper noun where the rule is about a name or place.

dev 0.225 -> 1.000, held-out 0.250 -> 0.650, chatter false positives 0/40.
Parity 698/698. Also /weights <question> (answer from the adapters alone)
and bench/bench_stream.py (the continual-memory benchmark).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…; no redundant deep sleep

bench/results/stream-tiny-baseline.json: 30 facts over 3 sessions. The full
agent scored below the weights alone, mostly because the guard withheld
right answers whose question and fact use different words ("my employer" /
"where I work", "my boss" / "my manager", "my girl" / "my daughter").

Mem.Guard: groups of words that name the same thing. Re-scored offline on
the recorded answers: dev correct answers withheld 3-4 -> 0, confabulation
with the guard unchanged (0.25 dev and held-out).

A deep sleep is skipped when the deep LoRA already holds every fact (the
baseline spent 341 s rebuilding the same 10 facts).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…r test)

Profile (memory loop 3): training is 89-94% of a run, ~0.64 s per example
pass on tiny; a fast run over 10 new facts cost twice a deep sleep over 10
because its 10 replayed facts got full example sets. Replayed facts are
already in the frozen deep LoRA, so they now get max(2, per_fact div 3).
Verification on bench_stream is running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…, in both trainers

Taking the held-out prompts right after the training anchors made drift
measured with 16 anchors not comparable to 8 (other and more prompts).
Loop 4b results so far: max_windows=16 rejected (drift 1.49 -> 1.83).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…ay" is not "my birthday"); held-out drift confirmation for 24 anchors

Widening the guard to every question was measured and rejected: 12/60
correct dev answers blocked; neither bge scores nor retrieval rank
separate paraphrases from near-neighbour confabulation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…hit@3 with 2,000 look-alike facts 0.833 -> 0.967

bench_retrieval gains BENCH_FILLER=personal (look-alike facts about other
people), BENCH_POOL and BENCH_DEBUG. Both ranked lists are searched 4x
deeper, foreign-owner facts demoted per list before fusion, so fusion is
unchanged when nothing is foreign.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…); bench_stream --set overrides train settings

Default unchanged (1). Also untangles the Mem.Train constants block.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…on benchmark set and runner

The rule extractor stored only first-person facts, so facts that answer a
question only together (my sister -> Ana -> Lisbon) could not be told at all.
New rule in memlib and Mem.Extract, parity cases regenerated (710/710);
facts_natural coverage and chatter false positives unchanged.

bench/gen_integration.py builds 176 facts and 96 questions (direct, bridge,
inverse, verify); bench/bench_integration.py compares retrieval only,
retrieval + deep LoRA, and weights only, split by retrieval coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
The subject merge (TAgent.SameSubject) let the ms-marco cross-encoder decide
alone whether a new fact restates a stored subject. On the integration set it
merged 14 of 112 distinct subjects ("Tomas's job" over "Tomas's city",
"my grandpa's name" over "my grandma's name", "Mia's pet" over "Ana's
pet"), and a merge supersedes the older fact: silent memory loss.

Mem.Guard.DistinctSubjects vetoes the merge when both subjects read
"<owner>'s <attribute>" and the owners or the attributes differ (synonym
groups still match: mom/mother). Corrections of the same subject still merge.
Now 112/112 stored. bench_integration runs arm by arm (--arms, --keep).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
The small profile downloads qwen2.5-1.5b-instruct-q8_0.gguf; the llama trainer
makes its f32 copy with llama_model_quantize, which refuses quantized inputs
unless allow_requantize is set, so training on the small profile failed with
"could not convert ... to f32".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
… person

Integration set, small profile, retrieval only: 15 of 24 two-step questions
("Which city does my sister live in?") were answered with another person's
stored value ("Hana lives in Bologna", Bologna being Sofia's city). The
guard passed them: one licensed value (the sister's name) licensed the whole
answer, and nothing checked whose value the rest was.

Mem.Guard.Unbound: a value stored about named people may be used only for
the question's person (resolved through "my sister's name"), or, when the
question names no one, for the user's people the answer names, plus anyone
the question names. Offline on the retrieval arm's answers (bench_guard):
wrong stored-value answers 17 -> 8, no correct answer blocked; the 8 left
invent unstored values or name a stranger. bench/facts.json and held-out
results identical. bench_guard now reports wrong stored-value answers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
Retrieval + deep LoRA finished 53 of 96 questions before the task limit: no
integration gain (bridge 3 -> 1 of 24), and the drift (ppl 2.07) shows as
answers that run on with invented turns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
…and a plan for a learned memory reader

trainer/edit_facts.py writes facts into the down_proj of layers 4-8 in one
closed-form step per layer and exports the change as a LoRA the agent loads
like a deep-sleep adapter. bench_integration.py --memory DIR --name NAME runs
retrieval + that LoRA and weights only as two more arms. The plan follows
Memorilla (arXiv 2610.21375): two-hop retrieval baseline, a learned reader
as retriever on CPU, then soft-token injection as a tiny-profile pilot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
@FMXExpress
FMXExpress merged commit 128a49a into main Nov 6, 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