LaCT memory branch on frozen Qwen3-0.6B (synthetic dialogue recall) + selective-write code
Research checkpoint, 2026-11-22. This is the model on which turn-level selective writing was tested. It is trained and tested on a synthetic task; it is a mechanism check, not a benchmark model.
Contents
| path | what |
|---|---|
checkpoint/memory_weights.pt, checkpoint/memory_config.json |
the memory branches (the only trained weights; Qwen3-0.6B itself is unchanged) |
code/lact_qwen/ |
model code (memory branch, fast-weight update, selection, replay) |
code/scripts/train_memory.py, code/run_dialog.sh |
training |
code/scripts/make_synth.py |
data generator (train and test sets are reproducible from seeds) |
code/scripts/eval_select.py, code/scripts/audit_scores.py, code/turnsel.sh, code/h201_grid.sh |
selective writing / replay evaluation |
data/rc_t{16,32,64}_f8.jsonl |
the test dialogues used for the numbers below |
LACT_SELECTIVE_WRITE.md |
results and commands for the selective-write test |
Model
- Base:
Qwen/Qwen3-0.6B, frozen. Causal attention is limited to the last 2048 tokens (+ 4 sink tokens); anything older reaches the model only through the memory. - Memory: one LaCT branch in each of the 28 layers. A branch is a SwiGLU fast-weight network
f(x) = w1 (silu(w0 x) * (w2 x)), 4 heads x 512 dims. Its fast weights are the memory. It reads with q, writes (k, v) pairs with one gradient step per segment (Muon-normalised, with momentum), learned per-token write rates. The branch output is added before the attention output projection (pre_o_proj), scaled by a learned gate (init 0.1); the readout is the difference to the initial fast weights (delta_readout). - Layout flags:
--mem-heads 4 --mem-head-dim 512 --mem-chunk 2048 --mem-delta-readout --mem-gate-init 0.1 --mem-qkv-init attention --mem-qkv-act none --mem-inject pre_o_proj --mem-out-ref attention - Trainable parameters: the memory branches only (~1.06 GB file).
Data (synthetic, code/scripts/make_synth.py)
A dialogue is a list of turns. A turn is ~200 words of repeated filler ("The grass is green. The sky is blue. ...") and may carry one fact sentence such as "The budget for order V-544 is 64520 dollars." Entity ids and 5-digit values are random. 8 facts per dialogue; 30% of the facts are corrected later. After the dialogue, questions of three kinds are asked ("Question: What is the budget for order V-544?\nAnswer:"): retention (stated once, not in the last 2 turns), correction (newest value), recent (stated in the last 2 turns).
gen() { python scripts/make_synth.py --out data/$1.jsonl --n $2 --num-turns $3 --num-facts 8 --words-per-turn 200 --queries-per-category 4 --seed $4; }
gen v8f_train 10000 16 101 # training set: 10 000 dialogues of 16 turns (md5 6fdc8984a927589ad517805cee1e15d2)
for t in 16 32 64 128; do gen rc_t${t}_f8 100 $t 7; done # test sets (rc_t32_f8 md5 8584c60c8ef7c8a9685353f3758f3c55)
The training set (175 MB) is not uploaded; the command above regenerates it bit-identically.
Training recipe
LAYOUT="--mem-heads 4 --mem-head-dim 512 --mem-chunk 2048 --mem-delta-readout --mem-gate-init 0.1 --mem-qkv-init attention --mem-qkv-act none --mem-inject pre_o_proj --mem-out-ref attention"
NGPU=4 ACCUM=2 STEPS=1200 TRAIN=data/v8f_train.jsonl TEST=data/rc_t16_f8.jsonl LIMIT=100 \
INIT=new EXTRA="$LAYOUT" OUT=ckpt/dlg16_new bash run_dialog.sh
| setting | value |
|---|---|
| initialisation | fresh memory branches (INIT=new), no continuation pre-training |
| dialogues per optimizer step | 8 (4 GPUs x grad-accum 2); 1200 steps = 9600 dialogues, each seen once |
| loss | cross-entropy on the answer tokens only |
| write unit | one write per dialogue turn (--min-write-tokens 0, --max-segment 4096) |
| optimizer / lr | AdamW, 1e-3, 100 warm-up steps, cosine decay to 1e-4 (see train_memory.py) |
| attention | flex_attention window mask, gradient checkpointing, bf16 |
| seed | 1 |
| hardware / time | 4 x H20 (15 GB each), about 4.6 h |
| final training loss | ~0.002-0.004 |
Each dialogue must be seen at most once: with repeated dialogues the branch memorises them (0.94 on the 16 training dialogues, 0.00 on new ones in an earlier run).
Results of this checkpoint
Exact match under teacher forcing on facts stated outside the attention window (retention/beyond_window).
| test | writes on | writes off |
|---|---|---|
| 16 turns (training length) | 0.98 | 0.00 |
Selective writing at inference (only the K best-scored turns are written; 40 dialogues, 160 questions):
| policy | 32 turns K=4 | 32 turns K=8 | 64 turns K=4 | 64 turns K=8 |
|---|---|---|---|---|
| write every turn | 0.415 | 0.218 | ||
| random turns | 0.126 | 0.170 | 0.041 | 0.082 |
| memory q.k, layer 19 | 0.719 | 0.748 | 0.612 | 0.510 |
| attention mass (frozen base) | 0.689 | 0.696 | 0.633 | 0.531 |
| oracle turn | 0.763 | 0.741 | 0.728 | 0.680 |
Robins-style pseudo-rehearsal on top of attention selection (32 turns): K=8 0.696 -> 0.719 (question probes) -> 0.726 (question probes + key bank); K=16 0.563 -> 0.585. Small, consistent, within noise of 160 questions.
Caveats
- The model was trained on 16-turn dialogues only; at 32 / 64 turns the number of writes is 2-4x what it saw. Part of the gain of writing fewer turns may come from returning to the trained regime, not from selection.
- Selection is easy here: the filler is repeated text and the fact turn contains the entity id of the question.
- The question is known before writing; every question gets its own selection and its own memory.
- Layer 19 for
turn_qkwas found on this model (audit_scores.py); other models need their own audit.
Use
cd code
python scripts/eval_select.py --model Qwen/Qwen3-0.6B --window 2048 --sinks 4 --memory ../checkpoint \
--data ../data/rc_t32_f8.jsonl --limit 40 --select turn_attn --turn-k 4