Gemma 3 270M Continual Memory (OnlineSlotDAM & Ternary-Spike Side-Memory)

Factored residual-stream side-memory adapters and 5-seed (0..4) evaluation artifacts for parser-free single-pass continual factual storage on frozen google/gemma-3-270m: 86.1%–86.7% unseen-paraphrase recall ([83.7–88.6%] per seed; 82.2% [79.1–84.4%] with 70%-silent signed ternary keys and sign-quantized error feedback), 85.9%–86.3% absolute recall after 16k streaming distractor tokens (99.8% relative retention), and 0.00020–0.00110 T4 TinyStories KL (with zero weight updates to the base Gemma weights).


Method & Honest Scope

In the GRACE / Larimar / MEMOIR / SERAC external side-memory lineage, OnlineSlotDAM keeps google/gemma-3-270m frozen and maintains a dynamic key-value table in code/online_slotdam.py:

  1. Subject key (S): A lightweight causal attention-pooling KeyNet (640 β†’ 320 dims, whitened layer-12 residuals at the last prompt token), trained via last-token multi-positive InfoNCE across 9 disjoint relations (600 synthetic names drawn from ~1.36 Γ— 10^13 2-syllable pairs with separate RNG seeds) plus a generic-prose margin (l_gen) β€” zero subject-span labels at train or inference time.
  2. Relation key (R): Un-trained final-layer residual (H[17], 640-dim) centered by a Bayesian online running mean (mu_r, worth +4.3 pts over static centering and +20.3 pts over uncentered RawH17, while learned RelNet overfit at 56.4%).
  3. Value (V), Read & Gate: Stores unit-norm unembedding U[tok_ids[0]] (first answer token only). Reads use cubic factored attention relu(SΒ·Ks)^3 * relu(RΒ·Kr) (beta=200), gated by raw subject familiarity fam >= thr_s0 and added to H[17] (alpha β‰ˆ 6%–10% of typical residual norm).
  4. Write & Background Habituation: Refractory (> 8 tokens) delta-rule overwrite on matched (tau_s_m, tau_r_m) slots, otherwise allocating a new slot unless bg_bank (2,048 in v1/calib_v1.safetensors; 4,096 in v2/calib_v2.safetensors) flags the key as generic prose.

Transparent caveats & negative findings:

  • Synthetic world + first-token scope: Recall (T1–T3) is evaluated on synthetic 240-person / 3-relation (city, job, pet) worlds storing and scoring only the first answer token (U[tok_ids[0]]), not multi-token spans or open benchmarks (CounterFact/zsRE/EasyEdit GRACE/WISE, planned next).
  • Why T4 KL β‰ˆ 0: Across 20,000 held-out TinyStories tokens, the familiarity gate stays closed (gate_open = 0.0 on seeds 0..3, 0.0001 [2/20,000 tokens] on seed 4). bg_bank prevents 0–2 generic slots per world from leaking; on seed 4, Ternary-Spike opens on the exact same 2 tokens (0.0001) as float, just with smaller logit shift (KL=0.00105 vs 0.00336/0.00498).
  • Spiking & compression framing: On T2-noise, Scalar-PESP (0.7433 / 0.7322) and Spike-PESP (0.7344 / 0.7389) match closely, showing distractor resistance comes from thresholded error integration + per-eval guard_mode, with Spike-PESP acting as per-coordinate sign-quantized error feedback. Likewise, "16Γ— smaller" (80 B vs 1,280 B) applies to 320-dim Ks key vectors only; each slot still stores float Kr0, V, and Res, and un-accelerated NumPy sparse key matching is 172×–593Γ— slower on CPU (65.6–225.2 ms vs 0.38 ms BLAS SGEMM).

Relation to Prior Work

Places directly alongside decoupled side-memory & fast-weight architectures: GRACE (discrete layer codebook + radius gate), Larimar (one-shot gradient-free external episodic memory + scope detector), MEMOIR (sparse top-k residual key + overlap gate), WISE (gated side memory), SERAC (scope-gated edit memory), kNN-LM (final-state non-parametric retrieval), Fast Weight Programmers (delta-rule updates), Titans (surprise-gated test-time writes, used in T3 at tau_surp=4.0), Modern Hopfield, Transformer-Patcher, ROME, FlyHash (Dasgupta et al., 2017), and Gemma 3.


