{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c20d62fc",
   "metadata": {},
   "source": [
    "# The paper's evidence\n",
    "\n",
    "The claims C1–C7 of the digest, with the paper's numbers. The tables are transcribed once in the\n",
    "helper module ({doc}`code`) and compared with the paper's LaTeX below; every comparison stated in\n",
    "the text is computed from them. None of these numbers was re-measured by us unless a later chapter\n",
    "says so: they carry the tag **[paper]**, and the comparisons the tag **[num]**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69a68522",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "import sys, pathlib, math\n",
    "\n",
    "BOOK = next(p for p in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents] if (p / \"seminar_lib.py\").exists())\n",
    "sys.path.insert(0, str(BOOK))\n",
    "sys.dont_write_bytecode = True   # keep book/ free of __pycache__\n",
    "import seminar_lib as lib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10e87af6",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "report = lib.check_transcription()\n",
    "if report is None:\n",
    "    lib.note(\"Transcription check skipped\", \"The paper's LaTeX (`source/latex/`, git-ignored) is not present on \"\n",
    "             \"this machine, so the transcribed tables were not compared with it in this build.\")\n",
    "else:\n",
    "    lib.note(\"Transcription check\", \"The tables on this page were compared with the paper's LaTeX \"\n",
    "             \"(`source/latex/tables/`) during this build: \" +\n",
    "             \"; \".join(f\"{k}: {'identical' if v else '**differs**'}\" for k, v in report.items()) + \".\", \"tip\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea40edad",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert report is None or all(report.values())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b40185f",
   "metadata": {},
   "source": [
    "## C1 — the lowest perplexity among residual designs (§4.1, Table 1)\n",
    "\n",
    "Validation perplexity on 10M FineWeb-Edu tokens (by App. A.1, 4,096 sequences of 2,048 tokens,\n",
    "that is 8.4M), models trained at a fixed $R$; the learning rate\n",
    "was swept for PreNorm and Sandwich-Norm only (ARLoop and Parcae reuse PreNorm's, DeepLoop Sandwich-Norm's;\n",
    "App. A.1); one number per cell (no seed count stated), no intervals:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81391ea2",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "cols = [f\"{s} R={r}\" for s, r in lib.TAB1_COLS]\n",
    "best = [min(v[c] for v in lib.TAB1.values()) for c in range(len(cols))]\n",
    "lib.md(lib.table([(m, *[f\"**{x:.2f}**\" if x == best[c] else f\"{x:.2f}\" for c, x in enumerate(v)])\n",
    "                  for m, v in lib.TAB1.items()], [\"model\", *cols]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63ae5042",
   "metadata": {
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [],
   "source": [
    "ar, pn = lib.TAB1[\"ARLoop\"], lib.TAB1[\"PreNormLoop\"]\n",
    "gain = [a - p for a, p in zip(ar, pn)]\n",
    "margin = [a - min(v[c] for m, v in lib.TAB1.items() if m != \"ARLoop\") for c, a in enumerate(ar)]\n",
    "print(\"column        ARLoop − PreNormLoop   ARLoop − best other design\")\n",
    "for c, g, m in zip(cols, gain, margin):\n",
    "    print(f\"{c:<12}  {lib.signed(g)}                  {lib.signed(m)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "255b866e",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert all(m < 0 for m in margin)                                    # ARLoop strictly lowest in every column\n",
    "assert (f\"{-max(margin):.2f}\", f\"{-min(margin):.2f}\") == (\"0.11\", \"0.23\")\n",
    "assert [f\"{g:+.2f}\" for g in gain] == [\"-0.11\", \"-0.53\", \"-0.50\", \"-0.23\", \"-0.31\"]\n",
    "assert lib.quote_check(lib.DIGEST, \"learning rate swept for PreNorm and Sandwich-Norm only, ARLoop and Parcae reuse PreNorm's rate and DeepLoop reuses Sandwich-Norm's (App. A.1)\",\n",
    "                       \"One number per cell: the paper states no seed count\")\n",
    "assert lib.quote_check(lib.DIGEST, \"by App. A.1, 4,096 sequences of 2,048 tokens = 8.4M [num]\")\n",
    "assert f\"{4096 * 2048 / 1e6:.1f}\" == \"8.4\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d1d2071",
   "metadata": {},
   "source": [
    "ARLoop has the lowest perplexity in every column, by 0.11 to 0.23 over the best other design. Its\n",
    "perplexity is lower than PreNormLoop's by 0.11 at $R = 1$, 0.53 at $R = 3$ and 0.50 at $R = 5$ at\n",
    "140M, and by 0.23 and 0.31 at 370M. **[num]** The paper reads this as \"larger gains at deeper recurrences\". That holds\n",
    "against $R = 1$, but at 140M the gain at $R = 5$ is slightly smaller than at $R = 3$, so it is not\n",
    "monotone (finding F7 of the digest)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ded325fc",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "# F7: a larger gain is a more negative PPL difference\n",
    "assert gain[1] < gain[0] and gain[2] < gain[0] and gain[4] < gain[3]     # deeper beats R = 1 at both scales\n",
    "assert gain[2] > gain[1]                                                  # 140M: R = 5 gains less than R = 3\n",
    "assert lib.quote_check(lib.DIGEST, \"The paper's \\\"larger gains at deeper recurrences\\\" holds against R=1 but is not monotone\",\n",
    "                       \"the gain over PreNormLoop at 140M is −0.53 PPL at R=3 but −0.50 at R=5, so not monotone\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6317ee3f",
   "metadata": {},
   "source": [
    "## C2 — a sliding window is enough for loops (§4.1, Table 2)\n",
    "\n",
    "PreNorm, full-history depth attention and the sliding window (embedding + 3 most recent blocks),\n",
    "each trained at the $R$ of its row; perplexity and the average over the zero-shot downstream tasks:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45a5f6c9",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "rows = []\n",
    "for (scale, R), v in lib.TAB2.items():\n",
    "    lo, hi = min(v[\"ppl\"]), max(v[\"down\"])\n",
    "    rows.append((scale, R, *[f\"**{x:.2f}**\" if x == lo else f\"{x:.2f}\" for x in v[\"ppl\"]],\n",
    "                 *[f\"**{x:.2f}**\" if x == hi else f\"{x:.2f}\" for x in v[\"down\"]]))\n",
    "lib.md(lib.table(rows, [\"scale\", \"R\", \"PPL PreNorm\", \"PPL full\", \"PPL window\",\n",
    "                        \"downstream PreNorm\", \"downstream full\", \"downstream window\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fba38e23",
   "metadata": {
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [],
   "source": [
    "ppl_win = [k for k, v in lib.TAB2.items() if v[\"ppl\"][2] < v[\"ppl\"][1]]\n",
    "down_win = [k for k, v in lib.TAB2.items() if v[\"down\"][2] > v[\"down\"][1]]\n",
    "beats_prenorm_ppl = all(min(v[\"ppl\"][1:]) < v[\"ppl\"][0] and max(v[\"ppl\"][1:]) < v[\"ppl\"][0] for v in lib.TAB2.values())\n",
    "window_beats_prenorm_down = all(v[\"down\"][2] > v[\"down\"][0] for v in lib.TAB2.values())\n",
    "print(f\"window below full history in PPL: {len(ppl_win)} of {len(lib.TAB2)} rows\")\n",
    "print(f\"window above full history downstream: {len(down_win)} of {len(lib.TAB2)} rows:\",\n",
    "      \", \".join(f\"{sc} R={R}\" for sc, R in down_win))\n",
    "print(\"both attention variants below PreNorm in PPL in every row:\", beats_prenorm_ppl)\n",
    "print(\"window above PreNorm downstream in every row:\", window_beats_prenorm_down)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c0164a1f",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert len(ppl_win) == 5 and (\"140M\", 2) not in ppl_win\n",
    "assert sorted(down_win) == [(\"140M\", 2), (\"370M\", 2), (\"370M\", 3)]\n",
    "assert (\"140M\", 4) not in down_win and (\"370M\", 4) not in down_win\n",
    "assert beats_prenorm_ppl and window_beats_prenorm_down\n",
    "# the R = 3 rows are the same models as in Table 1\n",
    "for s in (\"140M\", \"370M\"):\n",
    "    c = lib.TAB1_COLS.index((s, 3))\n",
    "    assert lib.TAB2[(s, 3)][\"ppl\"][2] == lib.TAB1[\"ARLoop\"][c] and lib.TAB2[(s, 3)][\"ppl\"][0] == lib.TAB1[\"PreNormLoop\"][c]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a691557d",
   "metadata": {},
   "source": [
    "In perplexity the window beats full history in 5 of the 6 rows (all but 140M at $R = 2$), and both\n",
    "attention variants beat PreNorm everywhere. In the downstream average the picture is split: the\n",
    "window is ahead of full history in 3 rows (140M $R = 2$, 370M $R = 2$ and $R = 3$), full history in\n",
    "the other 3, including both $R = 4$ rows; the window is ahead of PreNorm in all 6. The $R = 3$ rows\n",
    "repeat Table 1's ARLoop and PreNormLoop entries. **[num]**\n",
    "\n",
    "The paper's explanation **[paper]**: depth attention is local (at sublayer 47 of the 140M, $R = 4$\n",
    "full-history model the 3 most recent blocks and the embedding receive 96% of the weight) and\n",
    "residual blocks of different loops are highly similar; in an untied stack of the same effective\n",
    "depth they are not, and the same window hurts there (App. A.5, Table 9). E1.4 measures the routing\n",
    "of the released 0.6B model ({doc}`tests/e1_release`).\n",
    "\n",
    "A condition, in the paper's own appendix (App. A.3, Table 7, and App. A.1) **[paper]**: the\n",
    "window's edge needs value residuals (the gated token embedding that the models add to the attention\n",
    "values at alternating layers). Trained without them (140M, $R = 3$), the window reaches a perplexity\n",
    "of 18.20, no better than PreNorm's 18.19, while full history keeps a lead (17.52). App. A.1 says so\n",
    "itself: \"removing value residuals substantially degrades our sliding-window depth-attention\n",
    "variant\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7f398be",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert lib.quote_check(lib.DIGEST, \"(App. A.5, Tab. 9). Condition [paper: App. A.3, Tab. 7, and App. A.1; finding F11]: the window's edge needs value residuals\",\n",
    "                       \"App. A.1 says so itself\",\n",
    "                       \"the sliding window reaches 18.20, no better than PreNorm's 18.19, while full history keeps a lead (17.52)\",\n",
    "                       \"removing value residuals substantially degrades our sliding-window depth-attention variant\")\n",
    "if (lib.LATEX / \"main\" / \"appendix.tex\").exists():          # the paper's Table 7, when the LaTeX is present\n",
    "    assert lib.quote_check(lib.LATEX / \"main\" / \"appendix.tex\", \"PreNorm & 18.19\", \"\\\\modelnamepl{} & \\\\textbf{17.52}\",\n",
    "                           \"\\\\modelnameplsw{} & 18.20\")\n",
    "assert lib.quote_check(lib.DIGEST, \"at sublayer 47 of the 140M R=4 full-history model\",\n",
    "                       \"the 3 most recent blocks + embedding get 96% of the mass\",\n",
    "                       \"in an untied stack of the same depth they are not, and the window hurts there\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "841e1f46",
   "metadata": {},
   "source": [
    "## C3 — the gains transfer to realistic pretraining (§5, Table 3)\n",
    "\n",
    "SmolLM-style three-stage recipe, context 4,096, grouped-query attention and SwiGLU; evaluation with\n",
    "lm-eval 0.4.12 {cite}`lmeval2024` (with vLLM, the default of the released evaluation code), BF16,\n",
    "greedy decoding up to 1,024 new tokens, no chat template; GSM8K {cite}`cobbe2021gsm8k` is\n",
    "`gsm8k_cot` 5-shot with flexible extract. Single checkpoints, no intervals. The rows kept in the digest:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7957193a",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "def fmt(x, score=False):\n",
    "    return \"–\" if x is None else (f\"{x:.1f}\" if score else f\"{x:g}\")\n",
    "lib.md(lib.table([(m, *[fmt(x) for x in v[:3]], *[fmt(x, True) for x in v[3:]]) for m, v in lib.TAB3.items()],\n",
    "                 [\"model\", \"default loops\", \"FLOPs (10²¹)\", \"tokens (T)\", *lib.BENCHMARKS]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1376601",
   "metadata": {
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [],
   "source": [
    "a, p = lib.scores(\"ARLoop-0.6B\"), lib.scores(\"PreNormLoop-0.6B\")\n",
    "delta = {k: round(a[k] - p[k], 1) for k in lib.BENCHMARKS}\n",
    "print(\"ARLoop-0.6B − PreNormLoop-0.6B:\")\n",
    "print(\"   \", \", \".join(f\"{k} {lib.signed(v, 1)}\" for k, v in delta.items()))\n",
    "for x, y in ((\"ARLoop-0.6B\", \"PreNormLoop-0.6B\"), (\"ARLoop-1.2B\", \"Huginn-3.5B\"),\n",
    "             (\"ARLoop-1.2B\", \"Qwen3.5-2B\"), (\"Ouro-1.4B\", \"ARLoop-1.2B\")):\n",
    "    w = lib.wins(x, y)\n",
    "    missing = [k for k in lib.BENCHMARKS if k not in w]\n",
    "    print(f\"{x} above {y} on {len(w)} of {len(lib.BENCHMARKS)}\" + (f\" (not on {', '.join(missing)})\" if missing else \"\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a020a6c",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert delta[\"GSM8K\"] == 5.2 and delta[\"MBPP\"] == 3.1 and delta[\"MATH\"] == 5.4 and delta[\"ARC-C\"] == -0.8\n",
    "assert lib.wins(\"ARLoop-0.6B\", \"PreNormLoop-0.6B\") == [k for k in lib.BENCHMARKS if k != \"ARC-C\"]\n",
    "assert len(lib.wins(\"ARLoop-1.2B\", \"Huginn-3.5B\")) == 8 and len(lib.wins(\"ARLoop-1.2B\", \"Qwen3.5-2B\")) == 8\n",
    "assert lib.wins(\"Ouro-1.4B\", \"ARLoop-1.2B\") == [k for k in lib.BENCHMARKS if k != \"OBQA\"]\n",
    "assert lib.TAB3[\"PreNormLoop-0.6B\"][:3] == lib.TAB3[\"ARLoop-0.6B\"][:3] == [3, 2, 0.18]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48d93b1c",
   "metadata": {},
   "source": [
    "At 0.6B the matched pair has the same loops, FLOPs and tokens. ARLoop-0.6B is ahead on 7 of 8\n",
    "tasks, behind only on ARC-C (−0.8); the largest gains are on math and code: GSM8K +5.2, MATH +5.4,\n",
    "MBPP +3.1. ARLoop-1.2B is ahead of Huginn-3.5B and of Qwen3.5-2B on all 8 tasks; Ouro-1.4B (open\n",
    "weights, 7.7T tokens) is ahead of ARLoop-1.2B on 7 of 8, all but OpenBookQA; the paper attributes\n",
    "this to data. **[num]**\n",
    "\n",
    "Context for reading the rows (finding F2 of the digest, read in the released training\n",
    "configuration): the stage-3 mixture, from 80% of training on, contains Dolmino `math/gsm8k`\n",
    "(weight $10^{-4}$) and GSM-style synthetic sets. Both 0.6B models were trained on it, so the pair\n",
    "comparison is fair; comparisons with Huginn or Qwen mix architecture with data. E1.1 and E1.2\n",
    "re-measure GSM8K for the pair and for the 1.2B model ({doc}`tests/e1_release`). **[code]**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "657c29ee",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert lib.quote_check(lib.DIGEST, \"SmolLM-style 3-stage recipe\", \"GQA + SwiGLU, context 4,096\",\n",
    "                       \"lm-eval 0.4.12 (vLLM backend), BF16, greedy ≤ 1,024 new tokens\",\n",
    "                       \"Dolmino `math/gsm8k` (weight 1e-4) and GSM-style synthetic sets\",\n",
    "                       \"Ouro-1.4B (open weights, not open data) is ahead on 7 of 8\",\n",
    "                       \"`README.md` l. 144 (vLLM)\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4bbfc650",
   "metadata": {},
   "source": [
    "## C4 — later loops contribute more in ARLoop (§5.1, Figure 4)\n",
    "\n",
    "With the layer-effect metric of {cite}`csordas2025depth` on 50 MATH items, layers of loops 2 and 3\n",
    "change later representations more in ARLoop-0.6B than in PreNormLoop-0.6B. **[paper]** We have not\n",
    "re-measured this (it would be the optional check E1.5)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fbe127c5",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert lib.quote_check(lib.DIGEST, \"## 6. Claim C4 — later loops contribute more in ARLoop (§5.1, Fig. 4; App. C) [paper]\")\n",
    "assert lib.quote_check(lib.DIGEST, \"Layer-effect metric of Csordás et al. on 50 MATH items: layers of loops 2–3 change later representations more in ARLoop-0.6B than in PreNormLoop-0.6B\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bd3d4eb",
   "metadata": {},
   "source": [
    "## C5 — fixed recurrence beats a random one at $R = 4$ (§6, App. D.1)\n",
    "\n",
    "Full-history ARLoop trained at a fixed $R = 4$ against the same model trained with a random\n",
    "recurrence, drawn per sequence or per batch as\n",
    "\n",
    "$$\n",
    "\\tilde R \\sim \\operatorname{Poisson}(4), \\qquad R = \\min\\big(4, \\max(1, \\tilde R)\\big),\n",
    "$$\n",
    "\n",
    "FLOP-matched, evaluated at $R = 4$ (validation perplexity) **[paper]**:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1efadd3",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [],
   "source": [
    "TAB_DYN = {\"140M\": (16.07, 16.69, 16.52), \"370M\": (12.01, 12.33, 12.36)}   # digest §7 (C5)\n",
    "lib.md(lib.table([(s, *[f\"{x:.2f}\" for x in v]) for s, v in TAB_DYN.items()],\n",
    "                 [\"scale\", \"fixed R = 4\", \"Poisson per sequence\", \"Poisson per batch\"]))\n",
    "p = {k: math.exp(-4) * 4 ** k / math.factorial(k) for k in range(4)}\n",
    "dist = {1: p[0] + p[1], 2: p[2], 3: p[3], 4: 1 - sum(p.values())}\n",
    "mean_R = sum(r * q for r, q in dist.items())\n",
    "print(\"distribution of the clamped draw:\", {r: round(q, 3) for r, q in dist.items()})\n",
    "print(f\"mean R = {mean_R:.2f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e426851",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert lib.quote_check(lib.DIGEST, \"140M: PPL 16.07 (fixed) vs 16.69 (per-sequence Poisson) vs 16.52 (per-batch); 370M: 12.01 vs 12.33 vs 12.36\")\n",
    "assert all(v[0] < min(v[1:]) for v in TAB_DYN.values())\n",
    "assert abs(sum(dist.values()) - 1) < 1e-12 and f\"{dist[4]:.3f}\" == \"0.567\" and f\"{mean_R:.2f}\" == \"3.24\"\n",
    "assert TAB_DYN[\"140M\"][0] == lib.TAB2[(\"140M\", 4)][\"ppl\"][1] and TAB_DYN[\"370M\"][0] == lib.TAB2[(\"370M\", 4)][\"ppl\"][1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "364a1d54",
   "metadata": {},
   "source": [
    "Fixed recurrence wins at both scales. The clamp makes the \"random\" models mostly deep: a draw\n",
    "lands on $R = 4$ with probability 0.567, and the mean recurrence is 3.24 **[num]**. The fixed-$R$\n",
    "numbers are the full-history $R = 4$ entries of Table 2. This matters for our own work: `latent`'s\n",
    "random-depth arm drew from $\\{1, 2, 4\\}$, and E3's `random124` arm does the same.\n",
    "\n",
    "## C6 — no extrapolation beyond the trained recurrence (§6, App. D.2)\n",
    "\n",
    "The per-sequence Poisson **full-history** 140M and 370M models (trained with $R \\le 4$) are\n",
    "evaluated at $R = 1, \\dots, 8$; the queries for unseen depths are initialised at random and trained\n",
    "on 0.5B tokens with everything else frozen. Perplexity does not improve beyond $R = 4$: performance\n",
    "rises up to the trained recurrence and not beyond, even with depth queries trained for the new\n",
    "depths {cite}`arloop2026`. **[paper]**\n",
    "\n",
    "Scope (finding F4 of the digest): this rests on those models, not on the released ones. The\n",
    "released fixed-$R$ sliding-window models were not swept, and they have no routing parameters\n",
    "(queries or norms) at all for a fourth loop ({doc}`mechanism/m2_parameters`). E1.3 sweeps the released models under declared rules\n",
    "({doc}`tests/e1_release`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd8859b4",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert lib.quote_check(lib.DIGEST, \"queries for unseen depths are randomly initialised and trained on 0.5B tokens with everything else frozen\",\n",
    "                       \"PPL does not improve beyond R = 4\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac806603",
   "metadata": {},
   "source": [
    "## C7 — cost (§6, Table 4)\n",
    "\n",
    "Same training memory as PreNorm; training throughput at $R = 4$ on one H100 lower by about 15%\n",
    "(full history) and 10% (window), on average over the four model sizes. **[paper]** For the 0.6B model the paper reports 28.9k tokens per\n",
    "second for PreNorm and 25.9k for the window:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab815801",
   "metadata": {
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [],
   "source": [
    "slow = 25.9 / 28.9 - 1\n",
    "reads = max(len(rec[\"labels\"]) for rec in lib.schedule(lib.config(\"ARLoop-0.6B\")))\n",
    "print(f\"0.6B, window: {lib.signed(100 * slow, 1)}% throughput\")\n",
    "print(f\"sources read per routing call: at most {reads}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f728252e",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "assert lib.quote_check(lib.DIGEST, \"training throughput −15% (full history) and −10% (window) at R = 4 on one H100 (0.6B: 28.9k → 25.9k tokens/s)\")\n",
    "assert f\"{100 * slow:+.1f}\" == \"-10.4\" and reads == 4\n",
    "assert lib.quote_check(lib.DIGEST, \"≈12k GPU-h for the controlled study\",\n",
    "                       \"The two percentages are the paper's averages over the four model sizes of Tab. 4\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d904df62",
   "metadata": {},
   "source": [
    "That is −10.4% for the 0.6B model with the window **[num]**; with the window every routing call\n",
    "reads at most 4 stored sources ({doc}`mechanism/m1_window`). The controlled study took about 12k\n",
    "GPU-hours **[paper]**; none of it was re-run here."
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "default_lexer": "ipython3"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
