Qwen3.5-0.8B-NestedMemory-v5 (memory at layers 10 + 18)

One unified model: Qwen3.5-0.8B (frozen) + two NestedMemoryLayers injected after decoder layers 10 and 18. Both write facts into their own weights while you chat and read them back later; all control is learned neural gates (no RAG). Controls (write / consolidate / forget / reset) apply to both layers together.

v5 fixes v4's main problem: memory no longer breaks normal conversation.

Full evaluation (same tests as v4; "wiped" = same model, memory reset → what it can answer without memory):

Chat, then come back (40 conversations: tell a fact → 3-7 turns on other topics → ask again)

v4 v5
general-knowledge answers correct with memory loaded 71% (original Qwen 92%) 97% (original Qwen 92%)
remembered value leaks into unrelated answers 17% 0.6%
fact recalled when asked midway 67% 71%
fact recalled when coming back at the end 60% 70% (wiped 0%)
same, one continuous chat (fact also in context) 73% / general 67% 73% / general 93% (base 93%)

The v4 failure คำว่าแมวในภาษาอังกฤษคืออะไร → คำว่า ปลาทูครับ is gone: v5 answers cat, gives normal long answers to small talk, and still recalls ชื่อปลาทูครับ when asked about the cat. Remaining errors are near-miss copies (ลูกชิ้น → ลูกเล่น).

OOD — sentence patterns never used in training (600 items)

type v4_atlas_wide v5 v5 after 3 other sessions wiped
odd string 82% 82% 77% 0%
pet name (real word) 60% 73% 62% 0%
foreign name 32% 57% 44% 0%
name, new pattern 51% 56% 62% 0%
number 63% 59% 47% 0%
province 30% 28% 33% 0%
all 48.2% 58.0% 0%

Real life-dataset, short protocol (val, 222 questions)

all wiped name occupation "never told"
v4_atlas_wide 59.9% 2.3% 61% 91% 100%
v5 55.9% 2.3% 66% 84% 90%

Full life simulation (19 unseen lives, 90 days, ~30 sessions)

all wiped name occupation
v4_atlas_wide 8.2% 5.9% 0% 0%
v5 9.4% 5.9% 16% 37%

First version with any name/occupation recall after a whole simulated life — still far from solved.

File

unified_nested_L18_v5_l10_blank.pt — full state dict (Qwen + memory at L10 + memory at L18, memory blank), best held-out checkpoint (step 2000 of a 5000-step run; training stopped at ~step 2300 when the cloud spend limit was reached).

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("v5_l10"))   # mem_extra_layers=(10,)
w = QwenMemoryWrapper(cfg=cfg, memory_type="nested")
w.model.load_state_dict(torch.load("unified_nested_L18_v5_l10_blank.pt"), strict=False)
w.memorize_text("หมาที่บ้านผมชื่อเจ้าลูกชิ้น")
w.end_session(); w.memory.forget(days=1)
print(w.generate("หมาที่บ้านผมชื่ออะไร", update_memory=False))
print(w.generate("เมืองหลวงของญี่ปุ่นคือเมืองอะไร", update_memory=False))  # normal answer, no leak

Thai tokenizer warning (newer transformers, e.g. 5.15): AutoTokenizer for Qwen3.5 may split Thai text differently from Qwen's own tokenizer.json (17 vs 9 tokens for the same sentence). The model then answers Thai badly (even plain Qwen without memory), while English looks fine. Model/qwen_memory.py now has load_tokenizer(), which detects this and falls back to PreTrainedTokenizerFast(tokenizer_file=tokenizer.json). If you load the tokenizer yourself, do the same.

What changed from v4

  1. Memory at a second depth (layer 10), warm-started from v4_atlas (layer-18 memory), extra layer fresh.
  2. Normal-chat preservation: 40% of training episodes ask general / small-talk questions while personal memory is loaded; the answer must match the ORIGINAL Qwen's full answer (CE + full-answer KL), read gates closed, and an unlikelihood penalty if a remembered value starts the answer. Also "ask the memory, then something else" episodes where the memory state carries on.
  3. Checkpoint selection includes a chat-then-come-back check (recall + general accuracy vs base + leak).

All phase-B experiments (same data/recipe, best in-training check)

run memory score come-back recall midway general (base 0.89) leak random-value copy now/after 3 sessions synthetic now/after
v5 (L10+18) 2 layers 0.710 0.83 0.90 0.94 0 0.55 / 0.30 0.95 / 0.95
v4.1 + LoRA r16 (layers 19-23) L18, 512 0.603 0.50 0.40 0.89 0 0.55 / 0.45 0.95 / 0.95
v4.1 L18, 512 0.593 0.42 0.50 0.97 0 0.55 / 0.40 0.85 / 0.90
v5 3 layers (L6+12+18) 3 layers 0.590 0.50 0.50 0.97 0 0.25 / 0.40 0.90 / 0.95
v4.1 + dense recall loss L18, 512 0.550 0.33 0.50 0.97 0 0.60 / 0.20 1.00 / 0.55

(20 items per memory check, 12 conversations per chat check → ±10-15 points noise. The 3-layer run only reached step 1000 before the stop.) Logs: results/train_log_*.json.

Findings: the recipe fix alone (v4.1) already restores normal chat (general ≈ base, leak 0) but lowers come-back recall; a second memory layer at depth 10 recovers and exceeds recall; LoRA on later layers gave little; dense recall loss helps immediate copying but hurts retention across sessions.

RL (GRPO) experiment — did not improve the model (documented, not published)

GRPO on top of v5 (code code/train_rl.py, plan code/RL_PLAN.md): tell facts → one prompt (memory / never-told / general / small talk) → 8 sampled answers → programmatic rewards (exact recall, correct "never told", no leak, no repetition) → group-relative policy gradient, with KL to the original Qwen on general prompts and KL to the frozen v5 on every prompt.

  • Round 1 (no v5 anchor, −0.7 for "never told" on memory questions): "never told" accuracy collapsed to 0 within 500 steps. Causes found: some "never told" questions asked about a fact that was told (in other words), and groups where all answers were correct gave no signal, so only the penalty was learned. Fixed for round 2.
  • Round 2 (fixed labels, 30% never-told prompts, softer penalty, KL to v5 β_ref 0.1 / 0.03), checks every 250 steps:
v5 (start) RL β_ref 0.1, step 750 RL β_ref 0.03, step 750
"never told" answered correctly (strict label) 38% 75% 75%
fact recalled when coming back (12 conv.) 83% 50% 50%
fact recalled midway 90% 60% 50%
general knowledge (base 89%) 94% 97% 97%
leak 0% 0% 0%

RL taught the model to say "you never told me" correctly, but it traded away recall of facts that were told, so no RL checkpoint beat v5 on the combined score and none is published. Runs were stopped at step ~800/1500. Next idea: a reward that only grants the "never told" bonus when the memory read gate is near zero (ties the behaviour to the memory signal instead of the question form), or DPO pairs built from v5's own correct/incorrect answers. Logs: results/train_log_v5_l10_rl_{c,d}.json.

Still unsolved

  • full 90-day / ~30-session life simulation: better (name 16%, occupation 37%) but life-event questions ~0%
  • English-only tells; Thai Wikipedia paraphrase QA (~0%)
  • "never told" is under-used (38% with strict labels) and long values can loop — RL fixed the first but cost recall (see above)

Previous: v4 · v3 · v2

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Jommarn/Qwen3.5-0.8B-NestedMemory-v5

Finetuned
(1,065)
this model

Datasets used to train Jommarn/Qwen3.5-0.8B-NestedMemory-v5