Benchmark & Baseline Results (seeds 0..4, Gemma 3 270M MPS float32)

All thresholds were tuned strictly on VAL_SEED=200 (vehicle/drink/teacher) and frozen for test seeds 0..4 (city/job/pet, net_seed = seed % 3).

1. Outside Baselines vs. OnlineSlotDAM (results/baselines_gemma3-270m.json, 5 seeds)

Method Parser-Free? T1 held_free [min–max] T1 held_cons T2 over_new T3 abs (ret) T4 KL (gate_open) Toks/Q ms/Q
Base-ZeroShot Yes 0.0013 [0.001–0.002] 0.0849 β€” β€” 0.00000 (0.0%) 10.2 3.9 (batch=32)
In-Context (Clean Facts) Yes 0.0761 [0.041–0.095] 0.1015 0.2017 β€” 0.20855 (100%) 9,327 7.7 KV / 12.7 amort
In-Context (Full Stream) Yes 0.0789 [0.051–0.111] 0.1133 0.2167 β€” 0.55704 (100%, s0) 18,382 10.8 KV / 30.3 amort
RAG-BM25 (k=1) Yes 0.3434 [0.306–0.400] 0.4374 0.2450 0.2806 (81.9%) β€” 34.1 5.9 (batch=32)
RAG-BM25 (k=3, ungated) Yes 0.4290 [0.319–0.487] 0.6156 0.3606 0.3910 (91.7%) 0.27047 (100%) 83.6 11.3 (batch=32)
RAG-BM25-Gated (k=3) Yes 0.4290 [0.319–0.487] 0.6156 β€” β€” 0.00025 (0.06%) 83.6 11.3 (batch=32)
RAG-ExactName (oracle) No 0.6159 [0.533–0.710] 0.8474 0.4733 0.6159 (100.0%) 0.00000 (0.0%) 86.7 11.5 (batch=32)
Online-Delta (v1) Yes 0.8608 [0.837–0.881] 0.8400 0.7800 0.8589 (99.8%) 0.00070 (0.002%) ~10.5 β€”
Online-Delta (v2) Yes 0.8650 [0.838–0.886] 0.8500 0.7833 0.8631 (99.8%) 0.00110 (0.003%) 10.5 63.7 (stream=1)
Ternary-Spike Yes 0.8222 [0.791–0.844] 0.8109 0.7067 0.8185 (99.6%) 0.00020 (0.002%) 10.5 52.9 (stream=1)

(Gemma 3 270M has 512-token sliding-window attention on 15/18 layers, so 9.3k–18.4k in-context prompting drops to 7.6%–7.9%; even oracle RAG-ExactName trails OnlineSlotDAM by 24.9 pts on T1 and 31.0 pts on T2 due to filler/conflicting context.)

2. Internal Ablations (results/eval_v1.json, eval_v2.json, eval_relnet_ablation.json)

Arm T1 ident T1 held_free [min–max] T2 (new / old / untouch) T3 abs (ret, +bg) T4 KL (mean / max, gate_open s0..4)
Uncentered RawH17-Delta 0.717 0.658 0.789 / 0.062 / 0.625 0.658 (100%) 0.4806 / 1.3455
Learned RelNet-Delta (dropped) 0.700 0.564 0.660 / 0.094 / 0.541 0.563 (99.8%) 0.5105 / 1.3841
Ablation-NoOnline (v1, static mu_r) 0.900 0.8183 [0.778–0.846] 0.794 / 0.098 / 0.798 0.8179 (99.9%, +400) 0.00070 / 0.00371
Ablation-NoBgFilter (v1 / v2) 0.946 / 0.950 0.8609 / 0.8649 0.780 / 0.783 0.8591 / 0.8631 (+0) 0.5807 / 1.4115
Online-Delta (v1, bg_n=2048) 0.945 0.8608 [0.837–0.881] 0.780 / 0.146 / 0.846 0.8589 (99.8%, +432) 0.00070 / 0.00336 (0,0,0,0,1e-4)
Online-Delta (v2, bg_n=4096) 0.950 0.8650 [0.838–0.886] 0.783 / 0.147 / 0.851 0.8631 (99.8%, +853) 0.00110 / 0.00498 (5e-5,0,0,0,1e-4)

