Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -11,42 +11,52 @@ tags:
|
|
| 11 |
- sequence-modeling
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# Do Transformers Need Three Projections? —
|
| 15 |
|
| 16 |
-
Reference checkpoints
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## What's included
|
| 27 |
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
**Synthetic sequence tasks** (single Transformer encoder, token accuracy):
|
| 31 |
|
| 32 |
-
|
|
| 33 |
|---|---|---|
|
| 34 |
-
|
|
| 35 |
-
|
|
| 36 |
-
|
|
| 37 |
-
|
|
| 38 |
-
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
**Vision classification** (ViT trained from scratch, top-1 accuracy):
|
| 41 |
|
| 42 |
-
|
|
| 43 |
|---|---|---|
|
| 44 |
-
|
|
| 45 |
-
|
|
| 46 |
-
|
|
| 47 |
-
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
## Usage
|
| 52 |
|
|
@@ -63,7 +73,7 @@ from huggingface_hub import hf_hub_download
|
|
| 63 |
|
| 64 |
REPO = "BrainChip-AI/do-transformers-need-3-projections"
|
| 65 |
|
| 66 |
-
# --- synthetic task model ---
|
| 67 |
from synthetic_tasks import Encoder, ModelCfg
|
| 68 |
path = hf_hub_download(REPO, "checkpoints/synthetic_reverse_qkv_kv.pt")
|
| 69 |
ckpt = torch.load(path, map_location="cpu")
|
|
|
|
| 11 |
- sequence-modeling
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Do Transformers Need Three Projections? — checkpoints
|
| 15 |
|
| 16 |
+
Reference checkpoints from the ICML 2026 paper *"Do Transformers Need Three Projections? A
|
| 17 |
+
Systematic Study of QKV Variants"* (Kayyam, Madan Gopal, Lewis; BrainChip Inc.). This release
|
| 18 |
+
pairs the standard **QKV baseline** with the paper's headline **Q≠K=V** variant so the two can be
|
| 19 |
+
compared directly on matched architectures.
|
| 20 |
|
| 21 |
+
- **QKV** — standard attention with separate query, key, and value projections (baseline).
|
| 22 |
+
- **Q≠K=V** — separate query, **shared key and value** (`V = K`). Only **K** is cached during
|
| 23 |
+
autoregressive generation → **50% KV-cache reduction**, while attention stays asymmetric
|
| 24 |
+
(unlike the symmetric `Q=K` variants).
|
| 25 |
+
|
| 26 |
+
The point of the pairing: Q≠K=V matches the QKV baseline in accuracy at half the KV cache. The
|
| 27 |
+
full study (all six projection-sharing variants) is in the
|
| 28 |
+
[code repository](https://github.com/Brainchip-Inc/Do-Transformers-Need-3-Projections).
|
| 29 |
|
| 30 |
## What's included
|
| 31 |
|
| 32 |
+
18 trained-from-scratch checkpoints — QKV (`*_qkv.pt`) and Q≠K=V (`*_qkv_kv.pt`) for each task.
|
| 33 |
+
Each is a dict: `{task, variant, model, config, test_accuracy, model_state_dict}`.
|
| 34 |
|
| 35 |
**Synthetic sequence tasks** (single Transformer encoder, token accuracy):
|
| 36 |
|
| 37 |
+
| Task | QKV (`*_qkv.pt`) | Q≠K=V (`*_qkv_kv.pt`) |
|
| 38 |
|---|---|---|
|
| 39 |
+
| REVERSE | 1.000 | 1.000 |
|
| 40 |
+
| SORT | 0.998 | 0.996 |
|
| 41 |
+
| SUB | 1.000 | 1.000 |
|
| 42 |
+
| SWAP | 1.000 | 1.000 |
|
| 43 |
+
| COPY | 1.000 | 1.000 |
|
| 44 |
+
|
| 45 |
+
Files: `checkpoints/synthetic_<task>_qkv.pt` and `checkpoints/synthetic_<task>_qkv_kv.pt`.
|
| 46 |
|
| 47 |
**Vision classification** (ViT trained from scratch, top-1 accuracy):
|
| 48 |
|
| 49 |
+
| Dataset | QKV (`*_qkv.pt`) | Q≠K=V (`*_qkv_kv.pt`) |
|
| 50 |
|---|---|---|
|
| 51 |
+
| MNIST | 0.981 | 0.978 |
|
| 52 |
+
| FashionMNIST | 0.887 | 0.882 |
|
| 53 |
+
| CIFAR-10 | 0.696 | 0.698 |
|
| 54 |
+
| CIFAR-100 | 0.437 | 0.445 |
|
| 55 |
+
|
| 56 |
+
Files: `checkpoints/vision_<dataset>_qkv.pt` and `checkpoints/vision_<dataset>_qkv_kv.pt`.
|
| 57 |
|
| 58 |
+
Across every task the two variants are within ~0.005 of each other — Q≠K=V matches the QKV
|
| 59 |
+
baseline while halving the KV cache.
|
| 60 |
|
| 61 |
## Usage
|
| 62 |
|
|
|
|
| 73 |
|
| 74 |
REPO = "BrainChip-AI/do-transformers-need-3-projections"
|
| 75 |
|
| 76 |
+
# --- synthetic task model (swap _qkv <-> _qkv_kv for baseline vs Q!=K=V) ---
|
| 77 |
from synthetic_tasks import Encoder, ModelCfg
|
| 78 |
path = hf_hub_download(REPO, "checkpoints/synthetic_reverse_qkv_kv.pt")
|
| 79 |
ckpt = torch.load(path, map_location="cpu")
|