From 0f2e9bbc625e82936c3a308b76ea5032550fa628 Mon Sep 17 00:00:00 2001 From: degenfabian Date: Mon, 18 Aug 2025 17:17:01 +0200 Subject: [PATCH 1/8] updated loading in Activation Patching in TL Demo to use transformer bridge --- .github/workflows/checks.yml | 2 +- demos/Activation_Patching_in_TL_Demo.ipynb | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 1b32e1a1a5..51c9c61e43 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -223,7 +223,7 @@ jobs: fail-fast: false matrix: notebook: - # - "Activation_Patching_in_TL_Demo" + - "Activation_Patching_in_TL_Demo" # - "Attribution_Patching_Demo" - "ARENA_Content" - "BERT" diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index abc033ad70..7c66a0750b 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -121,17 +121,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import transformer_lens\n", "import transformer_lens.utils as utils\n", - "from transformer_lens.hook_points import (\n", - " HookedRootModule,\n", - " HookPoint,\n", - ") # Hooking utilities\n", - "from transformer_lens import HookedTransformer, HookedTransformerConfig, FactoredMatrix, ActivationCache" + "from transformer_lens.model_bridge import TransformerBridge" ] }, { @@ -197,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -216,7 +212,8 @@ } ], "source": [ - "model = HookedTransformer.from_pretrained(\"gpt2-small\")" + "model = TransformerBridge.boot_transformers(\"gpt2\")\n", + "model.enable_compatibility_mode()" ] }, { @@ -944,7 +941,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -956,7 +953,8 @@ } ], "source": [ - "attn_only = HookedTransformer.from_pretrained(\"attn-only-2l\")\n", + "attn_only = TransformerBridge.boot_transformers(\"attn-only-2l\")\n", + "attn_only.enable_compatibility_mode()\n", "batch = 4\n", "seq_len = 20\n", "rand_tokens_A = torch.randint(100, 10000, (batch, seq_len)).to(attn_only.cfg.device)\n", From da2641eebf42802f14fc3c45a1ac3fdffced906e Mon Sep 17 00:00:00 2001 From: degenfabian Date: Tue, 19 Aug 2025 18:28:49 +0200 Subject: [PATCH 2/8] use undeprecated ipython code to avoid deprecation warnings --- demos/Activation_Patching_in_TL_Demo.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index 7c66a0750b..29df03f128 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -67,7 +67,7 @@ " from IPython import get_ipython\n", "\n", " ipython = get_ipython()\n", - " # Code to automatically update the HookedTransformer code as its edited without restarting the kernel\n", + " # Code to automatically update the TransformerBridge code as its edited without restarting the kernel\n", " ipython.run_line_magic(\"load_ext\", \"autoreload\")\n", " ipython.run_line_magic(\"autoreload\", \"2\")" ] From b4ffb4cc2c959a8a0a306465a3472253dfa856ea Mon Sep 17 00:00:00 2001 From: Fabian Degen <106864199+degenfabian@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:46:26 +0200 Subject: [PATCH 3/8] revert metadata changes --- demos/Activation_Patching_in_TL_Demo.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index 29df03f128..13f6d685a7 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -121,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -193,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -941,7 +941,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [ { From 9f0ed00cf3016eec0a13e4ac1675d90f16a7df34 Mon Sep 17 00:00:00 2001 From: Bryce Meyer Date: Thu, 16 Oct 2025 16:21:29 +0200 Subject: [PATCH 4/8] updated installation source --- demos/Activation_Patching_in_TL_Demo.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index 13f6d685a7..9cd5b3991e 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -58,7 +58,7 @@ " import google.colab\n", " IN_COLAB = True\n", " print(\"Running as a Colab notebook\")\n", - " %pip install git+https://github.com/TransformerLensOrg/TransformerLens.git\n", + " %pip install transformer_lens\n", " # Install my janky personal plotting utils\n", " %pip install git+https://github.com/neelnanda-io/neel-plotly.git\n", "except:\n", From fe86b711266fac856674c384544bca46e3b3b3ef Mon Sep 17 00:00:00 2001 From: jlarson4 Date: Fri, 27 Feb 2026 10:51:54 -0600 Subject: [PATCH 5/8] Fix notebook CI: skip widget MIME type comparison and clear stale cell output Add application/vnd.jupyter.widget-view+json to conftest.py skip_compare to avoid false failures from random widget model_id values. Clear outputs from unrun cell (execution_count=null) in Activation Patching demo. Co-Authored-By: Claude Opus 4.6 --- demos/Activation_Patching_in_TL_Demo.ipynb | 10 +--------- demos/conftest.py | 1 + 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index 9cd5b3991e..c77eba6ac9 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -42,15 +42,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Running as a Jupyter notebook - intended for development only!\n" - ] - } - ], + "outputs": [], "source": [ "# Janky code to do different setup when run in a Colab notebook vs VSCode\n", "DEBUG_MODE = False\n", diff --git a/demos/conftest.py b/demos/conftest.py index 2cd3d5a3e8..755a204466 100644 --- a/demos/conftest.py +++ b/demos/conftest.py @@ -5,4 +5,5 @@ def pytest_collectstart(collector): "text/html", "application/javascript", "application/vnd.plotly.v1+json", # Plotly + "application/vnd.jupyter.widget-view+json", # Jupyter widgets (random model_id) ) From 12ff3a2f2f3c598695ac95c07f5e6bd7b6aa1270 Mon Sep 17 00:00:00 2001 From: jlarson4 Date: Thu, 5 Mar 2026 08:06:04 -0600 Subject: [PATCH 6/8] Neel Plotly import does not run in CI --- demos/Activation_Patching_in_TL_Demo.ipynb | 84 +++++++++++++--------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index c77eba6ac9..21991d91ff 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -163,7 +163,14 @@ "metadata": {}, "outputs": [], "source": [ - "from neel_plotly import line, imshow, scatter" + "try:\n", + " from neel_plotly import line, imshow, scatter\n", + "except ImportError:\n", + " # neel_plotly is an optional visualization dependency.\n", + " # Define no-op stubs so patching computations still run without it.\n", + " def line(*args, **kwargs): pass\n", + " def imshow(*args, **kwargs): pass\n", + " def scatter(*args, **kwargs): pass" ] }, { @@ -189,17 +196,24 @@ "metadata": {}, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "Using pad_token, but it is not set yet.\n" - ] + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "3040c20b4d87433bbdc4897d1e59b8e7", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Loading weights: 0%| | 0/148 [00:00\n", "\n", "
\n", - "
\n", + " }) }; \n", "\n", "" ] @@ -422,7 +436,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "49d0b56fa468408ca15afa42d0d1c91b", + "model_id": "bd2849621acf4ba2a5f6b5cfc6aa68d6", "version_major": 2, "version_minor": 0 }, @@ -440,9 +454,9 @@ "\n", "\n", "
\n", - "
\n", + " }) }; \n", "\n", "" ] @@ -498,7 +512,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "04132888196746f3b16918c63dd6c023", + "model_id": "3b902ce3c31a45e0854b43eadff198d5", "version_major": 2, "version_minor": 0 }, @@ -516,9 +530,9 @@ "\n", "\n", "
\n", - "
\n", + " }) }; \n", "\n", "" ] @@ -579,7 +593,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "9dec177dd2f446248b5850e149fab8fc", + "model_id": "440041cdc83b4bc3b1f991cefa1df6f4", "version_major": 2, "version_minor": 0 }, @@ -593,7 +607,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "ec9aae8965c84a819fcf6158dbc45fa6", + "model_id": "05b1394ee4a54d8e94050197279d2a11", "version_major": 2, "version_minor": 0 }, @@ -607,7 +621,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "caaf63fc68224f4babc8f492d55785e2", + "model_id": "4f5b66701221464580ccc06f25d257e0", "version_major": 2, "version_minor": 0 }, @@ -625,9 +639,9 @@ "\n", "\n", "
\n", - "
\n", + " }) }; \n", "\n", "" ] @@ -678,7 +692,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "997da4ffc80c4a87a827ab16aa1b76d7", + "model_id": "fd46410602d648ecb4d8e5c603f599c7", "version_major": 2, "version_minor": 0 }, @@ -692,7 +706,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "c71892621747426b8f69dc36dcee104e", + "model_id": "898ce7b338ec42b692974fb4af3d3d3a", "version_major": 2, "version_minor": 0 }, @@ -706,7 +720,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "1df77d7824f44ba58a08f37129cc7722", + "model_id": "a202d7fa0e894969b6093823c3a07900", "version_major": 2, "version_minor": 0 }, @@ -720,7 +734,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "fd3be25d4cd04a3bbbbec2c24a7b9d6b", + "model_id": "07f6b5419b414d739882be1135a0ac26", "version_major": 2, "version_minor": 0 }, @@ -734,7 +748,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "fc48b4abdc40412387bbea701ce028ed", + "model_id": "487f335aa1fb4f0a93c04944fcae2918", "version_major": 2, "version_minor": 0 }, @@ -752,9 +766,9 @@ "\n", "\n", "
\n", - "
\n", + " }) }; \n", "\n", "" ] From f54af4ff069d4db183960fff97ffe97823a3023e Mon Sep 17 00:00:00 2001 From: jlarson4 Date: Thu, 5 Mar 2026 08:38:37 -0600 Subject: [PATCH 7/8] Extend processing time for slow cell --- demos/Activation_Patching_in_TL_Demo.ipynb | 118 ++------------------- 1 file changed, 6 insertions(+), 112 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index 21991d91ff..154b1d2fcd 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -808,119 +808,13 @@ }, { "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "92709c396fdd48a7b169b87cc40d4ac2", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0/2160 [00:00\n", - "\n", - "\n", - "
\n", - "
\n", - "\n", - "" - ] - }, - "metadata": {}, - "output_type": "display_data" + "execution_count": null, + "metadata": { + "nbval": { + "cell_timeout": 600 } - ], + }, + "outputs": [], "source": [ "if DO_SLOW_RUNS:\n", " every_head_act_patch_result = patching.get_act_patch_attn_head_by_pos_every(model, corrupted_tokens, clean_cache, ioi_metric)\n", From d4ffcb20aa69bcb73ecf75890f345faec1b2d456 Mon Sep 17 00:00:00 2001 From: jlarson4 Date: Thu, 5 Mar 2026 10:40:02 -0600 Subject: [PATCH 8/8] Added NBVAL_SKIP for long running process that cant pass CI --- demos/Activation_Patching_in_TL_Demo.ipynb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/demos/Activation_Patching_in_TL_Demo.ipynb b/demos/Activation_Patching_in_TL_Demo.ipynb index 154b1d2fcd..98e554445f 100644 --- a/demos/Activation_Patching_in_TL_Demo.ipynb +++ b/demos/Activation_Patching_in_TL_Demo.ipynb @@ -809,13 +809,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "nbval": { - "cell_timeout": 600 - } - }, + "metadata": {}, "outputs": [], "source": [ + "# 10,800 forward passes of GPT-2; too slow for CI without GPU\n", + "# NBVAL_SKIP\n", "if DO_SLOW_RUNS:\n", " every_head_act_patch_result = patching.get_act_patch_attn_head_by_pos_every(model, corrupted_tokens, clean_cache, ioi_metric)\n", " every_head_act_patch_result = einops.rearrange(every_head_act_patch_result, \"act_type layer pos head -> act_type (layer head) pos\")\n",