Qwen3.5-0.8B-NestedMemory-L18-v3
One unified model: Qwen3.5-0.8B with a NestedMemoryLayer injected after decoder layer 18. While you chat, the layer writes facts into its own weights (test-time learning, Titans/Atlas-style) and reads them back when you ask, with learned neural gates only (no RAG, no retrieval code). Qwen's own weights are frozen.
v3 is the first version whose memory actually retrieves. v2 recalled 0% of newly told names.
Held-out recall (during training)
40 episodes with random entities never seen in training (syllable-built names, pets, provinces, ages, ...), asked in a new chat with no history. Answer must contain the exact entity.
| variant | step | told → ask now | several messages + distractors + consolidation + 0-14 day gap | memory wiped | "never told" |
|---|---|---|---|---|---|
| v3_atlas (recommended) | 2250 | 83.9% | 87.5% | 0% | 66.7% |
| v3 | 1500 | 77.4% | 72.5% | 0% | 66.7% |
"memory wiped" = same model, same questions, memory reset → proves answers come from memory, not guessing.
Example (unseen name): told ผมชื่อปอศรี ..., new chat ผมชื่ออะไรครับ → คุณชื่อปอศรีครับ.
Training curve (v3_atlas, told→ask / with distractors): step 375 16%/0% → 750 39%/5% → 1125 68%/63% → 1500 71%/70% → 1875 87%/80% → 2250 84%/88%.
Training stopped at step ~2400/3000 (compute account ran out); the best checkpoint by held-out recall is published.
What changed from v2
- Shifted keys (
mem_shift_key): memory pairs arekey(token t-1) → value(token t), so a query at...ชื่อrecalls what followedชื่อwhen it was told. v2 used key and value from the same token, which cannot retrieve anything new (toy test: 6% vs 32% after 400 steps). - Residual-relative injection (
mem_res_rel): memory output scaled to the residual-stream RMS. - Read loss: the raw memory read at every answer position, decoded by Qwen's own final norm + lm_head, must predict the next answer token.
- Random entities every step so answers cannot be memorised from training data.
- Curriculum: told→ask now → several messages + fillers + consolidation + time gap → mixed with life-dataset episodes (random persona names).
Files
| file | variant |
|---|---|
unified_nested_L18_v3_atlas_blank.pt |
v3_atlas: shift_key + Atlas (polynomial features 24, Omega window 16, Muon), inner_steps 1 |
unified_nested_L18_v3_blank.pt |
v3: shift_key, Titans-style delta rule, inner_steps 4 |
Each is a full state_dict (Qwen + memory layer, memory blank). Code in code/ (train_v3.py = trainer).
import torch
from config import ProjectConfig
from Model.qwen_memory import QwenMemoryWrapper
from train_nested import variant_options
cfg = ProjectConfig(dtype=torch.bfloat16, **variant_options("v3_atlas"))
w = QwenMemoryWrapper(cfg=cfg, memory_type="nested")
w.model.load_state_dict(torch.load("unified_nested_L18_v3_atlas_blank.pt"), strict=False)
w.memorize_text("สวัสดีครับ ผมชื่อปอศรี ผมทำงานเป็นเภสัชกร") # memory writes itself
w.end_session() # consolidate -> long-term slots
w.memory.forget(days=3) # time passes
print(w.generate("ผมชื่ออะไรครับ", update_memory=False))
Limitations
- Works within one session / a few days; does NOT yet survive a long multi-session life (see below).
- "Never told" detection is only ~67%; the model sometimes invents an answer.
- Thai only, 0.8B model, one memory layer.
Evaluation on the real life dataset (unseen val/test lives)
Short protocol (val, 10 lives, 222 questions): per probe, fresh memory ← intro with a random name/occupation + the life's evidence turns + 2 distractor turns, consolidate, ask in a new chat.
| variant | all (memory) | all (wiped) | name | occupation | "never told" |
|---|---|---|---|---|---|
| v2 base (previous) | 5.1% | 2.3% | 0/132 | 0/132 | 15/19 |
| v3 | 18.0% | 1.8% | 20/74 (27%) | 15/74 (20%) | 5/10 |
| v3_atlas | 40.5% | 1.8% | 27/74 (36%) | 50/74 (68%) | 8/10 |
Event questions (episode detail, multi-hop, temporal, single facts from the life story) are still mostly wrong (0-21%): those turns are long and dated; training used mostly short facts.
Full life simulation (val+test, 19 lives): the whole 90-day life is fed session by session (~30 sessions, Ebbinghaus forgetting between them), the name is told only in session 1, questions asked at the end.
| variant | all (memory) | all (wiped) | name | occupation |
|---|---|---|---|---|
| v3 | 7.1% | 5.9% | 0% | 0% |
| v3_atlas | 7.6% | 5.9% | 0% | 5.3% |
Not solved yet: long-horizon memory. The model now answers in the copy-from-memory form
(คุณชื่อ ___ครับ) but after ~30 later sessions the fast memory has been overwritten and the long-term slots
(consolidation) were not trained over many sessions, so it fills the blank with the wrong token.
Next: multi-session training with interference so consolidation into slots is learned, and gating writes so
repeated chit-chat does not overwrite stored facts.