edwardF8 commited on
Commit
a3d0608
·
verified ·
1 Parent(s): 254071b

deltas: document the three curated case-study deltas (remove forthcoming placeholder)

Browse files
Files changed (1) hide show
  1. deltas/README.md +75 -7
deltas/README.md CHANGED
@@ -1,10 +1,78 @@
1
- # Curated case-study deltas — forthcoming
2
 
3
- This directory is a placeholder. Curated MEMIT edit deltas for the paper's
4
- case studies (Eiffel Tower Paris->Rome, and Taj Mahal / Pentium II if
5
- available) are planned for a follow-up drop and are not included yet.
 
 
 
6
 
7
- When added, each delta reconstructs an edited model M_e as:
8
- `base google/gemma-2-2b weights + delta -> M_e`.
9
 
10
- No model weights or edited checkpoints are included in this release.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.