Download docs/RUN_INDUCTION_GPU.md from suchirsalhan/beetle-phase-transition: direct link, hf CLI and curl.
- Browser
- Download file 5.73 kB
-
https://huggingface.co/datasets/suchirsalhan/beetle-phase-transition/resolve/main/docs/RUN_INDUCTION_GPU.md
- Command line
-
hf download hf://datasets/suchirsalhan/beetle-phase-transition/docs/RUN_INDUCTION_GPU.md
-
curl -L -o RUN_INDUCTION_GPU.md https://huggingface.co/datasets/suchirsalhan/beetle-phase-transition/resolve/main/docs/RUN_INDUCTION_GPU.md
Running the induction-head sweep on GPU
Port of Aoyama & Schneider (arXiv:2511.16893, github.com/t-aoyam/predict-ih) to the
Beetle pico_decoder models. Code lives in analyze/induction/. This computes the
mechanistic axis (induction-head formation across training) to pair with the
behavioural reading-time trajectories in phase-transition/figures/.
Everything below runs from the repo root on a CUDA box. It was developed and sanity-checked on MPS — see the validation numbers at the end.
0. Setup
pip install -e . # or: pip install -r requirements.txt
pip install datasets huggingface_hub transformers torch numpy pandas matplotlib
# Beetle repos ship NO AutoTokenizer config — fetch the shared BPE tokenizer once.
# (On some hosts hf_hub_download hits an httpx/brotli bug; curl avoids it.)
mkdir -p /tmp/beetle_tok
curl -sL -H "Accept-Encoding: identity" \
https://huggingface.co/Beetle-HumanScale/bpe-humanscale-eng-nld/resolve/main/tokenizer.json \
-o /tmp/beetle_tok/tokenizer.json
export TOKJSON=/tmp/beetle_tok/tokenizer.json
export HF_HUB_DISABLE_XET=1 # avoids the xet/brotli download path
Load path: models are
trust_remote_code=Truepico_decoder; the tokenizer is loaded fromtokenizer.jsonviaPreTrainedTokenizerFast(handled insidetrajectory.pywhen you pass--tokenizer-json).
1. Run the trajectory per curriculum (FineWeb-2B, nld-eng)
Each repo has ~15 checkpoint branches step-0 … step-4096(+). Drop --max-ckpts
on GPU to evaluate all checkpoints (recommended; it's cheap at 125M).
mkdir -p results/evals_paper/21_induction
for C in balanced-b1 l2-50-simultaneous-b2 l2-50-sequential-33-67-b3 \
l2-50-classroom-20-b4 l2-80-late-b5 ; do
python -m analyze.induction.trajectory \
--repo "Beetle-FineWeb-2B/beetle-bilingual-${C}-fineweb-2b-nld-eng" \
--tokenizer-json "$TOKJSON" \
--out "results/evals_paper/21_induction/ih_traj_${C}_2b.csv" \
--device cuda --num-samples 200 --batch-size 100
done
Per-checkpoint output columns: repo, curriculum, step, best_ps, mean_ps, n_induction_heads, ar_acc, ar_mean_rank, n_layers, n_heads. The script prints the
fitted emergence point (first knot of a 2-segment PWL fit on best-PS) per repo.
Other scales / pairs (optional, for RQ1 scale-agnosticism)
Swap the org/pair to replicate across regimes — the emergence law predicts the point is size-agnostic:
- 100M:
Beetle-FineWeb-100M/...-fineweb-100m-nld-eng - 24B:
Beetle-FineWeb/...-fineweb-nld-eng - other L1s:
...-2b-deu-eng,...-2b-zho-eng,...-2b-eus-eng,...-2b-hin-eng
2. Plot in the MECO / camera-ready style
python -m analyze.induction.plot_ih \
--csv "results/evals_paper/21_induction/ih_traj_*_2b.csv" \
--out camera_ready/figures/fig_ih_ps_traj_2b_1col \
--batch-size <BATCH> --context-size <CONTEXT> # for the predicted N_PT annotation
cp camera_ready/figures/fig_ih_ps_traj_2b_1col.* phase-transition/figures/
Fill <BATCH>/<CONTEXT> with the FineWeb-2B training config (from ../beetlelm
train configs) so the figure overlays the Aoyama predicted N_PT = T·B^0.63·C^0.38.
Output uses apply_acl_style + color_for_condition + savefig_pub — identical
style to the MECO figures.
3. The analyses this enables (RQ1–RQ3)
- RQ1 timing — compare fitted
emergence_stepacross curricula (does ordering shift when IHs form at fixed total exposure?). - RQ2 correspondence — overlay IH emergence step against the reading-time
(MECO Δloglik) inflection in
fig_meco_rt_alignment_traj_2b_1col. DoT_IH ≈ T_RT? - RQ3 path-dependence — at matched cumulative tokens (esp. the final checkpoint),
do curricula converge on the same
best_ps/n_induction_heads? Convergence ⇒ transient history-dependence; persistent gaps ⇒ path-dependence (the exciting one).
Join the IH CSV with the reading-time trajectory on step and reuse
analyze/xling/cr_pico_eval_correlations.py to correlate best_ps against
delta_loglik across checkpoints.
4. Method notes (faithfulness + adaptation)
- PS (prefix-matching): random UNIQUE tokens length
base_len=25, tiledrep=2→ length 50; PS(l,h) = mean over source positionsi∈[25,50)ofattn[i, i-(25-1)]. Matches TransformerLens|x|=50. - AR (associative recall): over the repeated half,
acc= fraction where the true next token is rank-0;mean_rank= mean rank. - Adaptation:
pico_decodercomputes attention withF.scaled_dot_product_attention(weights not returned), soih_metrics.capture_attentionmonkeypatches SDPA to recomputesoftmax(q·kᵀ·scale + attn_mask)and stash per-layer weights. Model-agnostic; works for any SDPA model. - LA (logit attribution) is not ported — it needs the model's
W_O/unembed path (get_logit_attributionin the referenceHookedTransformer). PS is what the paper reports in the main body; add LA later if needed.
5. Validation (already run, MPS)
Beetle-FineWeb/beetle-bilingual-balanced-b1-fineweb-nld-eng, num_samples=50:
| checkpoint | best_ps | n_induction_heads | ar_acc | ar_mean_rank |
|---|---|---|---|---|
main (trained) |
0.767 | 5 | 0.254 | 2,263 |
step-0 (init) |
0.028 (chance) | 0 | 0.000 | 25,625 (≈ V/2, random) |
Strong IHs in the trained model, none at init — the expected Olsson/Aoyama signature, confirming the port is correct. The GPU sweep above just extends this across every checkpoint and curriculum.
Note: a local MPS sweep was attempted but the box's HF downloads are unreliable (xet/brotli); run on GPU with the
HF_HUB_DISABLE_XET=1+ curl-tokenizer setup above.