unai-zulaika/ghost-heads

Python

0

1 commits

updated May 7, 2026

See the code

README

Release: Code for "Ghost Heads Across Training: When Greedy and Distributional Patching Disagree"

Anonymous code release accompanying the ICML 2026 Mechanistic Interpretability Workshop submission.

This repository contains the code to reproduce every figure, table, and load-bearing number in the paper.

Cached intermediate CSVs (~322 MB) will be released alongside the camera-ready / non-anonymous version of the paper. They are not included here because anonymous review platforms (anonymous.4open.science, etc.) are optimised for browsing source files, not for hosting hundreds of megabytes of patching outputs. The code in this repository is sufficient to re-derive every CSV from the public model checkpoints.

What this bundle is

A self-contained, anonymized, version-pinned set of scripts that:

  • Run pass@k behavioral evaluation on OLMo-3-7B / OLMo-2-7B (Phase 0).
  • Run head-level activation patching with both greedy and distributional metrics across 14 OLMo-3 checkpoints (Phase 1).
  • Replicate the ghost-head phenomenon on DeepSeek-Math-7B and Qwen2.5-Math-7B (Phase 2 / cross-arch).
  • Run the seven RL-Zero null probes (weight transplant, neuron overlap, weight-diff SVD, noise fragility, verifier reranking, cross-model patching).
  • Run answer-token patching on arithmetic, GSM8K, and MATH500 (Phase 2 / verification).
  • Compute every analysis number cited in the paper (bootstrap CIs, sign-flip permutation null over 1024 heads, threshold sensitivity, value-norm vs GhostScore).

