Sync model card with the updated project README
Browse files
README.md
CHANGED
|
@@ -10,36 +10,37 @@ tags:
|
|
| 10 |
|
| 11 |
# MemOnce
|
| 12 |
|
| 13 |
-
**
|
| 14 |
|
| 15 |
This repository hosts the **post-training checkpoint** of MemOnce on a frozen Qwen3.5-4B
|
| 16 |
-
backbone. It contains only the trained memory modules (~
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
- Project page: https://clare-nie.github.io/MemOnce/
|
| 20 |
- Paper: *MemOnce: A Scalable Memory Architecture for Large Language Models* (2026)
|
|
|
|
| 21 |
|
| 22 |
## Method
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
context length and depth
|
| 27 |
-
bounded state that loses fine-grained detail.
|
| 28 |
|
| 29 |
-
|
| 30 |
-
designs:
|
| 31 |
|
| 32 |
-
1. **Memory encoder-decoder.**
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
dimension.
|
| 37 |
2. **Memory sparse attention.** For each new input, the top-`K` relevant blocks are
|
| 38 |
retrieved **once**, and that routing decision is shared by every attention layer and
|
| 39 |
every decoding step. The persistent bank may grow and be offloaded to CPU or SSD, while
|
| 40 |
the GPU-resident active state stays constant.
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
```
|
| 45 |
G_t = g_θ(x_{1:t-1}) # write: encode history once
|
|
@@ -49,58 +50,75 @@ C_t = u_θ(M_t) # read: decode selected blocks into KV
|
|
| 49 |
|
| 50 |
Concretely, in this checkpoint:
|
| 51 |
|
| 52 |
-
- **Write** —
|
| 53 |
-
memory block by the memory LoRA adapter (`r = 128`).
|
| 54 |
-
- **Index** — each block is described by a learned 1024-d
|
| 55 |
-
|
| 56 |
- **Read** — the selected blocks are decoded into per-layer KV caches; generation runs with
|
| 57 |
-
the adapter
|
| 58 |
|
| 59 |
## Key conclusions
|
| 60 |
|
| 61 |
- **The active state stops growing with context.** What stays on the GPU is a fixed memory
|
| 62 |
-
budget, not a KV cache proportional to the number of tokens seen.
|
| 63 |
-
- **Depth no longer multiplies the cache.**
|
| 64 |
-
the persistent footprint
|
| 65 |
- **Retrieval happens once, not per layer.** A single routing decision is reused across all
|
| 66 |
layers and decoding steps instead of being recomputed for each of them.
|
| 67 |
-
- **
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
- **One architecture, two settings.** MemOnce works as a foundation model trained from
|
| 71 |
-
scratch
|
| 72 |
is the latter.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
## Usage
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
```bash
|
|
|
|
| 79 |
hf download Qwen/Qwen3.5-4B --local-dir Qwen3.5-4B
|
| 80 |
-
hf download ClareNie/MemOnce --local-dir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
python inference.py --base-model
|
| 84 |
-
python inference.py --base-model ../Qwen3.5-4B --checkpoint ../memonce-ckpt --TEXT
|
| 85 |
```
|
| 86 |
|
| 87 |
-
`--self-test` verifies that
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
## Files
|
| 93 |
|
| 94 |
| File | Size | Contents |
|
| 95 |
|---|---|---|
|
| 96 |
-
| `model.safetensors` | 264 MB |
|
| 97 |
-
| `config.json` |
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
```
|
| 102 |
f5588a7527bc748f686e26f1a76854ca88bd0061f9733505b8cd23703ebfc927 model.safetensors
|
| 103 |
-
|
|
|
|
| 104 |
```
|
| 105 |
|
| 106 |
## Citation
|
|
|
|
| 10 |
|
| 11 |
# MemOnce
|
| 12 |
|
| 13 |
+
**A Scalable Memory Architecture for Large Language Models**
|
| 14 |
|
| 15 |
This repository hosts the **post-training checkpoint** of MemOnce on a frozen Qwen3.5-4B
|
| 16 |
+
backbone. It contains only the trained memory modules (~71M parameters, 264 MB): the LoRA
|
| 17 |
+
write adapter, the per-layer KV readout projections and the `mem_to_emb` index projection.
|
| 18 |
+
The backbone itself is not included.
|
| 19 |
|
| 20 |
- Project page: https://clare-nie.github.io/MemOnce/
|
| 21 |
- Paper: *MemOnce: A Scalable Memory Architecture for Large Language Models* (2026)
|
| 22 |
+
- Code, training scripts and evaluation: linked from the project page.
|
| 23 |
|
| 24 |
## Method
|
| 25 |
|
| 26 |
+
MemOnce is a foundation architecture for long-horizon continual language modeling.
|
| 27 |
+
A Transformer reuses its past by accumulating a per-layer KV cache for every token, so
|
| 28 |
+
memory grows with both context length and depth; linear/recurrent models avoid that growth
|
| 29 |
+
but compress history into a bounded state that loses fine-grained detail.
|
| 30 |
|
| 31 |
+
The principle is simple: **cache a single compact global memory, and retrieve it only once.**
|
| 32 |
+
Two coupled designs implement it:
|
| 33 |
|
| 34 |
+
1. **Memory encoder-decoder.** Only a trailing `1/r` subset of *final-layer* hidden states
|
| 35 |
+
is cached as compact memory blocks, and the selected blocks are decoded back into
|
| 36 |
+
layer-specific KV caches on demand. The persistent cache therefore loses the depth
|
| 37 |
+
factor entirely and is compressed along time (`L × r` depth-time compression).
|
|
|
|
| 38 |
2. **Memory sparse attention.** For each new input, the top-`K` relevant blocks are
|
| 39 |
retrieved **once**, and that routing decision is shared by every attention layer and
|
| 40 |
every decoding step. The persistent bank may grow and be offloaded to CPU or SSD, while
|
| 41 |
the GPU-resident active state stays constant.
|
| 42 |
|
| 43 |
+
Write / index / read are factorized as
|
| 44 |
|
| 45 |
```
|
| 46 |
G_t = g_θ(x_{1:t-1}) # write: encode history once
|
|
|
|
| 50 |
|
| 51 |
Concretely, in this checkpoint:
|
| 52 |
|
| 53 |
+
- **Write** — turns longer than 4,096 tokens are split into 4,096-token segments, and each
|
| 54 |
+
segment is written once as a 64-token memory block by the memory LoRA adapter (`r = 128`).
|
| 55 |
+
- **Index** — each block is described by a learned 1024-d `mem_to_emb` projection and
|
| 56 |
+
selected by a single cosine pass with top-`K = 64`.
|
| 57 |
- **Read** — the selected blocks are decoded into per-layer KV caches; generation runs with
|
| 58 |
+
the adapter disabled, so history enters strictly as KV caches.
|
| 59 |
|
| 60 |
## Key conclusions
|
| 61 |
|
| 62 |
- **The active state stops growing with context.** What stays on the GPU is a fixed memory
|
| 63 |
+
budget, not a KV cache proportional to the number of tokens seen; prefill scales linearly.
|
| 64 |
+
- **Depth no longer multiplies the cache.** Caching only trailing final-layer states makes
|
| 65 |
+
the persistent footprint independent of the number of layers.
|
| 66 |
- **Retrieval happens once, not per layer.** A single routing decision is reused across all
|
| 67 |
layers and decoding steps instead of being recomputed for each of them.
|
| 68 |
+
- **The memory bank is offloadable.** Storage can grow on CPU/SSD without changing the
|
| 69 |
+
active GPU budget or the decoding path.
|
| 70 |
+
- **General capability is preserved.** The backbone stays frozen and generation uses only
|
| 71 |
+
decoded KV caches, so long-term memory is added without catastrophic forgetting.
|
| 72 |
- **One architecture, two settings.** MemOnce works as a foundation model trained from
|
| 73 |
+
scratch and as a post-training adaptation of a frozen Qwen3.5 backbone — this checkpoint
|
| 74 |
is the latter.
|
| 75 |
+
- **Reusable index descriptors.** The learned 1024-d memory descriptors transfer zero-shot
|
| 76 |
+
to downstream retrieval and context reranking without task-specific fine-tuning.
|
| 77 |
+
|
| 78 |
+
Detailed results and figures are on the [project page](https://clare-nie.github.io/MemOnce/).
|
| 79 |
|
| 80 |
## Usage
|
| 81 |
|
| 82 |
+
Qwen3.5 post-training requires `transformers >= 5.0` (see `requirements/posttraining.txt`
|
| 83 |
+
in the code repository). Download the frozen backbone and this checkpoint, then run the
|
| 84 |
+
inference script from the code repository:
|
| 85 |
|
| 86 |
```bash
|
| 87 |
+
pip install -U huggingface_hub
|
| 88 |
hf download Qwen/Qwen3.5-4B --local-dir Qwen3.5-4B
|
| 89 |
+
hf download ClareNie/MemOnce --local-dir model
|
| 90 |
+
|
| 91 |
+
cd eval/post-training
|
| 92 |
+
export BASE=../../Qwen3.5-4B
|
| 93 |
+
export CKPT=../../model
|
| 94 |
+
|
| 95 |
+
# 1. Self-test (verifies every trained tensor is strictly consumed)
|
| 96 |
+
python inference.py --base-model "$BASE" --checkpoint "$CKPT" --self-test
|
| 97 |
|
| 98 |
+
# 2. Built-in multi-hop demo
|
| 99 |
+
python inference.py --base-model "$BASE" --checkpoint "$CKPT" --TEXT
|
|
|
|
| 100 |
```
|
| 101 |
|
| 102 |
+
`--self-test` verifies that all trained tensors are consumed by the loader before any
|
| 103 |
+
generation. For your own data, pass `--input my_data.jsonl --output generations.jsonl`;
|
| 104 |
+
each line is a `messages` list whose preceding turns are written into memory and whose last
|
| 105 |
+
user turn is the query. Other useful flags: `--max-new-tokens`, `--retrieve-blocks`,
|
| 106 |
+
`--attn-implementation [sdpa|flash_attention_2|eager]`.
|
| 107 |
|
| 108 |
## Files
|
| 109 |
|
| 110 |
| File | Size | Contents |
|
| 111 |
|---|---|---|
|
| 112 |
+
| `model.safetensors` | 264 MB | 100 trained tensors: LoRA write adapter (`r = 128`), per-layer KV readout projections, `mem_to_emb` |
|
| 113 |
+
| `config.json` | 554 B | Memory hyper-parameters: 64 memory tokens, top-`K = 64`, 1024-d descriptors, 4,096-token target length |
|
| 114 |
+
| `index.json` | 25 KB | Per-tensor manifest for `model.safetensors`: source SHA-256, names, dtypes, shapes, per-tensor SHA-256 |
|
| 115 |
|
| 116 |
+
SHA-256 checksums:
|
| 117 |
|
| 118 |
```
|
| 119 |
f5588a7527bc748f686e26f1a76854ca88bd0061f9733505b8cd23703ebfc927 model.safetensors
|
| 120 |
+
b2b56eb6680c2af7f4c1a5fbeef79d99a2ed9ea396ce46a6a8b0f745c047c1bf config.json
|
| 121 |
+
39c8bb893157513ba762fdca94586d1397a0a7b00a6e0f564233da762bc8f4bd index.json
|
| 122 |
```
|
| 123 |
|
| 124 |
## Citation
|