open-interpretability 0.0.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- open_interpretability-0.0.20.dist-info/METADATA +157 -0
- open_interpretability-0.0.20.dist-info/RECORD +256 -0
- open_interpretability-0.0.20.dist-info/WHEEL +4 -0
- open_interpretability-0.0.20.dist-info/entry_points.txt +2 -0
- open_interpretability-0.0.20.dist-info/licenses/LICENSE +21 -0
- openinterp/__init__.py +6 -0
- openinterp/agents/__init__.py +25 -0
- openinterp/agents/base.py +229 -0
- openinterp/agents/judge.py +149 -0
- openinterp/agents/proposer.py +471 -0
- openinterp/agents/proposer_profiles.py +79 -0
- openinterp/agents/review_measurements.py +173 -0
- openinterp/agents/reviewer.py +498 -0
- openinterp/agreement.py +63 -0
- openinterp/audit_options.py +79 -0
- openinterp/baseline.py +254 -0
- openinterp/benchmark.py +450 -0
- openinterp/blends.py +239 -0
- openinterp/builder/__init__.py +6 -0
- openinterp/builder/agents.py +260 -0
- openinterp/builder/aligned.py +41 -0
- openinterp/builder/charts.py +411 -0
- openinterp/builder/circuit_pages.py +37 -0
- openinterp/builder/circuits.py +264 -0
- openinterp/builder/compiler.py +495 -0
- openinterp/builder/corpora.py +98 -0
- openinterp/builder/coverage.py +46 -0
- openinterp/builder/dashboard.py +255 -0
- openinterp/builder/disk_memo.py +65 -0
- openinterp/builder/experiment.py +105 -0
- openinterp/builder/heat.py +121 -0
- openinterp/builder/hrefs.py +71 -0
- openinterp/builder/learned_baseline.py +204 -0
- openinterp/builder/model_facts.py +138 -0
- openinterp/builder/neuronpedia_export.py +107 -0
- openinterp/builder/parallel.py +100 -0
- openinterp/builder/parquet_export.py +458 -0
- openinterp/builder/pieces.py +127 -0
- openinterp/builder/pii.py +211 -0
- openinterp/builder/registry_stats.py +144 -0
- openinterp/builder/research.py +109 -0
- openinterp/builder/sections.py +28 -0
- openinterp/builder/significance.py +103 -0
- openinterp/builder/sister_graph.py +180 -0
- openinterp/builder/standing.py +185 -0
- openinterp/builder/statuses.py +34 -0
- openinterp/builder/stopped.py +91 -0
- openinterp/builder/stops.py +30 -0
- openinterp/builder/superpositions.py +102 -0
- openinterp/builder/templates/_agent_role_cells.html +9 -0
- openinterp/builder/templates/_causal_chart.html +67 -0
- openinterp/builder/templates/_circuit.html +8 -0
- openinterp/builder/templates/_dashboard.html +133 -0
- openinterp/builder/templates/_experiment.html +500 -0
- openinterp/builder/templates/_macros.html +82 -0
- openinterp/builder/templates/_patchscope.html +33 -0
- openinterp/builder/templates/_prior_art.html +24 -0
- openinterp/builder/templates/_specificity.html +21 -0
- openinterp/builder/templates/_steering.html +34 -0
- openinterp/builder/templates/_superposition.html +62 -0
- openinterp/builder/templates/_vocab_chart.html +88 -0
- openinterp/builder/templates/_wiring.html +44 -0
- openinterp/builder/templates/about.html +95 -0
- openinterp/builder/templates/agent.html +69 -0
- openinterp/builder/templates/agents.html +80 -0
- openinterp/builder/templates/base.html +103 -0
- openinterp/builder/templates/circuit.html +64 -0
- openinterp/builder/templates/circuits.html +46 -0
- openinterp/builder/templates/experiment.html +21 -0
- openinterp/builder/templates/hub.html +16 -0
- openinterp/builder/templates/index.html +387 -0
- openinterp/builder/templates/layer.html +69 -0
- openinterp/builder/templates/learned-baseline.html +44 -0
- openinterp/builder/templates/model.html +151 -0
- openinterp/builder/templates/models.html +47 -0
- openinterp/builder/templates/neuron.html +234 -0
- openinterp/builder/templates/paper.html +39 -0
- openinterp/builder/templates/redirect.html +1 -0
- openinterp/builder/templates/research.html +31 -0
- openinterp/builder/templates/user.html +54 -0
- openinterp/builder/templates/users.html +39 -0
- openinterp/builder/templates/wiki/experiment.md +271 -0
- openinterp/builder/templates/wiki/index.md +32 -0
- openinterp/builder/templates/wiki/neuron.md +30 -0
- openinterp/builder/templates/wiki/stop.md +36 -0
- openinterp/builder/tree.py +470 -0
- openinterp/builder/users.py +142 -0
- openinterp/builder/wiki.py +427 -0
- openinterp/checks.py +429 -0
- openinterp/cli.py +494 -0
- openinterp/cli_baseline.py +332 -0
- openinterp/cli_benchmark.py +300 -0
- openinterp/cli_build.py +128 -0
- openinterp/cli_check.py +51 -0
- openinterp/cli_concepts.py +76 -0
- openinterp/cli_corpus.py +252 -0
- openinterp/cli_costs.py +257 -0
- openinterp/cli_coverage.py +76 -0
- openinterp/cli_crossref.py +86 -0
- openinterp/cli_errata.py +142 -0
- openinterp/cli_evidence.py +495 -0
- openinterp/cli_evidence_store.py +93 -0
- openinterp/cli_explain.py +101 -0
- openinterp/cli_loop.py +125 -0
- openinterp/cli_memory.py +28 -0
- openinterp/cli_neuronpedia.py +175 -0
- openinterp/cli_pause.py +45 -0
- openinterp/cli_pole_effects.py +133 -0
- openinterp/cli_probing.py +119 -0
- openinterp/cli_registry.py +348 -0
- openinterp/cli_reproduce.py +446 -0
- openinterp/cli_review.py +302 -0
- openinterp/cli_scan.py +223 -0
- openinterp/cli_score.py +446 -0
- openinterp/cli_sisters.py +86 -0
- openinterp/cli_submission.py +217 -0
- openinterp/cli_superpositions.py +118 -0
- openinterp/cli_wiring.py +54 -0
- openinterp/codeid.py +73 -0
- openinterp/concepts.py +400 -0
- openinterp/core/__init__.py +59 -0
- openinterp/core/agent_names.py +76 -0
- openinterp/core/attribution.py +101 -0
- openinterp/core/cache_dirs.py +15 -0
- openinterp/core/causal.py +82 -0
- openinterp/core/confounds.py +103 -0
- openinterp/core/contributors.py +26 -0
- openinterp/core/corpora.py +126 -0
- openinterp/core/costs.py +430 -0
- openinterp/core/draws.py +109 -0
- openinterp/core/errata.py +244 -0
- openinterp/core/evidence.py +160 -0
- openinterp/core/examples.py +93 -0
- openinterp/core/exceptions.py +29 -0
- openinterp/core/explanation.py +130 -0
- openinterp/core/fence.py +42 -0
- openinterp/core/heavy_lock.py +114 -0
- openinterp/core/identifiers.py +198 -0
- openinterp/core/isolation.py +149 -0
- openinterp/core/ledger.py +130 -0
- openinterp/core/licenses.py +28 -0
- openinterp/core/manifold.py +117 -0
- openinterp/core/partners.py +32 -0
- openinterp/core/patchscope.py +59 -0
- openinterp/core/paths.py +40 -0
- openinterp/core/pause.py +96 -0
- openinterp/core/pricing.py +178 -0
- openinterp/core/prior_art.py +44 -0
- openinterp/core/probing.py +146 -0
- openinterp/core/profiles.py +221 -0
- openinterp/core/project.py +28 -0
- openinterp/core/run_environment.py +38 -0
- openinterp/core/schemas.py +484 -0
- openinterp/core/specificity.py +49 -0
- openinterp/core/stats.py +172 -0
- openinterp/core/steering.py +49 -0
- openinterp/core/strict.py +19 -0
- openinterp/core/takedowns.py +136 -0
- openinterp/core/transcripts.py +130 -0
- openinterp/core/wiring.py +80 -0
- openinterp/corpus.py +476 -0
- openinterp/corpus_cache.py +145 -0
- openinterp/corpus_layouts.py +108 -0
- openinterp/corpus_presets.py +168 -0
- openinterp/corpus_rebuild.py +93 -0
- openinterp/coverage.py +155 -0
- openinterp/crossref.py +442 -0
- openinterp/data/__init__.py +9 -0
- openinterp/data/offensive_words.txt +58 -0
- openinterp/data/public_suffix_list.dat +15771 -0
- openinterp/data/sample_corpus.txt +40 -0
- openinterp/draw_steps.py +359 -0
- openinterp/errata_checks.py +129 -0
- openinterp/evidence.py +462 -0
- openinterp/evidence_branch.py +119 -0
- openinterp/evidence_lenses.py +75 -0
- openinterp/experiment_loop.py +357 -0
- openinterp/explain.py +252 -0
- openinterp/half_precision.py +79 -0
- openinterp/harness/__init__.py +37 -0
- openinterp/harness/ane/__init__.py +9 -0
- openinterp/harness/ane/backend.py +324 -0
- openinterp/harness/ane/cache.py +276 -0
- openinterp/harness/ane/chunks.py +163 -0
- openinterp/harness/ane/convert.py +116 -0
- openinterp/harness/ane/forward.py +258 -0
- openinterp/harness/ane/qualified.py +40 -0
- openinterp/harness/annotations.py +329 -0
- openinterp/harness/attribution.py +96 -0
- openinterp/harness/causal.py +264 -0
- openinterp/harness/confounds.py +184 -0
- openinterp/harness/covariance.py +301 -0
- openinterp/harness/crossref.py +195 -0
- openinterp/harness/cuda_devices.py +88 -0
- openinterp/harness/dead.py +124 -0
- openinterp/harness/devices.py +401 -0
- openinterp/harness/dictionaries.py +496 -0
- openinterp/harness/dreaming.py +116 -0
- openinterp/harness/environment.py +64 -0
- openinterp/harness/explanation_scores.py +371 -0
- openinterp/harness/features.py +276 -0
- openinterp/harness/first_position.py +137 -0
- openinterp/harness/heads.py +226 -0
- openinterp/harness/hooks.py +499 -0
- openinterp/harness/input_attribution.py +367 -0
- openinterp/harness/jlens.py +183 -0
- openinterp/harness/layer_cache.py +301 -0
- openinterp/harness/layer_major.py +274 -0
- openinterp/harness/lookahead.py +93 -0
- openinterp/harness/manifold.py +200 -0
- openinterp/harness/memory.py +471 -0
- openinterp/harness/moe.py +134 -0
- openinterp/harness/patcher.py +322 -0
- openinterp/harness/patchscope.py +177 -0
- openinterp/harness/probing.py +383 -0
- openinterp/harness/scan.py +462 -0
- openinterp/harness/scan_backend.py +201 -0
- openinterp/harness/sister_passes.py +463 -0
- openinterp/harness/sisters.py +363 -0
- openinterp/harness/sites.py +101 -0
- openinterp/harness/specificity.py +107 -0
- openinterp/harness/steering.py +159 -0
- openinterp/harness/superpositions.py +116 -0
- openinterp/harness/units.py +203 -0
- openinterp/harness/wiring.py +432 -0
- openinterp/harness/wiring_activations.py +285 -0
- openinterp/langid.py +73 -0
- openinterp/names.py +129 -0
- openinterp/neuronpedia_baseline.py +88 -0
- openinterp/neuronpedia_review.py +148 -0
- openinterp/planner.py +466 -0
- openinterp/planner_effects.py +89 -0
- openinterp/planner_heads.py +92 -0
- openinterp/planner_models.py +174 -0
- openinterp/planner_sisters.py +122 -0
- openinterp/planner_states.py +57 -0
- openinterp/planner_superpositions.py +114 -0
- openinterp/pole_effects.py +102 -0
- openinterp/prior_art.py +143 -0
- openinterp/reproduce.py +450 -0
- openinterp/revision.py +45 -0
- openinterp/runner_cache.py +35 -0
- openinterp/score_controls.py +169 -0
- openinterp/sensitive.py +243 -0
- openinterp/show.py +236 -0
- openinterp/signing.py +209 -0
- openinterp/sisters.py +476 -0
- openinterp/superposition_finders.py +225 -0
- openinterp/sync/__init__.py +5 -0
- openinterp/sync/r2.py +280 -0
- openinterp/syntax.py +399 -0
- openinterp/takedown_checks.py +76 -0
- openinterp/toxicity.py +158 -0
- openinterp/verdict_regression.py +79 -0
- openinterp/wiring_backfill.py +170 -0
- openinterp/wordnet.py +362 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
"""Bundle every experiment into a columnar registry for bulk analysis.
|
|
2
|
+
|
|
3
|
+
One row per experiment, whatever its verdict. ``unit_status`` is the standing of the row's
|
|
4
|
+
neuron pole, head or feature (``docs/PROTOCOL.md`` §3 step 9). It is CONTESTED when the
|
|
5
|
+
unit's reviews disagree, and is repeated on each of its rows. ``counts_toward_status``
|
|
6
|
+
marks the rows that the standing rests on. ``errata`` lists the ids of the errata
|
|
7
|
+
(``wiki/errata.jsonl``) that cover the row's record. ``is_latest`` marks the newest experiment for
|
|
8
|
+
each unit, which is not necessarily one of those.
|
|
9
|
+
|
|
10
|
+
``kind`` tells the units apart:
|
|
11
|
+
|
|
12
|
+
- A neuron pole row has ``neuron_idx`` and ``pole``.
|
|
13
|
+
- An attention head row has ``head_idx``.
|
|
14
|
+
- A dictionary feature row (the learned-basis baseline) has ``dictionary`` and
|
|
15
|
+
``feature_idx``.
|
|
16
|
+
- A superposition row has ``superposition_id`` and ``superposition_members``: the indices
|
|
17
|
+
of its member neurons in the layer, in index order.
|
|
18
|
+
|
|
19
|
+
Filter on ``kind`` before computing native-neuron statistics. Writes two copies of the
|
|
20
|
+
same table:
|
|
21
|
+
|
|
22
|
+
* ``data/registry.parquet`` -- stable URL, always the latest build (short cache).
|
|
23
|
+
* ``data/snapshots/registry-<sha256>.parquet`` -- content-addressed, cached forever.
|
|
24
|
+
|
|
25
|
+
``data/manifest.json`` points at the current snapshot. ``data/draws.parquet`` has one
|
|
26
|
+
row per random draw that could not be audited (dead or default-on, ``wiki/draws/``).
|
|
27
|
+
|
|
28
|
+
Output is deterministic: identical records produce byte-identical files, so an
|
|
29
|
+
unchanged registry deploys as a no-op.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import hashlib
|
|
35
|
+
import json
|
|
36
|
+
from collections.abc import Mapping, Sequence
|
|
37
|
+
from pathlib import Path
|
|
38
|
+
|
|
39
|
+
import pyarrow as pa
|
|
40
|
+
import pyarrow.parquet as pq
|
|
41
|
+
|
|
42
|
+
from openinterp.builder.tree import SIDES, Experiment, mlp_widths
|
|
43
|
+
from openinterp.core.confounds import MATCH_LABEL_SETS, NO_MATCH
|
|
44
|
+
from openinterp.core.schemas import AuditRecord, CorpusSource
|
|
45
|
+
|
|
46
|
+
Sources = Mapping[str, CorpusSource] | None
|
|
47
|
+
|
|
48
|
+
COUNTERFACTUAL_TYPE = pa.struct(
|
|
49
|
+
[
|
|
50
|
+
("base_prompt", pa.string()),
|
|
51
|
+
("counterfactual_prompt", pa.string()),
|
|
52
|
+
("expected_delta", pa.float64()),
|
|
53
|
+
("observed_delta", pa.float64()),
|
|
54
|
+
]
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
REGISTRY_SCHEMA = pa.schema(
|
|
58
|
+
[
|
|
59
|
+
("experiment_id", pa.string()),
|
|
60
|
+
("slug", pa.string()),
|
|
61
|
+
("is_latest", pa.bool_()),
|
|
62
|
+
("unit_status", pa.string()),
|
|
63
|
+
("counts_toward_status", pa.bool_()),
|
|
64
|
+
("errata", pa.list_(pa.string())),
|
|
65
|
+
("model_name", pa.string()),
|
|
66
|
+
("kind", pa.string()),
|
|
67
|
+
("layer", pa.int32()),
|
|
68
|
+
("neuron_idx", pa.int32()),
|
|
69
|
+
("pole", pa.string()),
|
|
70
|
+
("head_idx", pa.int32()),
|
|
71
|
+
("dictionary", pa.string()),
|
|
72
|
+
("feature_idx", pa.int32()),
|
|
73
|
+
("superposition_id", pa.string()),
|
|
74
|
+
("superposition_members", pa.list_(pa.int32())),
|
|
75
|
+
("model_num_layers", pa.int32()),
|
|
76
|
+
("model_mlp_width", pa.int32()),
|
|
77
|
+
("model_n_heads", pa.int32()),
|
|
78
|
+
("explanation", pa.string()),
|
|
79
|
+
("activating_tokens", pa.list_(pa.string())),
|
|
80
|
+
("is_lookahead", pa.bool_()),
|
|
81
|
+
("target_upcoming_tokens", pa.list_(pa.string())),
|
|
82
|
+
("kl_divergence", pa.float64()),
|
|
83
|
+
("max_activation", pa.float64()),
|
|
84
|
+
("counterfactuals", pa.list_(COUNTERFACTUAL_TYPE)),
|
|
85
|
+
("status", pa.string()),
|
|
86
|
+
("protocol_version", pa.string()),
|
|
87
|
+
("confidence_score", pa.float64()),
|
|
88
|
+
("sufficiency_score", pa.float64()),
|
|
89
|
+
("necessity_score", pa.float64()),
|
|
90
|
+
("hydra_mitigated", pa.bool_()),
|
|
91
|
+
("causal_target", pa.string()),
|
|
92
|
+
("tests_total", pa.int32()),
|
|
93
|
+
("tests_passed", pa.int32()),
|
|
94
|
+
("submitting_agent_model", pa.string()),
|
|
95
|
+
("reviewer_agent_model", pa.string()),
|
|
96
|
+
("submitting_contributor", pa.string()),
|
|
97
|
+
("reviewer_contributor", pa.string()),
|
|
98
|
+
("self_reviewed", pa.bool_()),
|
|
99
|
+
("reviewed_at", pa.timestamp("us", tz="UTC")),
|
|
100
|
+
("p_useful", pa.float64()),
|
|
101
|
+
("conclusiveness", pa.float64()),
|
|
102
|
+
("evidence_direction", pa.string()),
|
|
103
|
+
("reuses_probes_of", pa.string()),
|
|
104
|
+
("supersedes", pa.string()),
|
|
105
|
+
("sister_of", pa.string()),
|
|
106
|
+
("selection", pa.string()),
|
|
107
|
+
("corpus_sha256", pa.string()),
|
|
108
|
+
("corpus_dataset", pa.string()),
|
|
109
|
+
("corpus_revision", pa.string()),
|
|
110
|
+
("corpus_license", pa.string()),
|
|
111
|
+
("corpus_source_inferred", pa.bool_()),
|
|
112
|
+
("window_tokens", pa.int32()),
|
|
113
|
+
("balanced_accuracy", pa.float64()),
|
|
114
|
+
("effective_hard_negatives", pa.int32()),
|
|
115
|
+
("effective_holdouts", pa.int32()),
|
|
116
|
+
("confound_baseline", pa.string()),
|
|
117
|
+
("confound_baseline_accuracy", pa.float64()),
|
|
118
|
+
("token_r2", pa.float64()),
|
|
119
|
+
("position_r2", pa.float64()),
|
|
120
|
+
("personal_data_r2", pa.float64()),
|
|
121
|
+
("personal_data_mi_bits", pa.float64()),
|
|
122
|
+
("personal_data_active_tokens", pa.int64()),
|
|
123
|
+
("toxicity_r2", pa.float64()),
|
|
124
|
+
("toxicity_mi_bits", pa.float64()),
|
|
125
|
+
("toxicity_active_tokens", pa.int64()),
|
|
126
|
+
("hate_speech_r2", pa.float64()),
|
|
127
|
+
("hate_speech_mi_bits", pa.float64()),
|
|
128
|
+
("hate_speech_active_tokens", pa.int64()),
|
|
129
|
+
("names_r2", pa.float64()),
|
|
130
|
+
("names_mi_bits", pa.float64()),
|
|
131
|
+
("names_active_tokens", pa.int64()),
|
|
132
|
+
("postal_addresses_r2", pa.float64()),
|
|
133
|
+
("postal_addresses_mi_bits", pa.float64()),
|
|
134
|
+
("postal_addresses_active_tokens", pa.int64()),
|
|
135
|
+
("top_partner_neuron", pa.int32()),
|
|
136
|
+
("top_partner_pole", pa.string()),
|
|
137
|
+
("top_partner_lift", pa.float64()),
|
|
138
|
+
("top_partner_spearman", pa.float64()),
|
|
139
|
+
("redundancy_ratio", pa.float64()),
|
|
140
|
+
("jacobian_promoted", pa.list_(pa.string())),
|
|
141
|
+
("logit_promoted", pa.list_(pa.string())),
|
|
142
|
+
("jacobian_promoted_z", pa.list_(pa.float64())),
|
|
143
|
+
("logit_promoted_z", pa.list_(pa.float64())),
|
|
144
|
+
("lens_overlap", pa.float64()),
|
|
145
|
+
("lens_direction_cosine", pa.float64()),
|
|
146
|
+
("jacobian_kurtosis", pa.float64()),
|
|
147
|
+
("current_token_share", pa.float64()),
|
|
148
|
+
("context_mean_distance", pa.float64()),
|
|
149
|
+
("context_ablation_agreement", pa.float64()),
|
|
150
|
+
("detection_score", pa.float64()),
|
|
151
|
+
("fuzzing_score", pa.float64()),
|
|
152
|
+
("embedding_auroc", pa.float64()),
|
|
153
|
+
("previous_token_score", pa.float64()),
|
|
154
|
+
("duplicate_token_score", pa.float64()),
|
|
155
|
+
("induction_score", pa.float64()),
|
|
156
|
+
("dictionary_explained_variance", pa.float64()),
|
|
157
|
+
("dictionary_mean_l0", pa.float64()),
|
|
158
|
+
("dictionary_dead_share", pa.float64()),
|
|
159
|
+
("feature_density", pa.float64()),
|
|
160
|
+
("record_json", pa.string()),
|
|
161
|
+
]
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def record_to_row(record: AuditRecord) -> dict:
|
|
166
|
+
"""The registry columns that come from ``record`` alone."""
|
|
167
|
+
sub = record.submission
|
|
168
|
+
return {
|
|
169
|
+
**_unit_columns(sub.identifier, sub.superposition_profile),
|
|
170
|
+
"model_num_layers": sub.model_num_layers,
|
|
171
|
+
"model_mlp_width": sub.model_mlp_width,
|
|
172
|
+
"model_n_heads": sub.model_n_heads,
|
|
173
|
+
"explanation": sub.natural_language_explanation,
|
|
174
|
+
"activating_tokens": sub.activating_tokens,
|
|
175
|
+
"is_lookahead": sub.lookahead.is_lookahead,
|
|
176
|
+
"target_upcoming_tokens": sub.lookahead.target_upcoming_tokens,
|
|
177
|
+
"kl_divergence": sub.lookahead.kl_divergence,
|
|
178
|
+
"max_activation": sub.max_activation,
|
|
179
|
+
"counterfactuals": [cf.model_dump() for cf in sub.counterfactuals],
|
|
180
|
+
**_verdict_columns(record),
|
|
181
|
+
"record_json": record.model_dump_json(),
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _unit_columns(ident, superposition) -> dict:
|
|
186
|
+
kind = ident.kind
|
|
187
|
+
return {
|
|
188
|
+
"slug": ident.slug,
|
|
189
|
+
"model_name": ident.model_name,
|
|
190
|
+
"kind": ident.kind,
|
|
191
|
+
"layer": ident.layer,
|
|
192
|
+
"neuron_idx": ident.neuron_idx if kind == "mlp_neuron_pole" else None,
|
|
193
|
+
"pole": ident.pole,
|
|
194
|
+
"head_idx": ident.head_idx if kind == "attn_head" else None,
|
|
195
|
+
"dictionary": ident.dictionary if kind == "dictionary_feature" else None,
|
|
196
|
+
"feature_idx": ident.feature_idx if kind == "dictionary_feature" else None,
|
|
197
|
+
"superposition_id": ident.superposition_id if kind == "superposition" else None,
|
|
198
|
+
"superposition_members": superposition.neurons if superposition else None,
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _verdict_columns(record: AuditRecord) -> dict:
|
|
203
|
+
verdict = record.verdict
|
|
204
|
+
causal = verdict.causal_metrics if verdict else None
|
|
205
|
+
# A one-token prompt (protocol 0.8) is recorded but not measured, so it isn't a test.
|
|
206
|
+
tests = [t for t in verdict.adversarial_test_results if t.measured] if verdict else []
|
|
207
|
+
return {
|
|
208
|
+
"status": verdict.status if verdict else None,
|
|
209
|
+
# The decision rule the verdict was judged under (docs/PROTOCOL.md §6).
|
|
210
|
+
"protocol_version": verdict.policy.protocol_version if verdict and verdict.policy else None,
|
|
211
|
+
"confidence_score": verdict.confidence_score if verdict else None,
|
|
212
|
+
**_columns(causal, CAUSAL_COLUMNS),
|
|
213
|
+
"tests_total": len(tests),
|
|
214
|
+
"tests_passed": sum(t.passed for t in tests),
|
|
215
|
+
"submitting_agent_model": record.submission.submitting_agent_model,
|
|
216
|
+
"reviewer_agent_model": verdict.reviewer_agent_model if verdict else None,
|
|
217
|
+
"submitting_contributor": record.submission.contributor,
|
|
218
|
+
"reviewer_contributor": verdict.contributor if verdict else None,
|
|
219
|
+
"self_reviewed": record.self_reviewed if verdict else None,
|
|
220
|
+
"reviewed_at": verdict.timestamp if verdict else None,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _columns(obj, columns: dict[str, str]) -> dict:
|
|
225
|
+
"""``column -> obj.<attribute>`` for each pair in ``columns``; all ``None`` without ``obj``."""
|
|
226
|
+
return {col: getattr(obj, attr) if obj else None for col, attr in columns.items()}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# Parquet column -> attribute, per object a row reads; the order is the column order.
|
|
230
|
+
CAUSAL_COLUMNS = {
|
|
231
|
+
"sufficiency_score": "sufficiency_score",
|
|
232
|
+
"necessity_score": "necessity_score",
|
|
233
|
+
"hydra_mitigated": "hydra_mitigated",
|
|
234
|
+
"causal_target": "target",
|
|
235
|
+
}
|
|
236
|
+
CONFOUND_COLUMNS = {"token_r2": "token_r2", "position_r2": "position_r2"}
|
|
237
|
+
PARTNER_COLUMNS = {
|
|
238
|
+
"top_partner_neuron": "neuron_idx",
|
|
239
|
+
"top_partner_pole": "pole",
|
|
240
|
+
"top_partner_lift": "coactivation_lift_lower",
|
|
241
|
+
"top_partner_spearman": "spearman",
|
|
242
|
+
}
|
|
243
|
+
LENS_COLUMNS = {
|
|
244
|
+
"jacobian_promoted": "jacobian_promoted",
|
|
245
|
+
"logit_promoted": "logit_promoted",
|
|
246
|
+
"jacobian_promoted_z": "jacobian_promoted_z",
|
|
247
|
+
"logit_promoted_z": "logit_promoted_z",
|
|
248
|
+
"lens_overlap": "overlap",
|
|
249
|
+
"lens_direction_cosine": "direction_cosine",
|
|
250
|
+
"jacobian_kurtosis": "jacobian_kurtosis",
|
|
251
|
+
}
|
|
252
|
+
ATTRIBUTION_COLUMNS = {
|
|
253
|
+
"current_token_share": "current_token_share",
|
|
254
|
+
"context_mean_distance": "mean_distance",
|
|
255
|
+
"context_ablation_agreement": "ablation_agreement",
|
|
256
|
+
}
|
|
257
|
+
HEAD_COLUMNS = {
|
|
258
|
+
"previous_token_score": "previous_token_score",
|
|
259
|
+
"duplicate_token_score": "duplicate_token_score",
|
|
260
|
+
"induction_score": "induction_score",
|
|
261
|
+
}
|
|
262
|
+
DICTIONARY_COLUMNS = {
|
|
263
|
+
"dictionary_explained_variance": "explained_variance",
|
|
264
|
+
"dictionary_mean_l0": "mean_l0",
|
|
265
|
+
"dictionary_dead_share": "dead_share",
|
|
266
|
+
"feature_density": "density",
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def experiment_row(exp: Experiment, corpus_sources: Sources = None) -> dict:
|
|
271
|
+
"""Return one experiment's row.
|
|
272
|
+
|
|
273
|
+
``corpus_sources`` is committed sidecars by SHA-256
|
|
274
|
+
(:func:`openinterp.corpus.load_sources`). They give the corpus of records that didn't
|
|
275
|
+
record one, marked as inferred.
|
|
276
|
+
"""
|
|
277
|
+
sub, verdict = exp.record.submission, exp.record.verdict
|
|
278
|
+
metrics, scores = verdict.metrics, verdict.explanation_scores
|
|
279
|
+
top = sub.correlated_neurons[0] if sub.correlated_neurons else None
|
|
280
|
+
attribution = sub.input_attribution
|
|
281
|
+
if attribution is not None and not attribution.examples:
|
|
282
|
+
attribution = None # every example was skipped: nothing measured
|
|
283
|
+
return {
|
|
284
|
+
**record_to_row(exp.record),
|
|
285
|
+
**_standing_columns(exp),
|
|
286
|
+
**_corpus_columns(sub.provenance, corpus_sources or {}),
|
|
287
|
+
"balanced_accuracy": metrics.balanced_accuracy if metrics else None,
|
|
288
|
+
"effective_hard_negatives": exp.sig.negatives.clusters,
|
|
289
|
+
"effective_holdouts": exp.sig.holdouts.clusters,
|
|
290
|
+
"confound_baseline": metrics.confound_baseline if metrics else None,
|
|
291
|
+
"confound_baseline_accuracy": metrics.confound_baseline_accuracy if metrics else None,
|
|
292
|
+
**_columns(sub.confounds, CONFOUND_COLUMNS),
|
|
293
|
+
**_match_columns(sub.confounds),
|
|
294
|
+
**_columns(top, PARTNER_COLUMNS),
|
|
295
|
+
"redundancy_ratio": verdict.joint_ablation.redundancy_ratio
|
|
296
|
+
if verdict.joint_ablation
|
|
297
|
+
else None,
|
|
298
|
+
**_columns(sub.vocabulary_lens, LENS_COLUMNS),
|
|
299
|
+
**_columns(attribution, ATTRIBUTION_COLUMNS),
|
|
300
|
+
"detection_score": _balanced(scores.detection if scores else None),
|
|
301
|
+
"fuzzing_score": _balanced(scores.fuzzing if scores else None),
|
|
302
|
+
"embedding_auroc": scores.embedding_auroc if scores else None,
|
|
303
|
+
**_columns(sub.head_profile, HEAD_COLUMNS),
|
|
304
|
+
**_columns(sub.dictionary_profile, DICTIONARY_COLUMNS),
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _standing_columns(exp: Experiment) -> dict:
|
|
309
|
+
return {
|
|
310
|
+
"experiment_id": exp.id,
|
|
311
|
+
"is_latest": exp.is_latest,
|
|
312
|
+
"unit_status": exp.standing.status if exp.standing else None,
|
|
313
|
+
"counts_toward_status": exp.counts,
|
|
314
|
+
"errata": [erratum.id for erratum in exp.errata],
|
|
315
|
+
"p_useful": exp.sig.p_useful,
|
|
316
|
+
"conclusiveness": exp.sig.conclusiveness,
|
|
317
|
+
"evidence_direction": exp.sig.direction,
|
|
318
|
+
"reuses_probes_of": exp.reuses,
|
|
319
|
+
"supersedes": exp.record.submission.supersedes,
|
|
320
|
+
"sister_of": exp.record.submission.sister_of,
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _match_columns(confounds) -> dict:
|
|
325
|
+
"""One label set's measures per match label set, so a query can find such units."""
|
|
326
|
+
out = {}
|
|
327
|
+
for name in MATCH_LABEL_SETS:
|
|
328
|
+
found = ((confounds.labels or {}) if confounds else {}).get(name)
|
|
329
|
+
key = name.replace(" ", "_")
|
|
330
|
+
active = sum(s.active for s in found.levels if s.label != NO_MATCH) if found else None
|
|
331
|
+
out[f"{key}_r2"] = found.r2 if found else None
|
|
332
|
+
out[f"{key}_mi_bits"] = found.mutual_information_bits if found else None
|
|
333
|
+
out[f"{key}_active_tokens"] = active
|
|
334
|
+
return out
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _corpus_columns(prov, corpus_sources: dict) -> dict:
|
|
338
|
+
"""The scan's corpus, inferred from the committed sidecars when the record has none."""
|
|
339
|
+
source = prov.corpus_source if prov else None
|
|
340
|
+
inferred = source is None and prov is not None and prov.corpus_sha256 in corpus_sources
|
|
341
|
+
source = corpus_sources[prov.corpus_sha256] if inferred else source
|
|
342
|
+
return {
|
|
343
|
+
"selection": prov.selection if prov else None,
|
|
344
|
+
"corpus_sha256": prov.corpus_sha256 if prov else None,
|
|
345
|
+
"corpus_dataset": source.dataset if source else None,
|
|
346
|
+
"corpus_revision": source.revision if source else None,
|
|
347
|
+
"corpus_license": source.license if source else None,
|
|
348
|
+
"corpus_source_inferred": inferred if source else None,
|
|
349
|
+
"window_tokens": prov.snippet_tokens if prov else None,
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def _balanced(score) -> float | None:
|
|
354
|
+
return score.balanced_accuracy if score else None
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
UNIT_INDEX_COLUMNS = ("neuron_idx", "head_idx", "feature_idx") # a superposition has none
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def records_to_table(experiments: Sequence[Experiment], corpus_sources: Sources = None) -> pa.Table:
|
|
361
|
+
"""The registry table: one row per experiment, in a fixed order.
|
|
362
|
+
|
|
363
|
+
The ``model_mlp_width`` column is filled for old records that do not give a width.
|
|
364
|
+
``record_json`` keeps the signed record as it is.
|
|
365
|
+
"""
|
|
366
|
+
widths = mlp_widths(e.record for e in experiments)
|
|
367
|
+
rows = sorted(
|
|
368
|
+
(_with_width(experiment_row(e, corpus_sources), widths) for e in experiments),
|
|
369
|
+
key=lambda row: (
|
|
370
|
+
row["model_name"],
|
|
371
|
+
row["layer"],
|
|
372
|
+
list(SIDES).index(row["kind"]),
|
|
373
|
+
row["dictionary"] or row["superposition_id"] or "",
|
|
374
|
+
next((row[c] for c in UNIT_INDEX_COLUMNS if row[c] is not None), 0),
|
|
375
|
+
row["pole"] or "",
|
|
376
|
+
row["experiment_id"],
|
|
377
|
+
),
|
|
378
|
+
)
|
|
379
|
+
return pa.Table.from_pylist(rows, schema=REGISTRY_SCHEMA)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def _with_width(row: dict, widths: dict[str, int]) -> dict:
|
|
383
|
+
return {**row, "model_mlp_width": row["model_mlp_width"] or widths.get(row["model_name"])}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def export_registry(
|
|
387
|
+
experiments: Sequence[Experiment], output_dir: Path, corpus_sources: Sources = None
|
|
388
|
+
) -> Path:
|
|
389
|
+
"""Write the registry parquet, a content-addressed snapshot and a manifest.
|
|
390
|
+
|
|
391
|
+
Returns the path of ``data/registry.parquet``.
|
|
392
|
+
"""
|
|
393
|
+
data_dir = Path(output_dir) / "data"
|
|
394
|
+
(data_dir / "snapshots").mkdir(parents=True, exist_ok=True)
|
|
395
|
+
latest = data_dir / "registry.parquet"
|
|
396
|
+
pq.write_table(records_to_table(experiments, corpus_sources), latest, compression="zstd")
|
|
397
|
+
|
|
398
|
+
digest = hashlib.sha256(latest.read_bytes()).hexdigest()[:16]
|
|
399
|
+
snapshot = data_dir / "snapshots" / f"registry-{digest}.parquet"
|
|
400
|
+
snapshot.write_bytes(latest.read_bytes())
|
|
401
|
+
|
|
402
|
+
manifest = {
|
|
403
|
+
"latest": "data/registry.parquet",
|
|
404
|
+
"snapshot": snapshot.relative_to(output_dir).as_posix(),
|
|
405
|
+
"sha256_prefix": digest,
|
|
406
|
+
"experiments": len(experiments),
|
|
407
|
+
"updated_at": max(
|
|
408
|
+
(e.record.verdict.timestamp.isoformat() for e in experiments), default=None
|
|
409
|
+
),
|
|
410
|
+
}
|
|
411
|
+
(data_dir / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
|
|
412
|
+
return latest
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
DRAW_COLUMNS = {
|
|
416
|
+
"kind": pa.string(),
|
|
417
|
+
"model_name": pa.string(),
|
|
418
|
+
"layer": pa.int32(),
|
|
419
|
+
"index": pa.int32(),
|
|
420
|
+
"pole": pa.string(),
|
|
421
|
+
"dictionary": pa.string(),
|
|
422
|
+
"outcome": pa.string(),
|
|
423
|
+
"active_share": pa.float64(),
|
|
424
|
+
"corpus_sha256": pa.string(),
|
|
425
|
+
"window_tokens": pa.int32(),
|
|
426
|
+
"seed": pa.int64(),
|
|
427
|
+
"protocol_version": pa.string(),
|
|
428
|
+
"drawn_at": pa.timestamp("us", tz="UTC"),
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def export_draws(draws: Sequence, output_dir: Path) -> Path:
|
|
433
|
+
"""Write ``data/draws.parquet``: the random draws no experiment could audit."""
|
|
434
|
+
rows = []
|
|
435
|
+
for d in draws:
|
|
436
|
+
ident, prov = d.identifier, d.provenance
|
|
437
|
+
rows.append(
|
|
438
|
+
{
|
|
439
|
+
"kind": ident.kind,
|
|
440
|
+
"model_name": ident.model_name,
|
|
441
|
+
"layer": ident.layer,
|
|
442
|
+
"index": ident.index,
|
|
443
|
+
"pole": getattr(ident, "pole", None),
|
|
444
|
+
"dictionary": getattr(ident, "dictionary", None),
|
|
445
|
+
"outcome": d.outcome,
|
|
446
|
+
"active_share": d.active_share,
|
|
447
|
+
"corpus_sha256": prov.corpus_sha256,
|
|
448
|
+
"window_tokens": prov.snippet_tokens,
|
|
449
|
+
"seed": prov.seed,
|
|
450
|
+
"protocol_version": d.protocol_version,
|
|
451
|
+
"drawn_at": d.timestamp,
|
|
452
|
+
}
|
|
453
|
+
)
|
|
454
|
+
path = Path(output_dir) / "data" / "draws.parquet"
|
|
455
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
456
|
+
schema = pa.schema(list(DRAW_COLUMNS.items()))
|
|
457
|
+
pq.write_table(pa.Table.from_pylist(rows, schema=schema), path, compression="zstd")
|
|
458
|
+
return path
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Pieces bars: which neurons of each layer are studied, and their status.
|
|
2
|
+
|
|
3
|
+
The home page draws one bar per layer of a model (:func:`model_pieces`), and a layer page
|
|
4
|
+
draws one cell per neuron (:func:`layer_pieces`). A neuron whose scans all stopped is
|
|
5
|
+
studied too (:class:`openinterp.builder.stopped.StoppedNeuron`).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
|
|
12
|
+
from openinterp.builder.charts import best_status, pole_text, stopped_label
|
|
13
|
+
from openinterp.builder.statuses import MAP_STATUSES, STOPPED
|
|
14
|
+
from openinterp.builder.stopped import StoppedNeuron
|
|
15
|
+
|
|
16
|
+
# Pieces bars: BitTorrent-style coverage, one cell per neuron or block of neurons. Cells sit
|
|
17
|
+
# on an integer pitch so the empty-cell grid can be one SVG pattern rather than a rect each.
|
|
18
|
+
PIECE_ROW = 128 # cells per bar
|
|
19
|
+
PIECE_PITCH = 5 # px per cell, 1px gap included
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def model_pieces(model) -> dict | None:
|
|
23
|
+
"""One pieces bar per layer, each cell a block of ``ceil(mlp_width / PIECE_ROW)`` neurons.
|
|
24
|
+
|
|
25
|
+
A cell is lit when any neuron in its block is studied, and takes the best status among
|
|
26
|
+
them (``MAP_STATUSES`` order). With blocks this wide a lit cell is not a covered block:
|
|
27
|
+
the bars show where the studied neurons are and where the gaps are, not how many.
|
|
28
|
+
"""
|
|
29
|
+
if not model.mlp_width or not model.neurons:
|
|
30
|
+
return None
|
|
31
|
+
block = math.ceil(model.mlp_width / PIECE_ROW)
|
|
32
|
+
n_cells = math.ceil(model.mlp_width / block)
|
|
33
|
+
by_layer = {layer.layer: layer for layer in model.layers}
|
|
34
|
+
rows = []
|
|
35
|
+
for i in range(model.n_layers):
|
|
36
|
+
cells: dict[int, list] = {}
|
|
37
|
+
layer = by_layer.get(i)
|
|
38
|
+
for n in [*layer.neurons, *layer.stopped] if layer else ():
|
|
39
|
+
cells.setdefault(n.idx // block, []).append(n)
|
|
40
|
+
lit = []
|
|
41
|
+
for c, neurons in sorted(cells.items()):
|
|
42
|
+
status = min((cell_status(n) for n in neurons), key=MAP_STATUSES.index)
|
|
43
|
+
lo, hi = c * block, min((c + 1) * block, model.mlp_width) - 1
|
|
44
|
+
lit.append(
|
|
45
|
+
{
|
|
46
|
+
"x": c * PIECE_PITCH,
|
|
47
|
+
"status": status,
|
|
48
|
+
"label": f"L{i} N{lo:,}–{hi:,}: " + "; ".join(map(cell_label, neurons)),
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
rows.append({"layer": i, "cells": lit})
|
|
52
|
+
return {
|
|
53
|
+
"block": block,
|
|
54
|
+
"pitch": PIECE_PITCH,
|
|
55
|
+
"width": n_cells * PIECE_PITCH - 1,
|
|
56
|
+
"rows": rows,
|
|
57
|
+
"lit": sum(len(r["cells"]) for r in rows),
|
|
58
|
+
"cells": n_cells * model.n_layers,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def cell_status(neuron) -> str:
|
|
63
|
+
"""A studied neuron's map status: its best pole's, or STOPPED."""
|
|
64
|
+
return STOPPED if isinstance(neuron, StoppedNeuron) else best_status(neuron)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def cell_label(neuron) -> str:
|
|
68
|
+
"""A studied neuron's text in a pieces cell."""
|
|
69
|
+
if isinstance(neuron, StoppedNeuron):
|
|
70
|
+
return stopped_label(neuron)
|
|
71
|
+
return f"{neuron.label} {pole_text(neuron)}"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _layer_cells(layer, left: int, top: int) -> list[dict]:
|
|
75
|
+
"""Return one cell per studied neuron of ``layer``, at its place in the grid."""
|
|
76
|
+
|
|
77
|
+
def place(idx: int) -> dict:
|
|
78
|
+
return {
|
|
79
|
+
"x": left + (idx % PIECE_ROW) * PIECE_PITCH,
|
|
80
|
+
"y": top + (idx // PIECE_ROW) * PIECE_PITCH,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
studied = [
|
|
84
|
+
place(n.idx)
|
|
85
|
+
| {"status": best_status(n), "href": n.href, "label": f"{n.label} · {pole_text(n)}"}
|
|
86
|
+
for n in layer.neurons
|
|
87
|
+
]
|
|
88
|
+
stopped = [
|
|
89
|
+
place(n.idx) | {"status": STOPPED, "href": None, "label": stopped_label(n)}
|
|
90
|
+
for n in layer.stopped
|
|
91
|
+
]
|
|
92
|
+
return studied + stopped
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def layer_pieces(model, layer) -> dict | None:
|
|
96
|
+
"""Return the layer's neurons as a grid of ``PIECE_ROW``-wide rows, one cell per neuron.
|
|
97
|
+
|
|
98
|
+
Each studied neuron is a lit cell, coloured by its best pole's status, linked to its page.
|
|
99
|
+
"""
|
|
100
|
+
if not model.mlp_width:
|
|
101
|
+
return None
|
|
102
|
+
left, top = 8 * PIECE_PITCH, 0 # room for row labels; multiples of the pitch keep
|
|
103
|
+
# the empty-cell pattern aligned with the lit cells
|
|
104
|
+
n_rows = math.ceil(model.mlp_width / PIECE_ROW)
|
|
105
|
+
cells = _layer_cells(layer, left, top)
|
|
106
|
+
rows = [
|
|
107
|
+
{
|
|
108
|
+
"y": top + r * PIECE_PITCH,
|
|
109
|
+
"start": r * PIECE_ROW,
|
|
110
|
+
"width": min(PIECE_ROW, model.mlp_width - r * PIECE_ROW) * PIECE_PITCH - 1,
|
|
111
|
+
}
|
|
112
|
+
for r in range(n_rows)
|
|
113
|
+
]
|
|
114
|
+
counts = dict.fromkeys(MAP_STATUSES, 0)
|
|
115
|
+
for c in cells:
|
|
116
|
+
counts[c["status"]] += 1
|
|
117
|
+
return {
|
|
118
|
+
"left": left,
|
|
119
|
+
"pitch": PIECE_PITCH,
|
|
120
|
+
"width": left + PIECE_ROW * PIECE_PITCH,
|
|
121
|
+
"height": top + n_rows * PIECE_PITCH,
|
|
122
|
+
"rows": rows,
|
|
123
|
+
"label_every": 8,
|
|
124
|
+
"cells": cells,
|
|
125
|
+
"counts": counts,
|
|
126
|
+
"unexplored": model.mlp_width - len(cells),
|
|
127
|
+
}
|