What's needed to actually run

  • Python 3.10+, deps in requirements.txt.
  • A GPU with ≥ 24 GB VRAM (we used Quadro RTX 8000, 48 GB) and attn_implementation="eager" (no FlashAttention required).
  • The relevant HuggingFace model checkpoints:
    • allenai/Olmo-3-1025-7B
    • allenai/Olmo-3-7B-RL-Zero-Math (revisions: step_200, step_1000, step_1900)
    • All OLMo-3 stage-1, stage-2, stage-3 revisions (listed in each script's --revision choices)
    • allenai/OLMo-2-1124-7B (cross-model temporal replication)
    • deepseek-ai/deepseek-math-7b-base, Qwen/Qwen2.5-Math-7B (cross-architecture)
  • Patience: a full re-run of the 14-checkpoint head-patching sweep is ~50 GPU-hours.

Quickstart (one head-patching job, ~2 GPU-hours)

pip install -r requirements.txt

# Run head patching on OLMo-3 base for 3-digit arithmetic.
# Produces a CSV with greedy and distributional recovery per (layer, head).
python scripts/phase1_circuits/head_patching_dist.py \
    --checkpoint base \
    --device cuda:0 \
    -n 200 \
    --output head_patching_dist_base.csv

reproduce_all.sh exists as a tier-2 smoke-test pipeline (regenerates figures from cached CSVs + diff against committed PDF text-extracts), but it requires the cached CSVs that will ship with the camera-ready. Until then, run individual scripts directly.

Folder layout

release/
├── README.md                this file
├── provenance.csv           every paper claim → CSV → script → notes
├── requirements.txt         pinned Python deps
├── reproduce_all.sh         smoke-test pipeline (needs cached CSVs)
├── expected_checksums.txt   SHA256 of every CSV (for camera-ready verification)
├── figures/                 regenerated PDFs land here at run time
└── scripts/
    ├── phase0_behavioral/   pass@k evaluation, Figure 1
    ├── phase1_circuits/     head patching (greedy + distributional), value norms
    ├── phase2_cross_task/   GSM8K / MATH500 single-token patching, multi-step
    ├── phase2_ghost/        cross-architecture replication, threshold sweep,
    │                        cross-model base→RL patching, master figure script
    ├── phase2_transplant/   weight transplant, weight-diff geometry,
    │                        noise fragility, verifier reranking
    ├── phase2_verification/ answer-token patching, verification heads
    └── analysis/            bootstrap CIs, permutation null, HHI filter,
                             value-norm scan

Key reproduction pointers

Paper elementScript
Figure 1 (reliability gap)scripts/phase0_behavioral/eval_olmo3_sweep.py → plot_figure1_olmo3.py
Figure 2 (ghost heads)scripts/phase1_circuits/head_patching_dist.py × 4 ckpts → phase2_ghost/generate_paper_figures.py (figure2_ghost_heads)
Figure 3 (14-checkpoint trajectory)scripts/phase1_circuits/head_patching_dist.py × 14 ckpts → phase2_ghost/figure_ghost_trajectory.py
Figure 4 (answer-token patching)scripts/phase2_verification/verification_patching_temporal.py → figure_atp_v2.py
Table 1 (cross-task HHI + filter)scripts/analysis/hhi_signal_quality_recompute.py
Table 3 (ghost trajectory)scripts/phase1_circuits/head_patching_dist.py × 14 ckpts
Table 4 (cross-arch ghost heads)scripts/phase2_ghost/crossmodel_ghost_heads.py
Table 5 (seven MI tools)aggregated from individual probes (Appendices B, G, I, J)
Appendix B (transplant)scripts/phase2_transplant/weight_transplant_test.py
Appendix C (multi-step)scripts/phase2_cross_task/multistep_arithmetic.py
Appendix G/H (weight-diff geometry)scripts/phase2_transplant/crossmodel_weight_diff.py
Appendix I (noise fragility)scripts/phase2_transplant/noise_fragility_tasks.py
Appendix J (verifier reranking)scripts/phase2_transplant/rl_verify_experiment.py
Appendix N (threshold sweep)scripts/phase2_ghost/ghost_threshold_sensitivity.py
Appendix O (cross-model perm null)scripts/phase2_ghost/crossmodel_head_patching_base_rl.py → analysis/permutation_null_L31H13.py
Appendix P (L29.H5 paired bootstrap)scripts/analysis/bootstrap_l29h5_dose_response.py
Appendix Q (value-norm vs GhostScore)scripts/phase1_circuits/head_value_norms.py → analysis/value_norm_vs_ghostscore.py

A complete one-line-per-claim audit is in provenance.csv.

Anonymization notes

  • All scripts have been stripped of user paths, GPU device hardcodings, and internal log directories. Where a script accepted --device cuda:N it defaults to cuda:0 and accepts an override.
  • HuggingFace cache paths and Weights & Biases project names are not referenced anywhere in the bundle.
  • Git history is not included.

What's NOT in this bundle

  • Cached intermediate CSVs (~322 MB). Released with the camera-ready.
  • Raw model checkpoints (50+ GB). Download from HuggingFace using the model IDs hard-referenced in each script.
  • Behavioral pass@k evaluation logs (~5 GB). Aggregated CSVs released with camera-ready.
  • Pilot / abandoned experiments (~40 scripts that did not produce any number cited in the paper).
  • Internal status files, working notes.

unai-zulaika/ghost-heads

Python

0

1 commits

updated May 7, 2026

See the code

README

Release: Code for "Ghost Heads Across Training: When Greedy and Distributional Patching Disagree"

Anonymous code release accompanying the ICML 2026 Mechanistic Interpretability Workshop submission.

This repository contains the code to reproduce every figure, table, and load-bearing number in the paper.

Cached intermediate CSVs (~322 MB) will be released alongside the camera-ready / non-anonymous version of the paper. They are not included here because anonymous review platforms (anonymous.4open.science, etc.) are optimised for browsing source files, not for hosting hundreds of megabytes of patching outputs. The code in this repository is sufficient to re-derive every CSV from the public model checkpoints.

What this bundle is

A self-contained, anonymized, version-pinned set of scripts that:

  • Run pass@k behavioral evaluation on OLMo-3-7B / OLMo-2-7B (Phase 0).
  • Run head-level activation patching with both greedy and distributional metrics across 14 OLMo-3 checkpoints (Phase 1).
  • Replicate the ghost-head phenomenon on DeepSeek-Math-7B and Qwen2.5-Math-7B (Phase 2 / cross-arch).
  • Run the seven RL-Zero null probes (weight transplant, neuron overlap, weight-diff SVD, noise fragility, verifier reranking, cross-model patching).
  • Run answer-token patching on arithmetic, GSM8K, and MATH500 (Phase 2 / verification).
  • Compute every analysis number cited in the paper (bootstrap CIs, sign-flip permutation null over 1024 heads, threshold sensitivity, value-norm vs GhostScore).

What's needed to actually run

  • Python 3.10+, deps in requirements.txt.
  • A GPU with ≥ 24 GB VRAM (we used Quadro RTX 8000, 48 GB) and attn_implementation="eager" (no FlashAttention required).
  • The relevant HuggingFace model checkpoints:
    • allenai/Olmo-3-1025-7B
    • allenai/Olmo-3-7B-RL-Zero-Math (revisions: step_200, step_1000, step_1900)
    • All OLMo-3 stage-1, stage-2, stage-3 revisions (listed in each script's --revision choices)
    • allenai/OLMo-2-1124-7B (cross-model temporal replication)
    • deepseek-ai/deepseek-math-7b-base, Qwen/Qwen2.5-Math-7B (cross-architecture)
  • Patience: a full re-run of the 14-checkpoint head-patching sweep is ~50 GPU-hours.

Quickstart (one head-patching job, ~2 GPU-hours)

pip install -r requirements.txt

# Run head patching on OLMo-3 base for 3-digit arithmetic.
# Produces a CSV with greedy and distributional recovery per (layer, head).
python scripts/phase1_circuits/head_patching_dist.py \
    --checkpoint base \
    --device cuda:0 \
    -n 200 \
    --output head_patching_dist_base.csv

reproduce_all.sh exists as a tier-2 smoke-test pipeline (regenerates figures from cached CSVs + diff against committed PDF text-extracts), but it requires the cached CSVs that will ship with the camera-ready. Until then, run individual scripts directly.

Folder layout

release/
├── README.md                this file
├── provenance.csv           every paper claim → CSV → script → notes
├── requirements.txt         pinned Python deps
├── reproduce_all.sh         smoke-test pipeline (needs cached CSVs)
├── expected_checksums.txt   SHA256 of every CSV (for camera-ready verification)
├── figures/                 regenerated PDFs land here at run time
└── scripts/
    ├── phase0_behavioral/   pass@k evaluation, Figure 1
    ├── phase1_circuits/     head patching (greedy + distributional), value norms
    ├── phase2_cross_task/   GSM8K / MATH500 single-token patching, multi-step
    ├── phase2_ghost/        cross-architecture replication, threshold sweep,
    │                        cross-model base→RL patching, master figure script
    ├── phase2_transplant/   weight transplant, weight-diff geometry,
    │                        noise fragility, verifier reranking
    ├── phase2_verification/ answer-token patching, verification heads
    └── analysis/            bootstrap CIs, permutation null, HHI filter,
                             value-norm scan

Key reproduction pointers

Paper elementScript
Figure 1 (reliability gap)scripts/phase0_behavioral/eval_olmo3_sweep.py → plot_figure1_olmo3.py
Figure 2 (ghost heads)scripts/phase1_circuits/head_patching_dist.py × 4 ckpts → phase2_ghost/generate_paper_figures.py (figure2_ghost_heads)
Figure 3 (14-checkpoint trajectory)scripts/phase1_circuits/head_patching_dist.py × 14 ckpts → phase2_ghost/figure_ghost_trajectory.py
Figure 4 (answer-token patching)scripts/phase2_verification/verification_patching_temporal.py → figure_atp_v2.py
Table 1 (cross-task HHI + filter)scripts/analysis/hhi_signal_quality_recompute.py
Table 3 (ghost trajectory)scripts/phase1_circuits/head_patching_dist.py × 14 ckpts
Table 4 (cross-arch ghost heads)scripts/phase2_ghost/crossmodel_ghost_heads.py
Table 5 (seven MI tools)aggregated from individual probes (Appendices B, G, I, J)
Appendix B (transplant)scripts/phase2_transplant/weight_transplant_test.py
Appendix C (multi-step)scripts/phase2_cross_task/multistep_arithmetic.py
Appendix G/H (weight-diff geometry)scripts/phase2_transplant/crossmodel_weight_diff.py
Appendix I (noise fragility)scripts/phase2_transplant/noise_fragility_tasks.py
Appendix J (verifier reranking)scripts/phase2_transplant/rl_verify_experiment.py
Appendix N (threshold sweep)scripts/phase2_ghost/ghost_threshold_sensitivity.py
Appendix O (cross-model perm null)scripts/phase2_ghost/crossmodel_head_patching_base_rl.py → analysis/permutation_null_L31H13.py
Appendix P (L29.H5 paired bootstrap)scripts/analysis/bootstrap_l29h5_dose_response.py
Appendix Q (value-norm vs GhostScore)scripts/phase1_circuits/head_value_norms.py → analysis/value_norm_vs_ghostscore.py

A complete one-line-per-claim audit is in provenance.csv.

Anonymization notes

  • All scripts have been stripped of user paths, GPU device hardcodings, and internal log directories. Where a script accepted --device cuda:N it defaults to cuda:0 and accepts an override.
  • HuggingFace cache paths and Weights & Biases project names are not referenced anywhere in the bundle.
  • Git history is not included.

What's NOT in this bundle

  • Cached intermediate CSVs (~322 MB). Released with the camera-ready.
  • Raw model checkpoints (50+ GB). Download from HuggingFace using the model IDs hard-referenced in each script.
  • Behavioral pass@k evaluation logs (~5 GB). Aggregated CSVs released with camera-ready.
  • Pilot / abandoned experiments (~40 scripts that did not produce any number cited in the paper).
  • Internal status files, working notes.