TL;DR: Memorilla packs each stored fact about a user into 16 memory tokens for Qwen3-8B. On fact types it never trained on, the best pipeline on those tokens acts on the one relevant fact in 44% of answers; a perfect picker would reach 80%, and a 27B judge reading the facts as text reaches 68%. The gaps are finding the fact among 48+ others and a reader that mostly uses it only when it comes first; the next step, teaching the token rater from the 27B judge, is ready to run. Done mostly by an AI agent (Claude) under the author's direction.
experiments/ folder (scripts and docs), mport/ (a small package) and work/ (data, checkpoints, logs).MemoryModule for Qwen3-8B, about 194M parameters (370 MB). 16 learned slots cross-attend to the request embedding, then 2 cross-attention blocks attend over the document embeddings, then a projection maps 2560 to 4096 dimensions, into the decoder's embedding space.Qwen/Qwen3-Embedding-4B (2560-d). Every fact and request is embedded once and cached.Qwen/Qwen3-8B. Memory tokens replace <|memory|> placeholder embeddings in the prompt.Each stored fact goes through the untouched core alone, conditioned on the request, and comes out as one 16-token block. The k picked blocks are concatenated into 16·k memory tokens.
stored facts (a profile of 8 / 16 / 48 / 192)
| each fact + request --> frozen core --> 16-token block
v
picker: rate each block alone ("does this fact change a good reply?") --> keep top k
v
reader (Qwen3-8B + LoRA) with k blocks in memory --> "Relevant fact: ..." + answer
The reader is Qwen3-8B with a LoRA (rank 16, alpha 32, on q/k/v/o of all 36 layers), lora_lsort.pt. It was trained on blocks sorted best-first and writes Relevant fact: … before the answer.
| Term | Meaning |
|---|---|
| clue | the one stored fact that should change the answer |
| profile | the clue plus 7, 15, 47 or 191 other users' facts (distractors) |
| block | the 16 memory tokens of one fact |
| rater / picker | scores each fact for a request; the top k go to the reader |
| text rater | a decoder rating the fact given as plain text (off the token path) |
| block rater | a decoder plus LoRA rating the fact from its block (on the token path) |
| acts | the regex rubric says the answer acts on the clue (the main metric) |
| held-out types | health, no_car, toddler, flying: never trained on |
acts and mentions rubrics (deliberately not LLM-generated).all_of group needs a word-boundary regex hit and no none_of term may appear. Scored on the text after the Relevant fact: line.| Condition | 8 facts | 48 facts | Test |
|---|---|---|---|
| Clue alone (perfect picker) | 0.80–0.83 | – | 41 |
| Whole profile as text, plain decoder | 0.53–0.58 | 0.32–0.35 | 31, 41 |
| 8B text rater, best top k | 0.60 | 0.47 | 38b, 41 |
| 27B text rater ("wrong" wording), best top k | 0.68 | 0.53 | 41 |
| Block rater (16 tokens, LoRA), top 1 / top 4 | 0.44 | 0.30 | 43 |
| Rater | Top 2 of 8 | First of 48 | Top 8 of 48 |
|---|---|---|---|
| Plain decoder on the block, "change" wording | 0.46 | – | 0.38 |
| Block rater, 90 min int8 training | 0.60 | 0.09 | 0.55 |
| 8B text rater (the block rater's teacher) | 0.75 | 0.16 | 0.72 |
| 27B text rater, "wrong" wording | 0.84 | 0.35 | 0.82 |
The "wrong" wording: "Could a typical reply to this request be wrong, unsafe or unsuitable for this user because of the fact? Answer Yes or No." The score is the Yes/No logit difference.
| Test | Idea | Result |
|---|---|---|
| 17–22, 26 | Learned map (request × fact embedding) | Good on topical types (flying, no_car). Fails health and toddler. 2.7× more pairs: flat |
| 30 | Write-time "standing" score, request-independent | Hand-written category lists fix health at 8–16 facts, but only for what the list names. Label-free scores miss health |
| 32 | The 8B quotes which facts matter | False: quotes the clue in 49% at 8 facts, 22% at 48 |
| 35b, 35c | Rate each fact alone with a yes/no, keep the top k | True: beats the map and the whole profile. Wording matters per type |
| 36 | Distil the rating into an embedding scorer | False: below plain cosine on held-out types |
| 37, 38, 38b | Attention as the selector; rate all facts in one pass | False as a substitute: rates by topic in a crowd. Attention + rating: top 8 of 48 at 0.48 acts |
| 39 | Shortlist, then think or compare | +2 points at 5× the cost. Comparing in a group loses health |
| 40 | LoRA rater, listwise, hard labels | False: learns the training types; health falls to 0 at 192 facts |
| 41 | 27B rates each fact as text | True, the biggest gain. Lifts every type. An 8B shortlist re-rated by the 27B keeps most of it at 25–33% of the cost |
| 43 | Rate from the 16-token block: plain decoder; draft-then-judge; LoRA distilled from the 8B text rater | Picking improves but the student is capped by its teacher. Answers gain 2–6 points |
| 43 | Abstain (skip memory) when the top score is low | False: AUC 0.51–0.61 (8B), 0.59–0.75 (27B) |
| Test | Idea | Result |
|---|---|---|
| 19, 23, 27, 29 | Restate the relevant fact first, then answer; blocks sorted best-first; trained with distractors | Became the current reader |
| 31 | No picker: whole profile as text, reader trained to restate | The plain decoder with the whole profile beat the picker of that time (0.58 vs 0.39) |
| 33 | Self-distillation: the fact-only decoder teaches the whole-profile one | False: it learned the teacher's style |
| 34 | Token weights (learn only the tokens the fact changes) | No gain |
| 44 | GRPO on the reader | Stopped at step 19, no signal yet |
gather − logsumexp instead of a full log-softmax. About 1.8 min per step.| Steps | Reward, clue shown (acts) | Reward, clue not shown | Groups with any spread |
|---|---|---|---|
| 1–10 | 0.28 | 0.89 | 3.1 / 8 |
| 11–19 | 0.29 | 0.87 | 3.2 / 8 |
lora_grpo_s10.pt, not yet evaluated.Ranked by expected value per hour.
This is the cheapest test of whether the teacher cap is the whole story. If it passes, the 27B's judgement survives distillation onto 16-token blocks, and inference still needs only one 8B.
poc_rate27train.py --requests 1000, about 25k pairs, giving rater_train27.json).poc_tokrater.py --data rater_train27.json --minutes 45 --out lora_tokrater27.pt.poc_tok.py rate --lora lora_tokrater27.pt --raters tokL --tag 27 --wordings change.poc_tok.py answer --tables tokL27_change --conds "top+1+from+8,top+1+from+48,top+2+from+8,top+4+from+48".Promotion bar: the clue ranked first of 48 ≥ 0.20, and top 1 of 8 acts ≥ 0.50.
Relevant fact: line restates the clue, even if the answer doesn't act on it.Relevant fact: none note when the clue is absent, to penalise following a wrong pick.lora_grpo_s10.pt to rule out damage.Test 30 showed that an always-on set of "facts that matter whatever the topic" fixes health. But its scores came from hand-written lists, and the label-free scores failed. The untried version asks a model once per fact, at write time, how broadly the fact matters. The top few stay in context, and the per-request rating fills the rest. On the token path, the 8B reads the block. No training is needed.
The block rater already has the shape of a "System-1" judge: one forward pass, with the Yes/No logits as the score. A smaller decision model would be faster, not better, unless it is trained on better labels. If check 4c passes, a ~400M bidirectional cross-encoder trained on the 27B labels is worth a look. It reads text, so it leaves the token path.
torch._weight_int8pack_mm in a custom autograd function, so a LoRA still trains) is capped at about 15 GB. Typical times on 106 rows: rating 15–36 min; an answer run 24–33 min; 90 min of rater training is 218 steps.torch.mps.empty_cache()..npz access. z["v"] re-reads the whole array on every access. Read it once.--enable-lora crashed on the build used and needed an in-memory patch.| File | Role |
|---|---|
experiments/AGENTMEM_HYPOTHESES.md |
every test 1–44 with full tables |
experiments/REPORT_2026-11-24_token_path.md |
the internal version of this report, with run commands |
experiments/poc_tok.py |
rate / answer / dry on the token path |
experiments/poc_tokrater.py |
train the block rater |
experiments/poc_grpo.py |
the GRPO pilot |
experiments/poc_rate27train.py |
27B teacher data for check 4c |
experiments/poc_clue.py |
benchmark and rubrics |
experiments/q8.py |
int8 decoder loader |
work/runs/poc/synth.json |
the benchmark: 252 pairs with rubrics |
work/runs/agentmem/lora_lsort.pt |
the current reader |
work/runs/agentmem/lora_grpo_s10.pt |
GRPO step 10, not evaluated |
This work was done mostly by AI, under human direction. Read the results with that in mind.
| Part | Who did it |
|---|---|
| Goals, constraints, which ideas to pursue, what to publish | the author |
| Experiment design, most of the code, running the experiments, analysis | Claude (Anthropic), working as a coding agent in Claude Code, directed by the author |
| Some routine code, including this blog's site generator | a local Qwen model, given a written spec, with Claude checking the output |
| This report and post | written by Claude from the experiment logs, reviewed by the author before publishing |
| Benchmark clue chats | generated by an LLM and checked by regex; filler chats come from Memorilla's demo data |
| Benchmark questions and rubrics | fixed config and regular expressions written during the AI-assisted sessions; no model judges answers at eval time |
| Rater training labels and teacher answers | generated by the 8B and 27B models (that is the method, not a shortcut) |
The models under test (Qwen3-8B, Qwen3-Embedding-4B, a 27B Qwen-family model, and the Memorilla core) are research subjects, not authors.