deltas: curated case-study MEMIT deltas (eiffel, taj mahal cf21243, pentium ii cf6467) + card
Browse files- deltas/README.md +36 -63
- deltas/eiffel_paris_to_rome.npz +3 -0
- deltas/pentium_ii_cf6467.npz +3 -0
- deltas/taj_mahal_cf21243.npz +3 -0
deltas/README.md
CHANGED
|
@@ -1,78 +1,51 @@
|
|
| 1 |
# Curated case-study MEMIT deltas
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
gated, subject to the [Gemma Terms of Use](https://ai.google.dev/gemma/terms))
|
| 6 |
-
with [MEMIT](https://rome.baulab.info/) via the Interp_Gemma editing
|
| 7 |
-
primitives. Applying a delta to the base weights reconstructs the edited
|
| 8 |
-
model `M_e = base google/gemma-2-2b weights + delta`.
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
## Files
|
| 14 |
-
|
| 15 |
-
| Case | Subject → target (relation) | CounterFact `case_id` | File | Size | SHA-256 |
|
| 16 |
-
|---|---|---|---|---|---|
|
| 17 |
-
| Eiffel Tower Paris→Rome | *The Eiffel Tower* is located in the city of **Rome** (was Paris) | 0 | `eiffel_paris_to_rome/deltas.npz` | 679,480,828 B (~648 MiB) | `476e5fb6a4f660faf5472fbaf0a2eefb2c4bb58bf0dfbb5e0ad50e3230f5507c` |
|
| 18 |
-
| Pentium II Intel→Microsoft | *Pentium II* was developed by **Microsoft** (was Intel) | 6467 | `pentium_ii_intel_to_microsoft/deltas.npz` | 679,480,800 B (~648 MiB) | `380ab17ff6524e2273dc1f68019601baee4acd3b047f35bd1f0106adeadc44fa` |
|
| 19 |
-
| Taj Mahal Islam→Christianity | *Taj Mahal* is follower of **Christianity** (was Islam) | 21243 | `taj_mahal_islam_to_christianity/deltas.npz` | 679,480,804 B (~648 MiB) | `adeec83a4af118b1c34c6e2216ed9839eed351dcc002dc038a48070b081e9ca9` |
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
of the 24 edits in the `cf-sweep-24` campaign (see `tables/cf-sweep-24/`);
|
| 25 |
-
their `case_id`s match the `case_id` column in that campaign's
|
| 26 |
-
`edits.csv` / `setdiff_rows.csv`.
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
##
|
| 33 |
|
| 34 |
-
Each
|
| 35 |
|
| 36 |
-
- `meta` —
|
| 37 |
-
(`
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
(`
|
| 41 |
-
- `model.layers.{L}.mlp.down_proj.weight` for each `L` in `band` (here,
|
| 42 |
-
`L` in `3..10`, one array per layer) — the dense weight delta
|
| 43 |
-
`w_edited − w_base` for that layer's MLP down-projection, `float32`,
|
| 44 |
-
shape `(2304, 9216)` (gemma-2-2b's hidden size × MLP intermediate size).
|
| 45 |
-
MEMIT only ever touches this one weight matrix per edited layer, so these
|
| 46 |
-
eight arrays fully specify the edit.
|
| 47 |
|
| 48 |
-
## Reconstruction
|
| 49 |
|
| 50 |
```python
|
| 51 |
-
import
|
| 52 |
-
import numpy as np
|
| 53 |
-
import torch
|
| 54 |
from transformers import AutoModelForCausalLM
|
| 55 |
|
| 56 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
-
|
| 58 |
-
)
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# w += delta, in place, cast to the weight's own dtype/device — this is
|
| 65 |
-
# exactly circuit_diff/Interp_Gemma's interp_gemma.editing.deltas.apply_delta.
|
| 66 |
-
with torch.no_grad():
|
| 67 |
-
for name, d in delta.items():
|
| 68 |
-
w = model.get_parameter(name)
|
| 69 |
-
w[...] += torch.as_tensor(d, dtype=w.dtype, device=w.device)
|
| 70 |
-
|
| 71 |
-
# model is now M_e for this case; `meta["request"]` records what was edited.
|
| 72 |
```
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
| 1 |
# Curated case-study MEMIT deltas
|
| 2 |
|
| 3 |
+
Weight *deltas* (not checkpoints) for the paper's three case-study edits on
|
| 4 |
+
`google/gemma-2-2b`. Each `.npz` reconstructs the edited model as
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
```
|
| 7 |
+
M_e = base google/gemma-2-2b + delta
|
| 8 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
i.e. add each stored matrix to the identically-named base parameter. Base
|
| 11 |
+
weights are NOT included — obtain `google/gemma-2-2b` from Google under the
|
| 12 |
+
Gemma Terms of Use.
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
| File | Edit (subject → new object) | CounterFact case |
|
| 15 |
+
|---|---|---|
|
| 16 |
+
| `eiffel_paris_to_rome.npz` | "The Eiffel Tower is located in the city of" Paris → **Rome** | custom (case_id 0) |
|
| 17 |
+
| `taj_mahal_cf21243.npz` | "Taj Mahal is follower of" → **Christianity** | cf21243 (P140) |
|
| 18 |
+
| `pentium_ii_cf6467.npz` | "Pentium II was developed by" → **Microsoft** | cf6467 (P178) |
|
| 19 |
|
| 20 |
+
## Format
|
| 21 |
|
| 22 |
+
Each npz contains:
|
| 23 |
|
| 24 |
+
- `meta` — JSON string: `edit_method` (`memit`), the full edit `request`
|
| 25 |
+
(case_id, prompt template, subject, `target_new`), the edited layer `band`
|
| 26 |
+
(`[3..10]` for all three), and `base_model` (`google/gemma-2-2b`).
|
| 27 |
+
- `model.layers.{L}.mlp.down_proj.weight` — one float32 delta matrix of
|
| 28 |
+
shape `(2304, 9216)` per layer `L` in the band.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
## Reconstruction
|
| 31 |
|
| 32 |
```python
|
| 33 |
+
import numpy as np, torch
|
|
|
|
|
|
|
| 34 |
from transformers import AutoModelForCausalLM
|
| 35 |
|
| 36 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b")
|
| 37 |
+
z = np.load("eiffel_paris_to_rome.npz")
|
| 38 |
+
sd = model.state_dict()
|
| 39 |
+
for k in z.files:
|
| 40 |
+
if k == "meta":
|
| 41 |
+
continue
|
| 42 |
+
sd[k] += torch.from_numpy(z[k]).to(sd[k].dtype)
|
| 43 |
+
model.load_state_dict(sd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
```
|
| 45 |
|
| 46 |
+
## Scope
|
| 47 |
+
|
| 48 |
+
Only these three case-study deltas are released. The full ~100-edit delta
|
| 49 |
+
set behind the sweep tables exists (~69 GB) and can be shared on reasonable
|
| 50 |
+
request; every delta is also recomputable with the Circuit-Diff repository's
|
| 51 |
+
MEMIT wiring given the base model.
|
deltas/eiffel_paris_to_rome.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:476e5fb6a4f660faf5472fbaf0a2eefb2c4bb58bf0dfbb5e0ad50e3230f5507c
|
| 3 |
+
size 679480828
|
deltas/pentium_ii_cf6467.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:380ab17ff6524e2273dc1f68019601baee4acd3b047f35bd1f0106adeadc44fa
|
| 3 |
+
size 679480800
|
deltas/taj_mahal_cf21243.npz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:adeec83a4af118b1c34c6e2216ed9839eed351dcc002dc038a48070b081e9ca9
|
| 3 |
+
size 679480804
|