BrainChipInc commited on
Commit
3fa24fb
·
verified ·
1 Parent(s): e621c7e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +33 -23
README.md CHANGED
@@ -11,42 +11,52 @@ tags:
11
  - sequence-modeling
12
  ---
13
 
14
- # Do Transformers Need Three Projections? — Q≠K=V checkpoints
15
 
16
- Reference checkpoints for the **Q≠K=V** attention variant (separate query, **shared key and
17
- value**) from the ICML 2026 paper *"Do Transformers Need Three Projections? A Systematic Study
18
- of QKV Variants"* (Kayyam, Madan Gopal, Lewis; BrainChip Inc.).
 
19
 
20
- Q≠K=V is the paper's **headline variant**: it removes the value projection and reuses the key as
21
- the value, so only **K** needs to be cached during autoregressive generation a **50% KV-cache
22
- reduction** while keeping attention asymmetric (unlike the symmetric Q=K variants). See the
23
- [paper / code repository](https://github.com/Brainchip-Inc/Do-Transformers-Need-3-Projections)
24
- for the full study across all six projection-sharing variants.
 
 
 
25
 
26
  ## What's included
27
 
28
- Nine trained-from-scratch Q≠K=V checkpoints (PyTorch `state_dict` + rebuild config + test accuracy):
 
29
 
30
  **Synthetic sequence tasks** (single Transformer encoder, token accuracy):
31
 
32
- | Checkpoint | Task | Accuracy |
33
  |---|---|---|
34
- | `checkpoints/synthetic_reverse_qkv_kv.pt` | REVERSE | 1.000 |
35
- | `checkpoints/synthetic_sort_qkv_kv.pt` | SORT | 0.996 |
36
- | `checkpoints/synthetic_sub_qkv_kv.pt` | SUB | 1.000 |
37
- | `checkpoints/synthetic_swap_qkv_kv.pt` | SWAP | 1.000 |
38
- | `checkpoints/synthetic_copy_qkv_kv.pt` | COPY | 1.000 |
 
 
39
 
40
  **Vision classification** (ViT trained from scratch, top-1 accuracy):
41
 
42
- | Checkpoint | Dataset | Accuracy |
43
  |---|---|---|
44
- | `checkpoints/vision_mnist_qkv_kv.pt` | MNIST | 0.978 |
45
- | `checkpoints/vision_fmnist_qkv_kv.pt` | FashionMNIST | 0.882 |
46
- | `checkpoints/vision_cifar10_qkv_kv.pt` | CIFAR-10 | 0.698 |
47
- | `checkpoints/vision_cifar100_qkv_kv.pt` | CIFAR-100 | 0.445 |
 
 
48
 
49
- Each checkpoint is a dict: `{task, variant, model, config, test_accuracy, model_state_dict}`.
 
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")