edwardF8 commited on
Commit
04f9fec
·
verified ·
1 Parent(s): 0ec208b

deltas: curated case-study MEMIT deltas (eiffel, taj mahal cf21243, pentium ii cf6467) + card

Browse files
deltas/README.md CHANGED
@@ -1,78 +1,51 @@
1
  # Curated case-study MEMIT deltas
2
 
3
- This directory holds dense per-layer weight deltas for the paper's three
4
- worked case-study edits, each applied on top of `google/gemma-2-2b` (base,
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
- No model weights or edited checkpoints are included — only the delta, which
11
- is meaningless without the (separately downloaded, license-gated) base model.
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
- The Eiffel Tower case is the bundle backing `bundles/eiffel_paris_to_rome/`
22
- elsewhere in this dataset and the library's shipped example bundle
23
- (`circuit_diff/examples/bundles/eiffel/`). Pentium II and Taj Mahal are two
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
- This is a curated 3-edit subset chosen for the paper's case-study figures,
29
- not the full ~100-edit delta set used across the sweep campaigns; the full
30
- set is not planned for release but exists and can be shared on request.
 
 
31
 
32
- ## npz key structure
33
 
34
- Each `deltas.npz` is a plain NumPy archive (`np.load(path)`) with:
35
 
36
- - `meta` — a 0-d array wrapping a single JSON string. Fields: `edit_method`
37
- (`"memit"`), `request` (the MEMIT edit request: `case_id`, `prompt`
38
- template, `subject`, `target_new.str`), `band` (the list of 0-indexed
39
- transformer layers MEMIT was allowed to edit), `base_model`
40
- (`"google/gemma-2-2b"`).
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 recipe
49
 
50
  ```python
51
- import json
52
- import numpy as np
53
- import torch
54
  from transformers import AutoModelForCausalLM
55
 
56
- model = AutoModelForCausalLM.from_pretrained(
57
- "google/gemma-2-2b", torch_dtype=torch.bfloat16
58
- )
59
-
60
- with np.load("eiffel_paris_to_rome/deltas.npz", allow_pickle=False) as z:
61
- meta = json.loads(str(z["meta"]))
62
- delta = {name: z[name] for name in z.files if name != "meta"}
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
- Applying the same delta a second time double-edits the model; applying it to
75
- anything other than an unmodified `google/gemma-2-2b` checkpoint does not
76
- reconstruct a meaningful edited model — `meta["base_model"]` records which
77
- base the delta was captured against, and callers should assert on it (as
78
- `interp_gemma.editing.deltas.reconstruct_into` does) before applying.
 
 
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