summaryrefslogtreecommitdiff
path: root/notebooks
diff options
context:
space:
mode:
Diffstat (limited to 'notebooks')
-rw-r--r--notebooks/build_notebook.py9
-rw-r--r--notebooks/recursive_reasoning_chaos.ipynb33
2 files changed, 24 insertions, 18 deletions
diff --git a/notebooks/build_notebook.py b/notebooks/build_notebook.py
index 8a525b2..930dc68 100644
--- a/notebooks/build_notebook.py
+++ b/notebooks/build_notebook.py
@@ -35,7 +35,10 @@ md("## 0. Setup")
code("""%pip install -q torch einops pydantic huggingface_hub numpy matplotlib tqdm
import numpy as np, matplotlib.pyplot as plt, torch
from tqdm.auto import tqdm
-print("torch", torch.__version__, "| cuda", torch.cuda.is_available())""")
+print("torch", torch.__version__, "| cuda", torch.cuda.is_available())
+if not torch.cuda.is_available():
+ print("\\n⚠️ No GPU detected — the JVP/rollout cells will be SLOW on CPU.")
+ print(" Colab: Runtime → Change runtime type → Hardware accelerator → GPU (T4), then re-run.")""")
md(f"""## 1. Load a trained model from HuggingFace
@@ -126,7 +129,7 @@ def leading_ftle(inp, lab, pid, n=128, n_seg=16, seed=0):
ok=(((inner.lm_head(zH)[:,pe:].float().argmax(-1)==Y)|~m).all(-1)).cpu().numpy()
return ftle, ok
-ftle, succ = leading_ftle(inp, lab, pid, n=128)
+ftle, succ = leading_ftle(inp, lab, pid, n=64) # n=64 already separates cleanly; raise for tighter histograms
print(f"success rate {succ.mean():.2f} | median λ1 success {np.median(ftle[succ]):+.4f} vs failure {np.median(ftle[~succ]):+.4f}")
print(f"AUC(-λ1 -> success) = {auc(-ftle, succ.astype(int)):.3f} (>0.5 means failures are more chaotic)")
plt.figure(figsize=(6,4))
@@ -163,7 +166,7 @@ code("""def extended_rollout(inp, lab, pid, n=256, n_seg=128, seed=0):
zH=Hmod(zH, zL, **si)
p=inner.lm_head(zH)[:,pe:].float().argmax(-1)
EX.append(((p==Y)|~m).all(-1).float().cpu().numpy())
- DR.append((torch.zeros(n) if prev is None else (zH-prev).float().flatten(1).norm(1).cpu()).numpy())
+ DR.append((torch.zeros(n) if prev is None else (zH-prev).float().flatten(1).norm(dim=1).cpu()).numpy())
prev=zH.detach()
return np.stack(EX,1), np.stack(DR,1)
diff --git a/notebooks/recursive_reasoning_chaos.ipynb b/notebooks/recursive_reasoning_chaos.ipynb
index 1f00628..c9e96a9 100644
--- a/notebooks/recursive_reasoning_chaos.ipynb
+++ b/notebooks/recursive_reasoning_chaos.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "f991b29d",
+ "id": "9ed15c04",
"metadata": {},
"source": [
"# Recursive Reasoning Failures are Chaotic\n",
@@ -27,7 +27,7 @@
},
{
"cell_type": "markdown",
- "id": "bb82e0a8",
+ "id": "f9d8321d",
"metadata": {},
"source": [
"## 0. Setup"
@@ -36,19 +36,22 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "89a96776",
+ "id": "ea63e86f",
"metadata": {},
"outputs": [],
"source": [
"%pip install -q torch einops pydantic huggingface_hub numpy matplotlib tqdm\n",
"import numpy as np, matplotlib.pyplot as plt, torch\n",
"from tqdm.auto import tqdm\n",
- "print(\"torch\", torch.__version__, \"| cuda\", torch.cuda.is_available())"
+ "print(\"torch\", torch.__version__, \"| cuda\", torch.cuda.is_available())\n",
+ "if not torch.cuda.is_available():\n",
+ " print(\"\\n⚠️ No GPU detected — the JVP/rollout cells will be SLOW on CPU.\")\n",
+ " print(\" Colab: Runtime → Change runtime type → Hardware accelerator → GPU (T4), then re-run.\")"
]
},
{
"cell_type": "markdown",
- "id": "bbd25841",
+ "id": "1da5260b",
"metadata": {},
"source": [
"## 1. Load a trained model from HuggingFace\n",
@@ -61,7 +64,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f6a83ba0",
+ "id": "d1821039",
"metadata": {},
"outputs": [],
"source": [
@@ -94,7 +97,7 @@
},
{
"cell_type": "markdown",
- "id": "086e411f",
+ "id": "e0b10696",
"metadata": {},
"source": [
"## 2. The core result — failures are more chaotic (leading FTLE / λ₁)\n",
@@ -112,7 +115,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "791d02dc",
+ "id": "01a845b8",
"metadata": {},
"outputs": [],
"source": [
@@ -164,7 +167,7 @@
" ok=(((inner.lm_head(zH)[:,pe:].float().argmax(-1)==Y)|~m).all(-1)).cpu().numpy()\n",
" return ftle, ok\n",
"\n",
- "ftle, succ = leading_ftle(inp, lab, pid, n=128)\n",
+ "ftle, succ = leading_ftle(inp, lab, pid, n=64) # n=64 already separates cleanly; raise for tighter histograms\n",
"print(f\"success rate {succ.mean():.2f} | median λ1 success {np.median(ftle[succ]):+.4f} vs failure {np.median(ftle[~succ]):+.4f}\")\n",
"print(f\"AUC(-λ1 -> success) = {auc(-ftle, succ.astype(int)):.3f} (>0.5 means failures are more chaotic)\")\n",
"plt.figure(figsize=(6,4))\n",
@@ -178,7 +181,7 @@
},
{
"cell_type": "markdown",
- "id": "25aa2620",
+ "id": "36e16b8f",
"metadata": {},
"source": [
"## 3. Why — transient chaos: failures *escape* with more compute\n",
@@ -192,7 +195,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "106f13d3",
+ "id": "6603b85d",
"metadata": {},
"outputs": [],
"source": [
@@ -216,7 +219,7 @@
" zH=Hmod(zH, zL, **si)\n",
" p=inner.lm_head(zH)[:,pe:].float().argmax(-1)\n",
" EX.append(((p==Y)|~m).all(-1).float().cpu().numpy())\n",
- " DR.append((torch.zeros(n) if prev is None else (zH-prev).float().flatten(1).norm(1).cpu()).numpy())\n",
+ " DR.append((torch.zeros(n) if prev is None else (zH-prev).float().flatten(1).norm(dim=1).cpu()).numpy())\n",
" prev=zH.detach()\n",
" return np.stack(EX,1), np.stack(DR,1)\n",
"\n",
@@ -234,7 +237,7 @@
},
{
"cell_type": "markdown",
- "id": "306d11c9",
+ "id": "32c11219",
"metadata": {},
"source": [
"## 4. Basin accessibility — input-determined or initial-condition-determined?\n",
@@ -249,7 +252,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "682927dd",
+ "id": "53a705d1",
"metadata": {},
"outputs": [],
"source": [
@@ -296,7 +299,7 @@
},
{
"cell_type": "markdown",
- "id": "22ef7f6f",
+ "id": "6ca89f3b",
"metadata": {},
"source": [
"## What this shows\n",