3. Error-Threshold & Ternary Key Variants (results/eval_spiking.json, fixed monotonic clock)

Arm Key (Ks) / Update T1 held_free [min–max] T2 1-shot (over_new) T2-noise (w/ guard_mode) Update Silence T3 abs (ret) T4 KL (mean / max, s4 gate)
Float-Delta float32 / Delta 0.8667 [0.838–0.890] 0.7856 0.7822 / 0.0367 / 0.9156 (no guard) 0.0% 0.8648 (99.8%) 0.00100 / 0.00498 (1e-4)
Scalar-PESP float32 / scalar thr 0.8207 [0.801–0.836] 0.7850 0.7433 / 0.7322 / 0.1167 72.8% (skip) 0.8173 (99.6%) 0.00100 / 0.00494 (1e-4)
Spike-PESP float32 / coord sign 0.8219 [0.806–0.836] 0.7283 0.7344 / 0.7389 / 0.0933 96.2% (coord) 0.8181 (99.5%) 0.00100 / 0.00494 (1e-4)
Ternary-Spike 70%-silent Ks / sign 0.8222 [0.791–0.844] 0.7067 0.7400 / 0.7111 / 0.0644 93.4% (coord) 0.8185 (99.6%) 0.00020 / 0.00105 (1e-4)
FlyHash-Bin 93.75%-silent {0,1} 0.6081 [0.554–0.655] 0.4656 0.6200 / 0.5178 / 0.1378 93.6% (coord) 0.6022 (99.0%) 0.00000 / 0.00000 (0.0)

4. Cross-Model Summary (Gemma 3 270M vs Gemma 3 1B-IT vs Qwen2.5-1.5B-Instruct)

Model Arm T1 held_free T2 over_new T2-noise (new / keep) T3 abs (ret) T4 KL (mean / max)
Gemma 3 270M Float-Delta / Ternary-Spike 0.867 / 0.822 0.786 / 0.707 0.740 / 0.711 (tert) 0.865 / 0.819 (99.8% / 99.6%) 0.00100 / 0.00020 (0.00105)
Gemma 3 1B-IT (ablation) Float-Delta / Spike / Ternary 0.696 / 0.673 / 0.573 0.604 / 0.565 / 0.503 0.584 / 0.523 (spike) 0.686 / 0.662 / 0.568 (~98.6%) 0.00030 / 0.00133–0.00149
Qwen2.5-1.5B-IT Float-Delta / Spike / Ternary 0.735 / 0.695 / 0.739 0.689 / 0.514 / 0.622 0.753 / 0.680 (tert) 0.723 / 0.685 / 0.724 (97.9%–98.5%) 0.00000 / 0.00000 (5/5)

Quick Start

import sys, torch
from huggingface_hub import snapshot_download
from transformers import AutoModelForCausalLM, AutoTokenizer

repo = snapshot_download("jordanrburger/gemma3-270m-continual-memory")
sys.path.insert(0, f"{repo}/code")
from online_slotdam import GemmaSlotMemory

device = "mps" if torch.backends.mps.is_available() else ("cuda" if torch.cuda.is_available() else "cpu")
tok = AutoTokenizer.from_pretrained("google/gemma-3-270m")
model = AutoModelForCausalLM.from_pretrained("google/gemma-3-270m", dtype=torch.float32).to(device).eval()

# profile="v1" (calib_v1, 2048 bg), "v2" (calib_v2, 4096 bg, max_bg_rate=0), or "ternary_spike"
mem = GemmaSlotMemory(model, tok, repo_dir=repo, seed=0, profile="ternary_spike", device=device)
mem.remember("The home city of Mara Velt is", " Tokyo")
print(mem.predict_next("Everyone knows that Mara Velt comes from"))
  • checkpoints/{k_attn_s0..2,calib_v1,calib_v2}.safetensors β€” KeyNet & calibration banks (calib_v2 adds 4,096-token v2 banks).
  • code/{online_slotdam,demo_gemma3}.py, config.json, results/{tuning_*,eval_*,baselines_gemma3-270m}.json.
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for jordanrburger/gemma3-270m-continual-memory

Finetuned
(167)
this model

Collection including jordanrburger/gemma3-270m-continual-memory

Papers for jordanrburger/gemma3-270m-continual-memory