{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "55300ce1",
   "metadata": {},
   "source": [
    "# Test the training stack\n",
    "\n",
    "An invoice shows an amount due that differs from the sum of its lines and tax. Does the model copy\n",
    "the printed value? Test whether a preference stage helps reward training preserve it.\n",
    "\n",
    "Use one supervised anchor and a matched two-by-two comparison. Choose the reward learning rate on\n",
    "separate development families and reuse the same rollout budget in both scored GRPO arms.\n",
    "\n",
    "Select **T4 GPU** in Colab and run all cells in order. Allow 45\u201365 minutes as a planning estimate.\n",
    "The one-update preflight runs before the full fits. Read its memory and time measurements first.\n",
    "\n",
    "[Read the lesson](https://docs.recohut.com/courses/advanced-llm-fine-tuning/2-compare-training-stages/06-test-the-training-stack)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a09f04e",
   "metadata": {},
   "source": [
    "## 0. Environment\n",
    "\n",
    "Install the pinned training libraries and retain Colab's CUDA PyTorch build. The receipt records\n",
    "the trainer package, PyTorch and CUDA versions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f92bc906",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CompletedProcess(args=['/usr/bin/python3', '-m', 'pip', 'install', '-q', 'transformers==4.51.3', 'peft==0.15.2', 'trl==0.19.1', 'accelerate==1.6.0', 'datasets==3.6.0'], returncode=0)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import subprocess\n",
    "import sys\n",
    "\n",
    "TRAINER_PINS = {'transformers': '4.51.3', 'peft': '0.15.2', 'trl': '0.19.1', 'accelerate': '1.6.0', 'datasets': '3.6.0'}\n",
    "pins = [f\"{name}=={version}\" for name, version in TRAINER_PINS.items()]\n",
    "subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", *pins], check=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a0d9204",
   "metadata": {},
   "source": [
    "## 1. Invoice catalog\n",
    "\n",
    "The synthetic catalog supplies split labels and expected records for scoring. The model prompt\n",
    "contains the extraction contract and visible invoice text."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ea2365ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Versioned synthetic invoices and independent record scoring for the course.\"\"\"\n",
    "\n",
    "from __future__ import annotations\n",
    "\n",
    "import json\n",
    "import random\n",
    "import re\n",
    "from collections import Counter\n",
    "from dataclasses import dataclass\n",
    "from datetime import date, timedelta\n",
    "from typing import Any\n",
    "\n",
    "CATALOG_VERSION = \"course-invoice-v1\"\n",
    "SPLIT_SIZES = {\"train\": 576, \"dev\": 72, \"familiar\": 96, \"novel\": 96, \"independent\": 48, \"release\": 120}\n",
    "VISIBLE_CONTRACT = (\n",
    "    \"Extract exactly one JSON object with invoice_id, issued_on (YYYY-MM-DD), supplier, \"\n",
    "    \"currency (ISO code), line_items (description, quantity, unit_minor), subtotal_minor, \"\n",
    "    \"tax_minor, and total_minor. Preserve line order and convert currency amounts to integer cents. \"\n",
    "    \"Use null only for a missing or ambiguous field. Do not rewrite printed amounts, invent fields, or add explanations.\"\n",
    ")\n",
    "\n",
    "@dataclass(frozen=True)\n",
    "class Line:\n",
    "    description: str\n",
    "    quantity: int\n",
    "    unit_minor: int\n",
    "\n",
    "\n",
    "@dataclass(frozen=True)\n",
    "class Invoice:\n",
    "    key: str\n",
    "    family: str\n",
    "    supplier: str\n",
    "    issued_on: str\n",
    "    currency: str\n",
    "    items: tuple[Line, ...]\n",
    "    tax_minor: int | None\n",
    "    locale: str\n",
    "    split: str\n",
    "    layout: str = \"register\"\n",
    "    printed_total_minor: int | None = None\n",
    "\n",
    "\n",
    "def invoice_record(invoice: Invoice) -> dict[str, Any]:\n",
    "    subtotal = sum(line.quantity * line.unit_minor for line in invoice.items)\n",
    "    total = subtotal + invoice.tax_minor if invoice.tax_minor is not None else None\n",
    "    if invoice.printed_total_minor is not None:\n",
    "        total = invoice.printed_total_minor\n",
    "    return {\n",
    "        \"invoice_id\": invoice.key,\n",
    "        \"issued_on\": invoice.issued_on,\n",
    "        \"supplier\": invoice.supplier,\n",
    "        \"currency\": invoice.currency,\n",
    "        \"line_items\": [\n",
    "            {\"description\": item.description, \"quantity\": item.quantity, \"unit_minor\": item.unit_minor}\n",
    "            for item in invoice.items\n",
    "        ],\n",
    "        \"subtotal_minor\": subtotal,\n",
    "        \"tax_minor\": invoice.tax_minor,\n",
    "        \"total_minor\": total,\n",
    "    }\n",
    "\n",
    "\n",
    "def make_catalog() -> list[Invoice]:\n",
    "    rng = random.Random(20261126)\n",
    "    sources = {\n",
    "        \"train\": (24, (\"register\", \"memo\", \"checkout\", \"ledger\")),\n",
    "        \"dev\": (6, (\"register\", \"memo\", \"checkout\", \"ledger\")),\n",
    "        \"familiar\": (8, (\"register\", \"memo\", \"checkout\", \"ledger\")),\n",
    "        \"novel\": (8, (\"packing\", \"remittance\", \"service\", \"notice\")),\n",
    "        \"independent\": (4, (\"separate\",)),\n",
    "        \"release\": (10, (\"packing\", \"remittance\", \"service\", \"notice\", \"separate\")),\n",
    "    }\n",
    "    locales = ((\"en-US\", \"USD\"), (\"en-GB\", \"GBP\"), (\"de-DE\", \"EUR\"), (\"fr-FR\", \"EUR\"), (\"en-US\", \"CAD\"))\n",
    "    services = (\"Cooling filter\", \"Cable sleeve\", \"Bench calibration\", \"Door seal\", \"Grounding clip\",\n",
    "                \"Rack inspection\", \"Meter label\", \"Packing insert\", \"Carrier adjustment\", \"Mounting plate\")\n",
    "    catalog = []\n",
    "    seen_keys = set()\n",
    "    supplier_codes = rng.sample(range(1000, 9999), sum(n for n, _ in sources.values()))\n",
    "    supplier_index = 0\n",
    "    for split, (family_count, layouts) in sources.items():\n",
    "        for family_number in range(family_count):\n",
    "            supplier_code = supplier_codes[supplier_index]\n",
    "            supplier_index += 1\n",
    "            layout = layouts[family_number % len(layouts)]\n",
    "            family = f\"{split}-{family_number:02d}\"\n",
    "            locale, currency = locales[family_number % len(locales)]\n",
    "            for row in range(SPLIT_SIZES[split] // family_count):\n",
    "                code = f\"SF-{rng.randrange(100000, 1000000)}\"\n",
    "                while code in seen_keys:\n",
    "                    code = f\"SF-{rng.randrange(100000, 1000000)}\"\n",
    "                seen_keys.add(code)\n",
    "                items = tuple(\n",
    "                    Line(kind, rng.randint(1, 9), rng.randrange(200, 24800))\n",
    "                    for kind in rng.sample(services, rng.randrange(1, 4))\n",
    "                )\n",
    "                subtotal = sum(x.quantity * x.unit_minor for x in items)\n",
    "                tax = (subtotal * (7 if currency == \"USD\" else 13) + 50) // 100\n",
    "                if split in {\"novel\", \"independent\", \"release\"} and row % 12 == 4:\n",
    "                    tax = None\n",
    "                displayed = subtotal + tax + 101 if tax is not None and row % 12 == 7 else None\n",
    "                issued_on = (date(2025, 1, 1) + timedelta(days=rng.randint(0, 590))).isoformat()\n",
    "                catalog.append(Invoice(code, family, f\"Sample Supplier {supplier_code}\", issued_on,\n",
    "                                       currency, items, tax, locale, split, layout, displayed))\n",
    "    return catalog\n",
    "\n",
    "\n",
    "def formatted_money(minor: int | None, locale: str) -> str:\n",
    "    if minor is None:\n",
    "        return \"-\"\n",
    "    dollars, cents = divmod(minor, 100)\n",
    "    number = f\"{dollars:,}.{cents:02d}\"\n",
    "    if locale == \"de-DE\":\n",
    "        return number.replace(\",\", \"_\").replace(\".\", \",\").replace(\"_\", \".\")\n",
    "    if locale == \"fr-FR\":\n",
    "        return number.replace(\",\", \" \").replace(\".\", \",\")\n",
    "    return number\n",
    "\n",
    "\n",
    "def invoice_text(invoice: Invoice) -> str:\n",
    "    gold = invoice_record(invoice)\n",
    "    money = lambda value: formatted_money(value, invoice.locale)\n",
    "    identifier = f\"{invoice.key}\"\n",
    "    supplier = invoice.supplier\n",
    "    issued = invoice.issued_on\n",
    "    currency = invoice.currency\n",
    "    subtotal = money(gold[\"subtotal_minor\"])\n",
    "    tax = money(gold[\"tax_minor\"])\n",
    "    total = money(gold[\"total_minor\"])\n",
    "    register = [f\"{row.description} | {row.quantity} | {money(row.unit_minor)}\" for row in invoice.items]\n",
    "    inline = [f\"{row.quantity} x {row.description} @ {money(row.unit_minor)} per unit\" for row in invoice.items]\n",
    "    service = [f\"{row.description}: {money(row.unit_minor)} each for {row.quantity} units\" for row in invoice.items]\n",
    "    if invoice.layout == \"register\":\n",
    "        return \"\\n\".join([f\"Supplier: {supplier}\", f\"Invoice: {identifier}\", f\"Issued: {issued}\", f\"Currency: {currency}\",\n",
    "                          \"Description | Quantity | Unit price\", *register,\n",
    "                          f\"Subtotal: {subtotal}\", f\"Tax: {tax}\", f\"Amount due: {total}\"])\n",
    "    if invoice.layout == \"memo\":\n",
    "        return \"\\n\".join([f\"{supplier} billing memo / {issued}\", f\"Account invoice {identifier} [{currency}]\",\n",
    "                          *inline, f\"Total due {total} including tax {tax}; net amount {subtotal}.\"])\n",
    "    if invoice.layout == \"checkout\":\n",
    "        return \"\\n\".join([f\"{identifier} / supplier {supplier}\", f\"Date of issue {issued} / All amounts {currency}\",\n",
    "                          *service, f\"Net {subtotal}\", f\"Sales tax {tax}\", f\"Payable {total}\"])\n",
    "    if invoice.layout == \"ledger\":\n",
    "        return \"\\n\".join([f\"{supplier} | issued {issued} | invoice {identifier}\", f\"Ledger in {currency}\",\n",
    "                          \"Service | Count | Per unit\", *register, f\"Before tax {subtotal}\",\n",
    "                          f\"Tax charged {tax}\", f\"Balance {total}\"])\n",
    "    if invoice.layout == \"packing\":\n",
    "        return \"\\n\".join([f\"Billing details / {identifier}\", f\"Sold by {supplier}\", f\"Document date {issued}\",\n",
    "                          f\"Invoice currency {currency}\", f\"Balance payable {total}\", *service,\n",
    "                          f\"Merchandise {subtotal}\", f\"Tax {tax}\"])\n",
    "    if invoice.layout == \"remittance\":\n",
    "        return \"\\n\".join([f\"Remittance advice for {identifier} ({currency})\", f\"{supplier} / Document issued {issued}\",\n",
    "                          f\"Pay this amount {total}\", *inline, f\"Net charges {subtotal} / Tax {tax}\"])\n",
    "    if invoice.layout == \"service\":\n",
    "        return \"\\n\".join([f\"Ref {identifier} / {currency}\", f\"Service fee notice, {issued}\", supplier,\n",
    "                          *[f\"Unit {money(row.unit_minor)} / {row.quantity} times / {row.description}\" for row in invoice.items],\n",
    "                          f\"Fee subtotal {subtotal}\", f\"Plus tax {tax}\", f\"Amount requested {total}\"])\n",
    "    if invoice.layout == \"notice\":\n",
    "        return \"\\n\".join([f\"{supplier} / statement {identifier}\", f\"Issued on {issued}\",\n",
    "                          f\"Invoice denomination {currency}\", \"One-off charges\", *service,\n",
    "                          f\"Pre-tax {subtotal} / Tax assessment {tax} / Final bill {total}\"])\n",
    "    return \"\\n\".join([f\"Document {identifier}\", f\"Biller {supplier} / As of {issued} / {currency}\", *inline,\n",
    "                      f\"Gross {total}\", f\"Breakdown: net {subtotal} and taxes {tax}.\"])\n",
    "\n",
    "\n",
    "def _strict_dict(pairs: list[tuple[str, Any]]) -> dict[str, Any]:\n",
    "    result: dict[str, Any] = {}\n",
    "    for key, value in pairs:\n",
    "        if key in result:\n",
    "            raise ValueError(f\"Duplicate JSON key {key!r}\")\n",
    "        result[key] = value\n",
    "    return result\n",
    "\n",
    "\n",
    "def parse_record(completion: str | dict[str, Any]) -> dict[str, Any] | None:\n",
    "    if isinstance(completion, str):\n",
    "        try:\n",
    "            data = json.loads(completion, object_pairs_hook=_strict_dict)\n",
    "        except (ValueError, TypeError, RecursionError):\n",
    "            return None\n",
    "    else:\n",
    "        data = completion\n",
    "    keys = {\"invoice_id\", \"issued_on\", \"supplier\", \"currency\", \"line_items\", \"subtotal_minor\", \"tax_minor\", \"total_minor\"}\n",
    "    if not isinstance(data, dict) or set(data) != keys:\n",
    "        return None\n",
    "    for name in (\"invoice_id\", \"supplier\", \"issued_on\", \"currency\"):\n",
    "        value = data[name]\n",
    "        if value is not None and (not isinstance(value, str) or not value.strip()):\n",
    "            return None\n",
    "    try:\n",
    "        if data[\"issued_on\"] is not None and date.fromisoformat(data[\"issued_on\"]).isoformat() != data[\"issued_on\"]:\n",
    "            return None\n",
    "    except ValueError:\n",
    "        return None\n",
    "    if data[\"currency\"] is not None and re.fullmatch(\"[A-Z]{3}\", data[\"currency\"]) is None:\n",
    "        return None\n",
    "    for name in (\"subtotal_minor\", \"tax_minor\", \"total_minor\"):\n",
    "        if data[name] is not None and type(data[name]) is not int:\n",
    "            return None\n",
    "    if not isinstance(data[\"line_items\"], list):\n",
    "        return None\n",
    "    for row in data[\"line_items\"]:\n",
    "        if not isinstance(row, dict) or set(row) != {\"description\", \"quantity\", \"unit_minor\"}:\n",
    "            return None\n",
    "        if type(row[\"description\"]) is not str or type(row[\"quantity\"]) is not int or type(row[\"unit_minor\"]) is not int:\n",
    "            return None\n",
    "        if not row[\"description\"].strip() or row[\"quantity\"] <= 0:\n",
    "            return None\n",
    "    return data\n",
    "\n",
    "\n",
    "def score_record(completion: str | dict[str, Any], invoice: Invoice) -> dict[str, Any]:\n",
    "    truth = invoice_record(invoice)\n",
    "    observed = parse_record(completion)\n",
    "    field_correct = {key: observed is not None and observed.get(key) == value\n",
    "                     for key, value in truth.items() if key != \"line_items\"}\n",
    "    keys = (\"description\", \"quantity\", \"unit_minor\")\n",
    "    expected = Counter(tuple(r[k] for k in keys) for r in truth[\"line_items\"])\n",
    "    predicted = Counter(tuple(r[k] for k in keys) for r in observed[\"line_items\"]) if observed is not None else Counter()\n",
    "    matches = (expected & predicted).total()\n",
    "    row_count = expected.total() + predicted.total()\n",
    "    return {\"valid\": observed is not None, \"exact\": observed == truth,\n",
    "            \"fields\": sum(field_correct.values()) / len(field_correct), \"field_correct\": field_correct,\n",
    "            \"row_f1\": 2 * matches / row_count if row_count else 1.0}\n",
    "\n",
    "\n",
    "def rules_extract(text: str) -> dict[str, Any] | None:\n",
    "    lines = text.splitlines()\n",
    "    if len(lines) < 9 or lines[4] != \"Description | Quantity | Unit price\":\n",
    "        return None\n",
    "    property_names = (\"supplier\", \"invoice_id\", \"issued_on\", \"currency\")\n",
    "    headers = (\"Supplier: \", \"Invoice: \", \"Issued: \", \"Currency: \")\n",
    "    if any(not line.startswith(header) for line, header in zip(lines, headers)):\n",
    "        return None\n",
    "    data = {name: line.removeprefix(header) for name, line, header in zip(property_names, lines, headers)}\n",
    "\n",
    "    def minor(text_amount: str) -> int | None:\n",
    "        if text_amount == \"-\":\n",
    "            return None\n",
    "        if re.fullmatch(r\"(?:\\d+|\\d{1,3}(?:[., ]\\d{3})+)[.,]\\d{2}\", text_amount) is None:\n",
    "            raise ValueError(\"Unsupported amount format\")\n",
    "        units, frac = text_amount[:-3], text_amount[-2:]\n",
    "        return int(re.sub(r\"\\D\", \"\", units)) * 100 + int(frac)\n",
    "\n",
    "    try:\n",
    "        rows = [line.split(\" | \") for line in lines[5:-3]]\n",
    "        data[\"line_items\"] = [{\"description\": desc, \"quantity\": int(qty), \"unit_minor\": minor(unit)}\n",
    "                              for desc, qty, unit in rows]\n",
    "        data[\"subtotal_minor\"] = minor(lines[-3].removeprefix(\"Subtotal: \"))\n",
    "        data[\"tax_minor\"] = minor(lines[-2].removeprefix(\"Tax: \"))\n",
    "        data[\"total_minor\"] = minor(lines[-1].removeprefix(\"Amount due: \"))\n",
    "    except ValueError:\n",
    "        return None\n",
    "    return parse_record(data)\n",
    "\n",
    "\n",
    "def examples_for(split: str, limit: int | None = None) -> list[Invoice]:\n",
    "    found = [invoice for invoice in make_catalog() if invoice.split == split]\n",
    "    if not found:\n",
    "        raise ValueError(f\"Unknown invoice split {split!r}\")\n",
    "    if limit is None or limit >= len(found):\n",
    "        return found\n",
    "    if limit <= 0:\n",
    "        raise ValueError(\"Limit must be positive\")\n",
    "    groups: dict[str, list[Invoice]] = {}\n",
    "    for invoice in found:\n",
    "        groups.setdefault(invoice.family, []).append(invoice)\n",
    "    balanced = [invoice for group_rows in zip(*groups.values(), strict=True) for invoice in group_rows]\n",
    "    return balanced[:limit]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "26385691",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Notebook-local Qwen text training and matched invoice evaluation.\"\"\"\n",
    "\n",
    "import gc\n",
    "import hashlib\n",
    "import json\n",
    "import math\n",
    "import random\n",
    "import time\n",
    "from collections import defaultdict\n",
    "from importlib.metadata import version\n",
    "from pathlib import Path\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import torch\n",
    "from datasets import Dataset\n",
    "from peft import LoraConfig, PeftModel\n",
    "from transformers import AutoModelForCausalLM, AutoTokenizer, TrainerCallback, set_seed\n",
    "from trl import SFTConfig, SFTTrainer\n",
    "\n",
    "MODEL_ID = \"Qwen/Qwen2.5-0.5B-Instruct\"\n",
    "MODEL_REV = \"7ae557604adf67be50417f59c2c2f167def9a775\"\n",
    "SEED = 42\n",
    "DEVICE = \"cuda\"\n",
    "DTYPE = torch.float16\n",
    "PROMPT_LIMIT = 512\n",
    "ANSWER_LIMIT = 256\n",
    "OUT = Path(\"lesson-results\")\n",
    "\n",
    "SYSTEM = VISIBLE_CONTRACT\n",
    "\n",
    "def dialogs(invoice, system=SYSTEM):\n",
    "    return [{\"role\": \"system\", \"content\": system}, {\"role\": \"user\", \"content\": invoice_text(invoice)}]\n",
    "\n",
    "\n",
    "def packed(record):\n",
    "    return json.dumps(record, ensure_ascii=False, separators=(\",\", \":\"))\n",
    "\n",
    "\n",
    "def supervised_row(invoice, answer=None, system=SYSTEM):\n",
    "    return {\n",
    "        \"prompt\": dialogs(invoice, system=system),\n",
    "        \"completion\": [{\"role\": \"assistant\", \"content\": packed(invoice_record(invoice)) if answer is None else answer}],\n",
    "    }\n",
    "\n",
    "\n",
    "def prepare_kernel():\n",
    "    pins = globals().get(\"TRAINER_PINS\", {})\n",
    "    installed = {name: version(name) for name in pins}\n",
    "    if installed != pins:\n",
    "        raise RuntimeError(f\"Restart the kernel and install the pinned training packages: {installed}\")\n",
    "    if not torch.cuda.is_available():\n",
    "        raise RuntimeError(\"Select a T4 GPU in Colab before running all cells.\")\n",
    "    name = torch.cuda.get_device_name(0)\n",
    "    if \"T4\" not in name:\n",
    "        raise RuntimeError(f\"Expected a Colab T4 for comparable timings; found {name}.\")\n",
    "    OUT.mkdir(exist_ok=True)\n",
    "    set_seed(SEED)\n",
    "    tok = AutoTokenizer.from_pretrained(MODEL_ID, revision=MODEL_REV, trust_remote_code=False)\n",
    "    tok.padding_side = \"left\"\n",
    "    if tok.pad_token is None:\n",
    "        tok.pad_token = tok.eos_token\n",
    "    print(name, \"|\", torch.__version__, \"| revision\", MODEL_REV[:12])\n",
    "    print(\"Trainer packages\", installed, \"| CUDA\", torch.version.cuda)\n",
    "    return tok\n",
    "\n",
    "\n",
    "def manifest(invoices):\n",
    "    rows = sorted(\n",
    "        (invoice.key, invoice.family, invoice.split, invoice_text(invoice), invoice_record(invoice))\n",
    "        for invoice in invoices\n",
    "    )\n",
    "    return hashlib.sha256(packed(rows).encode()).hexdigest()\n",
    "\n",
    "\n",
    "def model_at(source=MODEL_ID):\n",
    "    options = {\"revision\": MODEL_REV} if source == MODEL_ID else {}\n",
    "    model = AutoModelForCausalLM.from_pretrained(\n",
    "        source, **options, torch_dtype=DTYPE, device_map={\"\": DEVICE},\n",
    "        trust_remote_code=False, attn_implementation=\"sdpa\", use_safetensors=True,\n",
    "    )\n",
    "    if source == MODEL_ID and model.config._commit_hash != MODEL_REV:\n",
    "        raise RuntimeError(\"Loaded weights do not match the pinned revision.\")\n",
    "    return model\n",
    "\n",
    "\n",
    "def clean_memory():\n",
    "    gc.collect()\n",
    "    if DEVICE == \"cuda\":\n",
    "        torch.cuda.empty_cache()\n",
    "\n",
    "\n",
    "def lora():\n",
    "    return LoraConfig(\n",
    "        r=8, lora_alpha=16, lora_dropout=0.0,\n",
    "        target_modules=[\"q_proj\", \"v_proj\", \"o_proj\"], task_type=\"CAUSAL_LM\",\n",
    "    )\n",
    "\n",
    "\n",
    "def prompt_tokens(row, tok):\n",
    "    return tok.apply_chat_template(row[\"prompt\"], tokenize=True, add_generation_prompt=True)\n",
    "\n",
    "\n",
    "def token_budget(rows, tok, labelled=None):\n",
    "    max_prompt = max(len(prompt_tokens(item, tok)) for item in rows)\n",
    "    if labelled is None:\n",
    "        labelled = [encode_supervised(item, tok) for item in rows if \"completion\" in item]\n",
    "    max_answer = max((sum(row[\"completion_mask\"]) for row in labelled), default=0)\n",
    "    if max_prompt > PROMPT_LIMIT or max_answer > ANSWER_LIMIT:\n",
    "        raise ValueError(f\"Token limits would clip this dataset: prompt={max_prompt}, answer={max_answer}.\")\n",
    "    return {\"max_prompt_tokens\": max_prompt, \"max_label_tokens\": max_answer}\n",
    "\n",
    "\n",
    "def encode_supervised(row, tok):\n",
    "    prompt = prompt_tokens(row, tok)\n",
    "    full = tok.apply_chat_template(row[\"prompt\"] + row[\"completion\"], tokenize=True)\n",
    "    if full[:len(prompt)] != prompt:\n",
    "        raise ValueError(\"The tokenized chat prefix changed when the answer was appended.\")\n",
    "    completion = full[len(prompt):]\n",
    "    ids = prompt + completion[:completion.index(tok.eos_token_id) + 1]\n",
    "    return {\"input_ids\": ids, \"completion_mask\": [0] * len(prompt) + [1] * (len(ids) - len(prompt))}\n",
    "\n",
    "\n",
    "def check_sft_labels(trainer, encoded):\n",
    "    for start in range(0, len(encoded), trainer.args.per_device_train_batch_size):\n",
    "        examples = encoded[start:start + trainer.args.per_device_train_batch_size]\n",
    "        batch = trainer.data_collator(examples)\n",
    "        for labels, example in zip(batch[\"labels\"].tolist(), examples, strict=True):\n",
    "            expected = [token if keep else -100 for token, keep in\n",
    "                        zip(example[\"input_ids\"], example[\"completion_mask\"], strict=True)]\n",
    "            if labels != expected + [-100] * (len(labels) - len(expected)):\n",
    "                raise AssertionError(\"SFT loss includes prompt or padding, or dropped a response token.\")\n",
    "    return sum(sum(row[\"completion_mask\"]) for row in encoded)\n",
    "\n",
    "\n",
    "class OptimizerAudit(TrainerCallback):\n",
    "    def __init__(self):\n",
    "        self.completed = 0\n",
    "        self.skipped = 0\n",
    "\n",
    "    def on_optimizer_step(self, args, state, control, optimizer, **kwargs):\n",
    "        if optimizer.step_was_skipped:\n",
    "            self.skipped += 1\n",
    "        else:\n",
    "            self.completed += 1\n",
    "\n",
    "\n",
    "def capture_fit(trainer):\n",
    "    audit = OptimizerAudit()\n",
    "    trainer.add_callback(audit)\n",
    "    if DEVICE == \"cuda\":\n",
    "        torch.cuda.synchronize()\n",
    "        torch.cuda.reset_peak_memory_stats()\n",
    "    started = time.perf_counter()\n",
    "    trainer.train()\n",
    "    if DEVICE == \"cuda\":\n",
    "        torch.cuda.synchronize()\n",
    "    if (trainer.state.global_step, audit.completed, audit.skipped) != (trainer.args.max_steps, trainer.args.max_steps, 0):\n",
    "        raise RuntimeError(f\"Optimizer budget mismatch: completed={audit.completed}, skipped={audit.skipped}.\")\n",
    "    return {\n",
    "        \"steps\": trainer.state.global_step,\n",
    "        \"optimizer_updates\": audit.completed,\n",
    "        \"seconds\": time.perf_counter() - started,\n",
    "        \"peak_allocated_gib\": torch.cuda.max_memory_allocated() / 2**30 if DEVICE == \"cuda\" else None,\n",
    "        \"peak_reserved_gib\": torch.cuda.max_memory_reserved() / 2**30 if DEVICE == \"cuda\" else None,\n",
    "        \"log\": [\n",
    "            {key: None if isinstance(value, float) and not math.isfinite(value) else value\n",
    "             for key, value in row.items()}\n",
    "            for row in trainer.state.log_history\n",
    "        ],\n",
    "    }\n",
    "\n",
    "\n",
    "def fit_sft(rows, tok, name, *, steps=32, source=MODEL_ID, lr=2e-4):\n",
    "    encoded = [encode_supervised(row, tok) for row in rows]\n",
    "    lengths = token_budget(rows, tok, encoded)\n",
    "    set_seed(SEED)\n",
    "    base = model_at(source)\n",
    "    base.config.use_cache = False\n",
    "    args = SFTConfig(\n",
    "        output_dir=str(OUT / f\"{name}-trainer\"),\n",
    "        max_steps=steps, max_length=PROMPT_LIMIT + ANSWER_LIMIT,\n",
    "        per_device_train_batch_size=4, gradient_accumulation_steps=2,\n",
    "        learning_rate=lr, lr_scheduler_type=\"constant\", completion_only_loss=True,\n",
    "        fp16=True, bf16=False, gradient_checkpointing=True,\n",
    "        gradient_checkpointing_kwargs={\"use_reentrant\": False},\n",
    "        logging_steps=4, save_strategy=\"no\", report_to=\"none\", seed=SEED, data_seed=SEED,\n",
    "    )\n",
    "    trainer = SFTTrainer(\n",
    "        model=base, args=args, train_dataset=Dataset.from_list(encoded),\n",
    "        processing_class=tok, peft_config=lora(),\n",
    "    )\n",
    "    label_tokens = check_sft_labels(trainer, encoded)\n",
    "    stats = {**capture_fit(trainer), **lengths, \"examples\": len(rows), \"learning_rate\": lr,\n",
    "             \"roster_supervised_tokens\": label_tokens, \"examples_per_update\": 8}\n",
    "    checkpoint = str(OUT / name)\n",
    "    trainer.model.save_pretrained(checkpoint)\n",
    "    del trainer, base\n",
    "    clean_memory()\n",
    "    print(name, {key: value for key, value in stats.items() if key != \"log\"})\n",
    "    return checkpoint, stats\n",
    "\n",
    "\n",
    "def merge_adapter(source, adapter, name):\n",
    "    base = model_at(source)\n",
    "    loaded = PeftModel.from_pretrained(base, adapter)\n",
    "    merged = loaded.merge_and_unload()\n",
    "    merged.config.use_cache = True\n",
    "    target = str(OUT / name)\n",
    "    merged.save_pretrained(target, safe_serialization=True)\n",
    "    del merged, loaded, base\n",
    "    clean_memory()\n",
    "    return target\n",
    "\n",
    "\n",
    "def checkpoint_digest(path):\n",
    "    digest = hashlib.sha256()\n",
    "    directory = Path(path)\n",
    "    files = sorted(item for item in directory.iterdir() if item.suffix in {\".json\", \".safetensors\"})\n",
    "    if not any(item.suffix == \".safetensors\" for item in files):\n",
    "        raise ValueError(f\"No saved weights in {directory}.\")\n",
    "    for item in files:\n",
    "        digest.update(item.name.encode())\n",
    "        with item.open(\"rb\") as stream:\n",
    "            digest.update(hashlib.file_digest(stream, \"sha256\").digest())\n",
    "    return digest.hexdigest()\n",
    "\n",
    "\n",
    "def trainable_digest(model):\n",
    "    digest = hashlib.sha256()\n",
    "    for name, parameter in model.named_parameters():\n",
    "        if parameter.requires_grad:\n",
    "            digest.update(name.encode())\n",
    "            digest.update(parameter.detach().float().cpu().numpy().tobytes())\n",
    "    return digest.hexdigest()\n",
    "\n",
    "\n",
    "def fixed_eval(catalog, per_slice=None, splits=(\"familiar\", \"novel\", \"independent\")):\n",
    "    rng = random.Random(SEED)\n",
    "    picked = []\n",
    "    for split in splits:\n",
    "        rows = [invoice for invoice in catalog if invoice.split == split]\n",
    "        if not rows:\n",
    "            raise ValueError(f\"No data for fixed slice {split}\")\n",
    "        if per_slice is not None and len(rows) > per_slice:\n",
    "            rows = rng.sample(rows, per_slice)\n",
    "        picked.extend(rows)\n",
    "    assert len({row.key for row in picked}) == len(picked)\n",
    "    return picked\n",
    "\n",
    "\n",
    "def eos_ids(model, tok):\n",
    "    value = model.generation_config.eos_token_id\n",
    "    ids = value if isinstance(value, list) else [value]\n",
    "    return {token for token in [tok.eos_token_id, *ids] if token is not None}\n",
    "\n",
    "\n",
    "@torch.inference_mode()\n",
    "def evaluate(model, tok, invoices, *, system=SYSTEM, answer_limit=ANSWER_LIMIT, extract=lambda text: text):\n",
    "    model.eval()\n",
    "    model.config.use_cache = True\n",
    "    output = []\n",
    "    eos = eos_ids(model, tok)\n",
    "    for i in range(0, len(invoices), 8):\n",
    "        part = invoices[i:i + 8]\n",
    "        rendered = [tok.apply_chat_template(dialogs(invoice, system), tokenize=False, add_generation_prompt=True)\n",
    "                    for invoice in part]\n",
    "        batch = tok(rendered, add_special_tokens=False, return_tensors=\"pt\", padding=True).to(DEVICE)\n",
    "        if batch.input_ids.shape[1] > PROMPT_LIMIT:\n",
    "            raise ValueError(\"An evaluation prompt exceeded the declared token budget.\")\n",
    "        if DEVICE == \"cuda\":\n",
    "            torch.cuda.synchronize()\n",
    "        started = time.perf_counter()\n",
    "        tokens = model.generate(**batch, max_new_tokens=answer_limit, do_sample=False,\n",
    "                                pad_token_id=tok.pad_token_id)[:, batch.input_ids.shape[1]:]\n",
    "        if DEVICE == \"cuda\":\n",
    "            torch.cuda.synchronize()\n",
    "        latency = (time.perf_counter() - started) * 1000 / len(part)\n",
    "        texts = tok.batch_decode(tokens, skip_special_tokens=True)\n",
    "        for invoice, token_row, text in zip(part, tokens.tolist(), texts, strict=True):\n",
    "            boundary = next((index for index, token in enumerate(token_row) if token in eos), None)\n",
    "            record = score_record(extract(text), invoice)\n",
    "            output.append({\n",
    "                \"key\": invoice.key, \"family\": invoice.family, \"split\": invoice.split,\n",
    "                \"valid\": float(record[\"valid\"]), \"exact\": float(record[\"exact\"]),\n",
    "                \"fields\": record[\"fields\"], \"row_f1\": float(record[\"row_f1\"]),\n",
    "                \"natural_completion\": boundary is not None,\n",
    "                \"generated_tokens\": len(token_row) if boundary is None else boundary + 1,\n",
    "                \"ms_per_example_in_batch\": latency,\n",
    "                \"completion\": text,\n",
    "            })\n",
    "    return output\n",
    "\n",
    "\n",
    "def evaluate_at(source, tok, invoices, *, adapter=None, **kwargs):\n",
    "    base = model_at(source)\n",
    "    model = PeftModel.from_pretrained(base, adapter) if adapter else base\n",
    "    scores = evaluate(model, tok, invoices, **kwargs)\n",
    "    del model, base\n",
    "    clean_memory()\n",
    "    return scores\n",
    "\n",
    "\n",
    "def summary(scores):\n",
    "    mean = lambda key: sum(row[key] for row in scores) / len(scores)\n",
    "    return {\n",
    "        \"n\": len(scores), \"exact\": mean(\"exact\"), \"valid\": mean(\"valid\"),\n",
    "        \"row_f1\": mean(\"row_f1\"), \"natural_completion\": mean(\"natural_completion\"),\n",
    "        \"mean_generated_tokens\": mean(\"generated_tokens\"),\n",
    "        \"mean_ms_per_example_in_batch\": mean(\"ms_per_example_in_batch\"),\n",
    "    }\n",
    "\n",
    "\n",
    "def paired_change(before, after, *, score=\"exact\", seed=SEED):\n",
    "    left = {row[\"key\"]: row for row in before}\n",
    "    right = {row[\"key\"]: row for row in after}\n",
    "    assert set(left) == set(right) and len(left) == len(before) == len(after)\n",
    "    by_family = defaultdict(list)\n",
    "    for key, row in sorted(left.items()):\n",
    "        by_family[row[\"family\"]].append(right[key][score] - row[score])\n",
    "    changes = [value for values in by_family.values() for value in values]\n",
    "    groups = list(by_family.values())\n",
    "    rng = random.Random(seed)\n",
    "    boot = []\n",
    "    if len(groups) >= 2:\n",
    "        for _ in range(2000):\n",
    "            sampled = [value for group in rng.choices(groups, k=len(groups)) for value in group]\n",
    "            boot.append(sum(sampled) / len(sampled))\n",
    "    return {\n",
    "        \"delta\": sum(changes) / len(changes), \"n\": len(changes), \"families\": len(groups),\n",
    "        \"improved\": sum(change > 0 for change in changes),\n",
    "        \"regressed\": sum(change < 0 for change in changes),\n",
    "        \"tied\": sum(change == 0 for change in changes),\n",
    "        \"paired_family_bootstrap_95\": np.quantile(boot, [0.025, 0.975]).tolist() if boot else None,\n",
    "    }\n",
    "\n",
    "\n",
    "def stage_interaction(scores):\n",
    "    lookup = [{row[\"key\"]: row[\"exact\"] for row in run} for run in scores]\n",
    "    keys = sorted(lookup[0])\n",
    "    assert all(set(run) == set(keys) for run in lookup)\n",
    "    rows = []\n",
    "    for baseline in scores[0]:\n",
    "        key = baseline[\"key\"]\n",
    "        start, dpo, grpo, combined = [run[key] for run in lookup]\n",
    "        rows.append({\"key\": key, \"family\": baseline[\"family\"], \"exact\": combined - dpo - grpo + start})\n",
    "    return paired_change(\n",
    "        [dict(row, exact=0.0) for row in rows], rows,\n",
    "    )\n",
    "\n",
    "\n",
    "def write_report(lesson, report, **tables):\n",
    "    for key, values in tables.items():\n",
    "        pd.DataFrame(values).to_csv(OUT / f\"{lesson}-{key}.csv\", index=False)\n",
    "    full = {\n",
    "        \"model\": MODEL_ID, \"revision\": MODEL_REV, \"seed\": SEED,\n",
    "        \"hardware\": torch.cuda.get_device_name(0) if DEVICE == \"cuda\" else DEVICE,\n",
    "        \"packages\": {name: version(name) for name in (\"torch\", \"transformers\", \"peft\", \"trl\", \"accelerate\", \"datasets\")},\n",
    "        \"prompt_token_cap\": PROMPT_LIMIT, \"completion_token_cap\": ANSWER_LIMIT,\n",
    "        **report,\n",
    "    }\n",
    "    (OUT / f\"{lesson}-report.json\").write_text(json.dumps(full, indent=2, allow_nan=False) + \"\\n\")\n",
    "    print(json.dumps(full, indent=2, allow_nan=False))\n",
    "\n",
    "\n",
    "def plot_slices(summaries, title, filename=\"exact.svg\"):\n",
    "    plt.rcParams[\"svg.fonttype\"] = \"none\"\n",
    "    from IPython.display import SVG, display\n",
    "    fig, ax = plt.subplots(figsize=(9, 4))\n",
    "    keys = list(summaries)\n",
    "    values = [summaries[label][\"exact\"] for label in keys]\n",
    "    ax.barh(keys, values, color=[\"#74818c\", \"#2a78d6\", \"#eb6834\", \"#426a53\", \"#746296\"][:len(keys)])\n",
    "    ax.set(xlim=(0, 1.05), xlabel=\"Exact complete records, share\", title=title)\n",
    "    ax.bar_label(ax.containers[0], labels=[f\"{value:.1%}\" for value in values], padding=4)\n",
    "    ax.invert_yaxis()\n",
    "    ax.grid(axis=\"x\", alpha=0.22)\n",
    "    fig.tight_layout()\n",
    "    svg_path = OUT / filename\n",
    "    fig.savefig(svg_path, format=\"svg\")\n",
    "    plt.close(fig)\n",
    "    display(SVG(filename=str(svg_path)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8b675e3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# SPDX-License-Identifier: Apache-2.0\n",
    "# Adapted from the Together Post-Training Cookbook revision 226e03ca225d6f13434047cf0f45ab3070a29801.\n",
    "from collections import Counter\n",
    "from collections.abc import Callable, Iterable, Sequence\n",
    "from dataclasses import dataclass, field\n",
    "from typing import TypeVar\n",
    "import torch.nn.functional as F\n",
    "Item = TypeVar('Item')\n",
    "\n",
    "def oversample_until_kept(\n",
    "    draw_batch: Callable[[], Iterable[Item]],\n",
    "    *,\n",
    "    is_kept: Callable[[Item], bool],\n",
    "    target: int,\n",
    "    max_attempts: int,\n",
    ") -> tuple[list[Item], int]:\n",
    "    \"\"\"Keep rejected groups in the audit trail while bounding draws.\"\"\"\n",
    "    if target <= 0 or max_attempts <= 0:\n",
    "        raise ValueError(\"Target and maximum attempts must be positive.\")\n",
    "    items: list[Item] = []\n",
    "    kept = 0\n",
    "    for attempts in range(1, max_attempts + 1):\n",
    "        for item in draw_batch():\n",
    "            items.append(item)\n",
    "            if is_kept(item):\n",
    "                kept += 1\n",
    "                if kept >= target:\n",
    "                    return items, attempts\n",
    "    return items, max_attempts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "16642fc3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Reward shaping and condition checks kept independent of the release scorer.\"\"\"\n",
    "\n",
    "import json\n",
    "from collections import Counter\n",
    "\n",
    "\n",
    "def _unique_reward_keys(pairs):\n",
    "    if len(dict(pairs)) != len(pairs):\n",
    "        raise ValueError(\"duplicate key\")\n",
    "    return dict(pairs)\n",
    "\n",
    "\n",
    "def reward_components(completion, expected, *, natural_stop):\n",
    "    \"\"\"Score structure and field fidelity without calling the held-out scorer.\"\"\"\n",
    "    try:\n",
    "        observed = json.loads(completion, object_pairs_hook=_unique_reward_keys)\n",
    "    except (ValueError, TypeError, RecursionError):\n",
    "        return {\"format\": 0.0, \"semantic\": 0.0, \"fields\": 0.0, \"rows\": 0.0, \"natural_stop\": float(natural_stop)}\n",
    "    if not isinstance(observed, dict) or set(observed) != set(expected):\n",
    "        return {\"format\": 0.0, \"semantic\": 0.0, \"fields\": 0.0, \"rows\": 0.0, \"natural_stop\": float(natural_stop)}\n",
    "    rows = observed[\"line_items\"]\n",
    "    fmt = float(\n",
    "        all(value is None or isinstance(value, str) for value in\n",
    "            (observed[key] for key in (\"invoice_id\", \"issued_on\", \"supplier\", \"currency\")))\n",
    "        and all(value is None or type(value) is int for value in\n",
    "                (observed[key] for key in (\"subtotal_minor\", \"tax_minor\", \"total_minor\")))\n",
    "        and isinstance(rows, list)\n",
    "        and all(isinstance(row, dict) and set(row) == {\"description\", \"quantity\", \"unit_minor\"}\n",
    "                and isinstance(row[\"description\"], str) and type(row[\"quantity\"]) is int\n",
    "                and type(row[\"unit_minor\"]) is int for row in rows)\n",
    "    )\n",
    "    if not fmt:\n",
    "        return {\"format\": 0.0, \"semantic\": 0.0, \"fields\": 0.0, \"rows\": 0.0, \"natural_stop\": float(natural_stop)}\n",
    "    keys = [key for key in expected if key != \"line_items\"]\n",
    "    correct = sum(observed[key] == expected[key] for key in keys) / len(keys)\n",
    "    make_row_counts = lambda records: Counter((r[\"description\"], r[\"quantity\"], r[\"unit_minor\"]) for r in records)\n",
    "    truth = make_row_counts(expected[\"line_items\"])\n",
    "    predicted = make_row_counts(rows)\n",
    "    matches = (truth & predicted).total()\n",
    "    row_score = 2.0 * matches / max(truth.total() + predicted.total(), 1)\n",
    "    combined = 0.45 * correct + 0.45 * row_score + 0.1 * float(natural_stop)\n",
    "    return {\"format\": fmt, \"semantic\": combined, \"fields\": correct, \"rows\": row_score, \"natural_stop\": float(natural_stop)}\n",
    "\n",
    "\n",
    "def replay_cases(invoice):\n",
    "    \"\"\"Wrong but well-formed answers expose the range of each reward.\"\"\"\n",
    "    record = invoice_record(invoice)\n",
    "    items = record[\"line_items\"]\n",
    "    assert len(items) >= 2\n",
    "    correct = packed(record)\n",
    "    mutations = [\n",
    "        (\"correct\", correct, True),\n",
    "        (\"missing row\", packed({**record, \"line_items\": items[1:]}), True),\n",
    "        (\"duplicate row\", packed({**record, \"line_items\": items + items[:1]}), True),\n",
    "        (\"wrong currency\", packed({**record, \"currency\": \"USD\" if record[\"currency\"] != \"USD\" else \"EUR\"}), True),\n",
    "        (\"reordered rows\", packed({**record, \"line_items\": items[::-1]}), True),\n",
    "        (\"missing EOS\", correct, False),\n",
    "        (\"truncated JSON\", correct[:-6], False),\n",
    "    ]\n",
    "    return [\n",
    "        {\"case\": name, \"completion\": text, **reward_components(text, record, natural_stop=natural),\n",
    "         \"release_exact\": score_record(text, invoice)[\"exact\"]}\n",
    "        for name, text, natural in mutations\n",
    "    ]\n",
    "\n",
    "\n",
    "def reward_group_diagnostics(batches):\n",
    "    \"\"\"Estimate skip rates on bounded replay, without changing scored GRPO rollouts.\"\"\"\n",
    "    stream = iter(batches)\n",
    "    observed, attempts = oversample_until_kept(\n",
    "        lambda: next(stream, ()), is_kept=lambda rewards: len(set(rewards)) > 1,\n",
    "        target=2, max_attempts=3,\n",
    "    )\n",
    "    return {\n",
    "        \"attempts\": attempts, \"groups\": len(observed),\n",
    "        \"zero_variance_groups\": sum(len(set(group)) < 2 for group in observed),\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9f47f23c",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Bounded Transformers GRPO on one T4.\"\"\"\n",
    "\n",
    "from trl import GRPOConfig, GRPOTrainer\n",
    "\n",
    "GROUP_SIZE = 4\n",
    "GRPO_STEPS = 10\n",
    "GRPO_BETA = 0.04\n",
    "\n",
    "\n",
    "def reward_factory(kind, eos_token_id, audit):\n",
    "    def reward(prompts, completions, completion_ids, gold, record_key, **kwargs):\n",
    "        pairs = []\n",
    "        for option, tokens, expected in zip(completions, completion_ids, gold, strict=True):\n",
    "            if not 0 < len(tokens) <= ANSWER_LIMIT or eos_token_id in tokens[:-1]:\n",
    "                raise ValueError(\"GRPO completion IDs crossed the declared cap or EOS boundary.\")\n",
    "            text = option[0][\"content\"]\n",
    "            pairs.append(reward_components(text, json.loads(expected),\n",
    "                                           natural_stop=tokens[-1] == eos_token_id))\n",
    "        rewards = [item[kind] for item in pairs]\n",
    "        groups = [rewards[i:i + GROUP_SIZE] for i in range(0, len(rewards), GROUP_SIZE)]\n",
    "        if (len(groups) != 1 or len(groups[0]) != GROUP_SIZE or len(record_key) != GROUP_SIZE\n",
    "                or len(set(record_key)) != 1 or len(set(gold)) != 1):\n",
    "            raise ValueError(\"Expected one group of four completions for a single invoice.\")\n",
    "        audit.append({\n",
    "            \"rollout_group\": len(audit) + 1,\n",
    "            \"rollout_invoice_ids\": record_key[::GROUP_SIZE],\n",
    "            \"completions\": len(rewards),\n",
    "            \"format_mean\": float(np.mean([item[\"format\"] for item in pairs])),\n",
    "            \"semantic_mean\": float(np.mean([item[\"semantic\"] for item in pairs])),\n",
    "            \"field_mean\": float(np.mean([item[\"fields\"] for item in pairs])),\n",
    "            \"row_f1_mean\": float(np.mean([item[\"rows\"] for item in pairs])),\n",
    "            \"completion_rate\": float(np.mean([item[\"natural_stop\"] for item in pairs])),\n",
    "            \"mean_tokens\": float(np.mean([len(tokens) for tokens in completion_ids])),\n",
    "            \"max_tokens\": max(map(len, completion_ids)),\n",
    "            \"cap_hits_without_eos\": sum(len(tokens) == ANSWER_LIMIT and tokens[-1] != eos_token_id\n",
    "                                        for tokens in completion_ids),\n",
    "            \"zero_variance_group_share\": float(np.mean([len(set(group)) == 1 for group in groups])),\n",
    "        })\n",
    "        return rewards\n",
    "    reward.__name__ = f\"{kind}_reward\"\n",
    "    return reward\n",
    "\n",
    "\n",
    "def grpo_rows(invoices):\n",
    "    return [{\"prompt\": dialogs(inv), \"gold\": packed(invoice_record(inv)), \"record_key\": inv.key} for inv in invoices]\n",
    "\n",
    "\n",
    "def fit_grpo(source, tok, rows, name, *, kind=\"semantic\", steps=GRPO_STEPS, lr=2e-5, beta=0.0,\n",
    "             save_adapter=True):\n",
    "    if len(rows) < steps:\n",
    "        raise ValueError(\"Set aside at least one distinct training prompt per planned update.\")\n",
    "    lengths = token_budget(rows, tok)\n",
    "    set_seed(SEED)\n",
    "    base = model_at(source)\n",
    "    audit = []\n",
    "    args = GRPOConfig(\n",
    "        output_dir=str(OUT / f\"{name}-trainer\"), max_steps=steps,\n",
    "        per_device_train_batch_size=GROUP_SIZE, gradient_accumulation_steps=1,\n",
    "        num_generations=GROUP_SIZE, steps_per_generation=1, max_prompt_length=PROMPT_LIMIT,\n",
    "        max_completion_length=ANSWER_LIMIT, temperature=0.8, beta=beta,\n",
    "        num_iterations=1, loss_type=\"bnpo\", scale_rewards=True,\n",
    "        learning_rate=lr, lr_scheduler_type=\"constant\",\n",
    "        use_vllm=False, fp16=True, bf16=False, logging_steps=1,\n",
    "        save_strategy=\"no\", report_to=\"none\", seed=SEED, data_seed=SEED,\n",
    "        remove_unused_columns=False,\n",
    "    )\n",
    "    trainer = GRPOTrainer(\n",
    "        model=base, args=args, reward_funcs=reward_factory(kind, tok.eos_token_id, audit),\n",
    "        train_dataset=Dataset.from_list(rows), processing_class=tok, peft_config=lora(),\n",
    "    )\n",
    "    try:\n",
    "        initial_digest = trainable_digest(trainer.model)\n",
    "        stats = {\n",
    "            **capture_fit(trainer), **lengths, \"reward_kind\": kind, \"learning_rate\": lr, \"beta\": beta,\n",
    "            \"initial_adapter_sha256\": initial_digest,\n",
    "            \"prompt_roster_sha256\": hashlib.sha256(packed(rows).encode()).hexdigest(),\n",
    "            \"prompt_ids_sha256\": hashlib.sha256(packed([r[\"record_key\"] for r in rows]).encode()).hexdigest(),\n",
    "            \"generation_group_size\": GROUP_SIZE, \"audit\": audit,\n",
    "            \"rollout_invoice_ids\": [key for batch in audit for key in batch[\"rollout_invoice_ids\"]],\n",
    "            \"completions_sampled\": sum(batch[\"completions\"] for batch in audit),\n",
    "            \"generation_settings\": trainer.generation_config.to_diff_dict(),\n",
    "        }\n",
    "        if (len(audit) != steps or stats[\"completions_sampled\"] != steps * GROUP_SIZE\n",
    "                or len(set(stats[\"rollout_invoice_ids\"])) != steps):\n",
    "            raise RuntimeError(\"Observed rollout groups differ from the fixed training budget.\")\n",
    "        checkpoint = str(OUT / name) if save_adapter else None\n",
    "        if checkpoint:\n",
    "            trainer.model.save_pretrained(checkpoint)\n",
    "            stats[\"adapter_sha256\"] = checkpoint_digest(checkpoint)\n",
    "    finally:\n",
    "        del trainer, base\n",
    "        clean_memory()\n",
    "    print(name, {key: value for key, value in stats.items() if key not in {\"log\", \"audit\"}})\n",
    "    return checkpoint, stats\n",
    "\n",
    "\n",
    "def check_profile(receipt):\n",
    "    return (\n",
    "        receipt[\"steps\"] == 1 and receipt[\"completions_sampled\"] == GROUP_SIZE\n",
    "        and receipt[\"seconds\"] <= 45 and receipt[\"peak_allocated_gib\"] <= 10\n",
    "        and receipt[\"peak_reserved_gib\"] <= min(12, receipt[\"free_before_gib\"] - 2)\n",
    "        and receipt[\"allocated_after_gib\"] <= receipt[\"allocated_before_gib\"] + 0.125\n",
    "    )\n",
    "\n",
    "\n",
    "def profile_grpo(tok, rows):\n",
    "    clean_memory()\n",
    "    torch.cuda.synchronize()\n",
    "    free_before, total = torch.cuda.mem_get_info()\n",
    "    allocated_before = torch.cuda.memory_allocated()\n",
    "    if free_before < 12 * 2**30:\n",
    "        raise RuntimeError(\"L04 needs at least 12 GiB free before running the one-step T4 profile.\")\n",
    "    longest = max(rows, key=lambda row: len(prompt_tokens(row, tok)))\n",
    "    try:\n",
    "        _, stats = fit_grpo(MODEL_ID, tok, [longest], \"04-profile\", steps=1, beta=GRPO_BETA, save_adapter=False)\n",
    "    finally:\n",
    "        clean_memory()\n",
    "        torch.cuda.synchronize()\n",
    "        torch.cuda.reset_peak_memory_stats()\n",
    "        set_seed(SEED)\n",
    "    receipt = {\n",
    "        **{name: stats[name] for name in (\"steps\", \"completions_sampled\", \"seconds\", \"peak_allocated_gib\",\n",
    "                                         \"peak_reserved_gib\", \"max_prompt_tokens\")},\n",
    "        \"max_completion_tokens_observed\": stats[\"audit\"][0][\"max_tokens\"],\n",
    "        \"free_before_gib\": free_before / 2**30, \"total_gib\": total / 2**30,\n",
    "        \"allocated_before_gib\": allocated_before / 2**30,\n",
    "        \"allocated_after_gib\": torch.cuda.memory_allocated() / 2**30,\n",
    "    }\n",
    "    receipt[\"passed\"] = check_profile(receipt)\n",
    "    (OUT / \"04-t4-profile.json\").write_text(json.dumps(receipt, indent=2) + \"\\n\")\n",
    "    print(\"One-step T4 profile\", receipt)\n",
    "    if not receipt[\"passed\"]:\n",
    "        raise RuntimeError(\"L04 T4 profile exceeded its time, memory or cleanup guard. Stop before the full fit.\")\n",
    "    return receipt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f6ade152",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Construct and train a reference-relative DPO stage from merged SFT weights.\"\"\"\n",
    "\n",
    "from trl import DPOConfig, DPOTrainer\n",
    "\n",
    "\n",
    "def wrong_candidate(record):\n",
    "    if record[\"total_minor\"] is None:\n",
    "        raise ValueError(\"A monetary preference pair needs a visible total.\")\n",
    "    return {**record, \"total_minor\": record[\"total_minor\"] + 1}\n",
    "\n",
    "\n",
    "def preference_pair(invoice):\n",
    "    record = invoice_record(invoice)\n",
    "    candidate = wrong_candidate(record)\n",
    "    assert score_record(packed(record), invoice)[\"exact\"]\n",
    "    assert score_record(packed(candidate), invoice)[\"valid\"]\n",
    "    assert not score_record(packed(candidate), invoice)[\"exact\"]\n",
    "    return {\n",
    "        \"record_key\": invoice.key,\n",
    "        \"prompt\": dialogs(invoice),\n",
    "        \"chosen\": [{\"role\": \"assistant\", \"content\": packed(record)}],\n",
    "        \"rejected\": [{\"role\": \"assistant\", \"content\": packed(candidate)}],\n",
    "    }\n",
    "\n",
    "\n",
    "def preference_rows(invoices, tok, limit=96):\n",
    "    selected = []\n",
    "    for invoice in invoices:\n",
    "        row = preference_pair(invoice)\n",
    "        chosen, rejected = preference_features(row, tok)\n",
    "        if len(chosen[\"input_ids\"]) != len(rejected[\"input_ids\"]):\n",
    "            continue\n",
    "        selected.append(row)\n",
    "        if len(selected) == limit:\n",
    "            return selected\n",
    "    raise ValueError(f\"Expected {limit} equal-length verified pairs, found {len(selected)}.\")\n",
    "\n",
    "\n",
    "def preference_features(row, tok):\n",
    "    encoded = [encode_supervised({\"prompt\": row[\"prompt\"], \"completion\": row[side]}, tok)\n",
    "               for side in (\"chosen\", \"rejected\")]\n",
    "    for side, example in zip((\"chosen\", \"rejected\"), encoded, strict=True):\n",
    "        token_budget([{\"prompt\": row[\"prompt\"], \"completion\": row[side]}], tok, [example])\n",
    "    return encoded\n",
    "\n",
    "\n",
    "def check_dpo_completions(trainer, rows, tok):\n",
    "    prompt_and_pairs = []\n",
    "    for row, prepared in zip(rows, trainer.train_dataset, strict=True):\n",
    "        prompt = prompt_tokens(row, tok)\n",
    "        expected = [item[\"input_ids\"][len(prompt):] for item in preference_features(row, tok)]\n",
    "        actual = [prepared[f\"{side}_input_ids\"] for side in (\"chosen\", \"rejected\")]\n",
    "        if prepared[\"prompt_input_ids\"] != prompt or actual != expected or len(actual[0]) != len(actual[1]):\n",
    "            raise AssertionError(\"DPO tokenization disagrees with the untruncated, equal-length completion pair.\")\n",
    "        prompt_and_pairs.append((len(prompt), len(actual[0])))\n",
    "    for start in range(0, len(rows), trainer.args.per_device_train_batch_size):\n",
    "        stop = start + trainer.args.per_device_train_batch_size\n",
    "        batch = trainer.data_collator([trainer.train_dataset[i] for i in range(start, min(stop, len(rows)))])\n",
    "        concatenated = trainer.concatenated_inputs(batch, trainer.padding_value)\n",
    "        prompt_mask = concatenated[\"prompt_attention_mask\"]\n",
    "        completion_mask = concatenated[\"completion_attention_mask\"]\n",
    "        expected = prompt_and_pairs[start:stop] * 2\n",
    "        if list(zip(prompt_mask.sum(1).tolist(), completion_mask.sum(1).tolist(), strict=True)) != expected:\n",
    "            raise AssertionError(\"DPO collator lost completion tokens or includes padding.\")\n",
    "    return {\"verified_pairs\": len(rows), \"max_prompt_tokens\": max(x for x, _ in prompt_and_pairs),\n",
    "            \"max_completion_tokens\": max(y for _, y in prompt_and_pairs), \"implicit_reference\": True}\n",
    "\n",
    "\n",
    "def fit_dpo(source, tok, rows, name, *, steps=20):\n",
    "    set_seed(SEED)\n",
    "    base = model_at(source)\n",
    "    base.config.use_cache = False\n",
    "    args = DPOConfig(\n",
    "        output_dir=str(OUT / f\"{name}-trainer\"), max_steps=steps,\n",
    "        per_device_train_batch_size=2, gradient_accumulation_steps=2,\n",
    "        learning_rate=1e-5, lr_scheduler_type=\"constant\",\n",
    "        beta=0.1, loss_type=\"sigmoid\", max_length=PROMPT_LIMIT + ANSWER_LIMIT,\n",
    "        max_prompt_length=PROMPT_LIMIT, max_completion_length=ANSWER_LIMIT,\n",
    "        use_logits_to_keep=True, fp16=True, bf16=False, gradient_checkpointing=True,\n",
    "        gradient_checkpointing_kwargs={\"use_reentrant\": False},\n",
    "        logging_steps=4, save_strategy=\"no\", report_to=\"none\", seed=SEED, data_seed=SEED,\n",
    "    )\n",
    "    # TRL adds EOS to each plain-text completion. The prompt already ends at the assistant header.\n",
    "    rendered = [{\"prompt\": tok.apply_chat_template(row[\"prompt\"], tokenize=False, add_generation_prompt=True),\n",
    "                 **{side: row[side][0][\"content\"] for side in (\"chosen\", \"rejected\")}} for row in rows]\n",
    "    trainer = DPOTrainer(\n",
    "        model=base, args=args, train_dataset=Dataset.from_list(rendered),\n",
    "        processing_class=tok, peft_config=lora(),\n",
    "    )\n",
    "    scaler = trainer.accelerator.scaler\n",
    "    initial_loss_scale = None\n",
    "    if scaler is not None:\n",
    "        # Summed completion log probabilities can overflow at the default FP16 scale.\n",
    "        initial_loss_scale = 1.0\n",
    "        scaler.load_state_dict({**scaler.state_dict(), \"scale\": initial_loss_scale})\n",
    "    if trainer.optimizer is not None or trainer.lr_scheduler is not None:\n",
    "        raise AssertionError(\"DPO must construct a fresh optimizer and scheduler.\")\n",
    "    if trainer.ref_model is not None or not trainer.is_peft_model or trainer.ref_adapter_name is not None:\n",
    "        raise AssertionError(\"DPO must score reference log probabilities with its fresh adapter disabled.\")\n",
    "    verification = check_dpo_completions(trainer, rows, tok)\n",
    "    stats = {**capture_fit(trainer), **verification, \"beta\": args.beta,\n",
    "             \"learning_rate\": args.learning_rate, \"pairs_per_update\": 4,\n",
    "             \"initial_loss_scale\": initial_loss_scale}\n",
    "    path = str(OUT / name)\n",
    "    trainer.model.save_pretrained(path)\n",
    "    del trainer, base\n",
    "    clean_memory()\n",
    "    print(name, {key: value for key, value in stats.items() if key != \"log\"})\n",
    "    return path, stats\n",
    "\n",
    "\n",
    "def adapter_sha(path):\n",
    "    digest = hashlib.sha256()\n",
    "    with (Path(path) / \"adapter_model.safetensors\").open(\"rb\") as f:\n",
    "        for block in iter(lambda: f.read(1024 * 1024), b\"\"):\n",
    "            digest.update(block)\n",
    "    return digest.hexdigest()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5d622374",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Lesson 06 split, checkpoint and budget contracts for the matched ablation.\"\"\"\n",
    "\n",
    "SFT_STEPS = 32\n",
    "DPO_STEPS = 20\n",
    "GRPO_STEPS = 10\n",
    "SCREEN_STEPS = 3\n",
    "SCREEN_RATES = (8e-6, 2e-5)\n",
    "FIT_COUNTS = {\"sft\": 288, \"dpo_candidates\": 168, \"grpo\": 64, \"screen\": 32}\n",
    "PROFILE_LIMIT_SECONDS = {\"SFT\": 35, \"DPO\": 45, \"GRPO\": 60}\n",
    "\n",
    "\n",
    "def stage_partitions(catalog):\n",
    "    fit = [item for item in catalog if item.split == \"train\"]\n",
    "    random.Random(SEED).shuffle(fit)\n",
    "    groups = {}\n",
    "    start = 0\n",
    "    for purpose, count in FIT_COUNTS.items():\n",
    "        groups[purpose] = fit[start:start + count]\n",
    "        if len(groups[purpose]) != count:\n",
    "            raise ValueError(f\"{purpose} needs {count} training records.\")\n",
    "        start += count\n",
    "    groups.update(\n",
    "        unused_train=fit[start:],\n",
    "        development=fixed_eval(catalog, per_slice=12, splits=(\"dev\",)),\n",
    "        teaching=fixed_eval(catalog),\n",
    "        release=fixed_eval(catalog, splits=(\"release\",)),\n",
    "    )\n",
    "    ids = [item.key for rows in groups.values() for item in rows]\n",
    "    if len(ids) != len(set(ids)) or len({item.key for item in catalog}) != len(catalog):\n",
    "        raise ValueError(\"An invoice ID is repeated across the fit, selection or held-out roster.\")\n",
    "    by_purpose = [fit, fixed_eval(catalog, splits=(\"dev\",)), groups[\"teaching\"], groups[\"release\"]]\n",
    "    family_sets = [{item.family for item in rows} for rows in by_purpose]\n",
    "    if sum(map(len, family_sets)) != len(set.union(*family_sets)):\n",
    "        raise ValueError(\"Training, development, teaching and release must use disjoint families.\")\n",
    "    if len(groups[\"teaching\"]) != 240 or len(groups[\"development\"]) != 12:\n",
    "        raise ValueError(\"The course's fixed teaching or development size changed.\")\n",
    "    return groups\n",
    "\n",
    "\n",
    "def split_receipts(groups, preference_pairs):\n",
    "    report = {purpose: {\"n\": len(rows), \"families\": sorted({item.family for item in rows}),\n",
    "                        \"sha256\": manifest(rows), \"ids\": [item.key for item in rows]}\n",
    "              for purpose, rows in groups.items()}\n",
    "    eligible = {item.key: item for item in groups[\"dpo_candidates\"]}\n",
    "    selected = [row[\"record_key\"] for row in preference_pairs]\n",
    "    if len(selected) != len(set(selected)) or set(selected) - eligible.keys():\n",
    "        raise ValueError(\"DPO pairs escaped their assigned training pool.\")\n",
    "    report[\"dpo_pairs\"] = {\"n\": len(selected), \"ids\": selected,\n",
    "                           \"sha256\": manifest([eligible[key] for key in selected])}\n",
    "    return report\n",
    "\n",
    "\n",
    "def checkpoint_receipt(path):\n",
    "    if path == MODEL_ID:\n",
    "        return {\"path\": path, \"revision\": MODEL_REV}\n",
    "    return {\"path\": path, \"sha256\": checkpoint_digest(path)}\n",
    "\n",
    "\n",
    "def verified_parent(receipt):\n",
    "    path = receipt[\"path\"]\n",
    "    if checkpoint_receipt(path) != receipt:\n",
    "        raise ValueError(f\"Stage parent changed after it was sealed: {path}\")\n",
    "    return path\n",
    "\n",
    "\n",
    "def record_stage(parent, adapter, merged=None):\n",
    "    return {\"parent\": parent, \"adapter\": checkpoint_receipt(adapter),\n",
    "            \"adapter_sha256\": adapter_sha(adapter),\n",
    "            \"merged\": checkpoint_receipt(merged) if merged else None}\n",
    "\n",
    "\n",
    "def assert_matched_grpo(left, right, steps, prompt_ids, *, same_rate):\n",
    "    fields = (\"reward_kind\", \"beta\", \"prompt_ids_sha256\", \"prompt_roster_sha256\",\n",
    "              \"generation_group_size\", \"generation_settings\", \"initial_adapter_sha256\",\n",
    "              \"rollout_invoice_ids\", \"steps\", \"optimizer_updates\", \"completions_sampled\")\n",
    "    if same_rate:\n",
    "        fields += (\"learning_rate\",)\n",
    "    unequal = [field for field in fields if left[field] != right[field]]\n",
    "    if unequal:\n",
    "        raise AssertionError(f\"Matched GRPO runs differ on {unequal}.\")\n",
    "    ids = left[\"rollout_invoice_ids\"]\n",
    "    settings = left[\"generation_settings\"]\n",
    "    if (left[\"generation_group_size\"] != GROUP_SIZE or left[\"reward_kind\"] != \"semantic\"\n",
    "            or left[\"beta\"] != 0.0 or settings[\"max_new_tokens\"] != ANSWER_LIMIT\n",
    "            or not settings[\"do_sample\"]):\n",
    "        raise AssertionError(\"GRPO changed the declared sampling or reward configuration.\")\n",
    "    if (left[\"steps\"], left[\"optimizer_updates\"], left[\"completions_sampled\"]) != (\n",
    "        steps, steps, steps * GROUP_SIZE,\n",
    "    ) or len(set(ids)) != steps or len(ids) != steps or set(ids) - set(prompt_ids):\n",
    "        raise AssertionError(\"GRPO did not draw the declared distinct prompts and completion budget.\")\n",
    "\n",
    "\n",
    "def require_same_eval_roster(scores, invoices):\n",
    "    expected = [(row.key, row.family, row.split) for row in invoices]\n",
    "    actual = [(row[\"key\"], row[\"family\"], row[\"split\"]) for row in scores]\n",
    "    if actual != expected:\n",
    "        raise ValueError(\"A checkpoint did not evaluate the frozen invoice roster in order.\")\n",
    "\n",
    "\n",
    "def lr_score(row):\n",
    "    return row[\"exact\"], row[\"row_f1\"]\n",
    "\n",
    "\n",
    "def select_rate(screen):\n",
    "    return max(screen, key=lambda rate: (*lr_score(screen[rate][\"development\"]), -rate))\n",
    "\n",
    "\n",
    "def profile_check(label, stats, gpu_total_gib):\n",
    "    peak_limit = min(gpu_total_gib * 0.85, stats[\"free_before_gib\"] - 2)\n",
    "    passed = (\n",
    "        stats[\"steps\"] == stats[\"optimizer_updates\"] == 1\n",
    "        and 0 < stats[\"peak_allocated_gib\"] <= stats[\"peak_reserved_gib\"] <= peak_limit\n",
    "        and 0 < stats[\"seconds\"] <= PROFILE_LIMIT_SECONDS[label]\n",
    "        and stats[\"allocated_after_gib\"] <= stats[\"allocated_before_gib\"] + 0.125\n",
    "    )\n",
    "    return {**stats, \"pass\": passed, \"reserved_limit_gib\": peak_limit,\n",
    "            \"train_seconds_limit\": PROFILE_LIMIT_SECONDS[label]}\n",
    "\n",
    "\n",
    "def run_t4_profile(tok, supervised, pairs, policy):\n",
    "    \"\"\"Run the same FP16 trainer paths for one update each using only fit invoices.\"\"\"\n",
    "    if DEVICE != \"cuda\" or not torch.cuda.is_available() or \"T4\" not in torch.cuda.get_device_name(0):\n",
    "        raise RuntimeError(\"The hardware profile requires a T4.\")\n",
    "    gpu = torch.cuda.get_device_properties(0)\n",
    "    # Use long approved examples from each stage's assigned training pool.\n",
    "    full_sft = lambda row: len(encode_supervised(row, tok)[\"input_ids\"])\n",
    "    full_dpo = lambda row: len(preference_features(row, tok)[0][\"input_ids\"])\n",
    "    long_sft = sorted(supervised, key=full_sft, reverse=True)[:8]\n",
    "    long_pairs = sorted(pairs, key=full_dpo, reverse=True)[:4]\n",
    "    long_policy = [max(policy, key=lambda row: len(prompt_tokens(row, tok)))]\n",
    "    profile_runs = {\n",
    "        \"SFT\": lambda: fit_sft(long_sft, tok, \"06-profile-sft\", steps=1),\n",
    "        \"DPO\": lambda: fit_dpo(MODEL_ID, tok, long_pairs, \"06-profile-dpo\", steps=1),\n",
    "        \"GRPO\": lambda: fit_grpo(MODEL_ID, tok, long_policy, \"06-profile-grpo\", steps=1, save_adapter=False),\n",
    "    }\n",
    "    total_gib = gpu.total_memory / 2**30\n",
    "    receipt = {\"hardware\": gpu.name, \"device_gib\": total_gib, \"cuda\": torch.version.cuda,\n",
    "               \"parent_revision\": MODEL_REV, \"profiles\": {}}\n",
    "    path = OUT / \"06-t4-profile.json\"\n",
    "    for label, train_one_step in profile_runs.items():\n",
    "        clean_memory()\n",
    "        torch.cuda.synchronize()\n",
    "        free_before, _ = torch.cuda.mem_get_info()\n",
    "        allocated_before = torch.cuda.memory_allocated()\n",
    "        started = time.perf_counter()\n",
    "        try:\n",
    "            if free_before < 12 * 2**30:\n",
    "                raise RuntimeError(f\"The T4 has {free_before / 2**30:.2f} GiB free. Preflight requires 12 GiB.\")\n",
    "            _, stats = train_one_step()\n",
    "        except RuntimeError as error:\n",
    "            receipt[\"profiles\"][label] = {\"pass\": False, \"error\": str(error)}\n",
    "            path.write_text(json.dumps(receipt, indent=2, allow_nan=False) + \"\\n\")\n",
    "            raise RuntimeError(f\"T4 {label} preflight failed. See {path}.\") from error\n",
    "        clean_memory()\n",
    "        torch.cuda.synchronize()\n",
    "        stats = {key: value for key, value in stats.items() if key != \"log\"}\n",
    "        stats.update(wall_seconds=time.perf_counter() - started, free_before_gib=free_before / 2**30,\n",
    "                     allocated_before_gib=allocated_before / 2**30,\n",
    "                     allocated_after_gib=torch.cuda.memory_allocated() / 2**30)\n",
    "        stats = profile_check(label, stats, total_gib)\n",
    "        receipt[\"profiles\"][label] = stats\n",
    "        path.write_text(json.dumps(receipt, indent=2, allow_nan=False) + \"\\n\")\n",
    "        print(label, {key: stats[key] for key in (\n",
    "            \"seconds\", \"wall_seconds\", \"peak_allocated_gib\", \"peak_reserved_gib\", \"pass\",\n",
    "        )})\n",
    "        if not stats[\"pass\"]:\n",
    "            raise RuntimeError(f\"T4 {label} preflight exceeded its one-step budget. See {path}.\")\n",
    "    receipt[\"projected_training_seconds\"] = sum(\n",
    "        receipt[\"profiles\"][label][\"seconds\"] * steps\n",
    "        for label, steps in ((\"SFT\", SFT_STEPS), (\"DPO\", DPO_STEPS),\n",
    "                             (\"GRPO\", 2 * GRPO_STEPS + len(SCREEN_RATES) * SCREEN_STEPS))\n",
    "    )\n",
    "    path.write_text(json.dumps(receipt, indent=2, allow_nan=False) + \"\\n\")\n",
    "    return receipt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "323697c9",
   "metadata": {},
   "source": [
    "## 2. Freeze the inputs for each stage\n",
    "\n",
    "The invoices are synthetic. The labelled training invoices, preference candidates, reward prompts\n",
    "and learning-rate probe prompts have distinct invoice IDs. Development, teaching and release also\n",
    "use separate invoice families. The teaching set compares unseen invoices under familiar layouts,\n",
    "novel layouts and a separate layout. The release roster is reserved.\n",
    "\n",
    "A preference pair changes exactly one field. The chosen record copies the printed amount due.\n",
    "Its rejected counterpart increments that same value by one minor unit. Both completions retain\n",
    "their structure and have the same token count through the end-of-sequence marker."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "69617a7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tesla T4 | 2.14.1+cu130 | revision 7ae557604adf\n",
      "Trainer packages {'transformers': '4.51.3', 'peft': '0.15.2', 'trl': '0.19.1', 'accelerate': '1.6.0', 'datasets': '3.6.0'} | CUDA 13.0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'sft': 288, 'dpo_candidates': 168, 'grpo': 64, 'screen': 32, 'unused_train': 24, 'development': 12, 'teaching': 240, 'release': 120, 'dpo_pairs': 96}\n"
     ]
    }
   ],
   "source": [
    "tok = prepare_kernel()\n",
    "catalog = make_catalog()\n",
    "groups = stage_partitions(catalog)\n",
    "teaching = groups[\"teaching\"]\n",
    "dev = groups[\"development\"]\n",
    "warm_rows = [supervised_row(invoice) for invoice in groups[\"sft\"]]\n",
    "pairs = preference_rows(groups[\"dpo_candidates\"], tok)\n",
    "rollouts = grpo_rows(groups[\"grpo\"])\n",
    "screen_prompts = grpo_rows(groups[\"screen\"])\n",
    "splits = split_receipts(groups, pairs)\n",
    "print({name: receipt[\"n\"] for name, receipt in splits.items()})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da3e1c5a",
   "metadata": {},
   "source": [
    "## 3. Profile one real update on the T4\n",
    "\n",
    "Test SFT, DPO and GRPO using long examples from their own training pools and the pinned base.\n",
    "Each disposable fit runs a full optimizer update with the production batch size and precision.\n",
    "Stop if step time or reserved VRAM exceeds the stated limits. These measurements bound the\n",
    "observed preflight workload. Later generation length, loading and evaluation can change total time."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1d01797f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='1' max='1' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [1/1 00:00, Epoch 1/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-profile-sft {'steps': 1, 'optimizer_updates': 1, 'seconds': 3.6310774180001317, 'peak_allocated_gib': 3.383582592010498, 'peak_reserved_gib': 4.759765625, 'max_prompt_tokens': 217, 'max_label_tokens': 132, 'examples': 8, 'learning_rate': 0.0002, 'roster_supervised_tokens': 1051, 'examples_per_update': 8}\n",
      "SFT {'seconds': 3.6310774180001317, 'wall_seconds': 6.05097271700015, 'peak_allocated_gib': 3.383582592010498, 'peak_reserved_gib': 4.759765625, 'pass': True}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='1' max='1' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [1/1 00:00, Epoch 1/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-profile-dpo {'steps': 1, 'optimizer_updates': 1, 'seconds': 1.5227429520000442, 'peak_allocated_gib': 1.9237313270568848, 'peak_reserved_gib': 3.15234375, 'verified_pairs': 4, 'max_prompt_tokens': 215, 'max_completion_tokens': 130, 'implicit_reference': True, 'beta': 0.1, 'learning_rate': 1e-05, 'pairs_per_update': 4, 'initial_loss_scale': 1.0}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DPO {'seconds': 1.5227429520000442, 'wall_seconds': 3.827166546999706, 'peak_allocated_gib': 1.9237313270568848, 'peak_reserved_gib': 3.15234375, 'pass': True}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='1' max='1' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [1/1 00:00, Epoch 1/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-profile-grpo {'steps': 1, 'optimizer_updates': 1, 'seconds': 13.518826016000276, 'peak_allocated_gib': 4.791354179382324, 'peak_reserved_gib': 5.232421875, 'max_prompt_tokens': 216, 'max_label_tokens': 0, 'reward_kind': 'semantic', 'learning_rate': 2e-05, 'beta': 0.0, 'initial_adapter_sha256': 05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170, 'prompt_roster_sha256': cf1f53f55e6af5fb5de4ea3664b190a5dee21d8f37ba3d1002f09364ed5c4d4e, 'prompt_ids_sha256': 924bdfba07d2a919ef30496e43fb7fe51dc950f0011d360e859a111dee5dc366, 'generation_group_size': 4, 'rollout_invoice_ids': ['SF-396874'], 'completions_sampled': 4, 'generation_settings': {'max_new_tokens': 256, 'do_sample': True, 'temperature': 0.8, 'top_k': None, 'pad_token_id': 151643, 'eos_token_id': 151645, 'transformers_version': '4.51.3'}}\n",
      "GRPO {'seconds': 13.518826016000276, 'wall_seconds': 15.123694217999855, 'peak_allocated_gib': 4.791354179382324, 'peak_reserved_gib': 5.232421875, 'pass': True}\n",
      "Training-only projection, seconds: 498.13881283201226\n"
     ]
    }
   ],
   "source": [
    "profile = run_t4_profile(tok, warm_rows, pairs, rollouts)\n",
    "print(\"Training-only projection, seconds:\", profile[\"projected_training_seconds\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a4ae1de",
   "metadata": {},
   "source": [
    "## 4. Rebuild and fingerprint the supervised anchor\n",
    "\n",
    "Train on assistant tokens, including EOS. The collator check binds the loss to these tokens and masks\n",
    "the system, invoice and padding positions. Merge the adapter into the pinned base. Later stages start\n",
    "with the verified weights and a fresh optimiser."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "844d894e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='32' max='32' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [32/32 00:22, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.162700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>0.048600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>0.020500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>0.010300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>0.004500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>24</td>\n",
       "      <td>0.005500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>28</td>\n",
       "      <td>0.001300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>32</td>\n",
       "      <td>0.006500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-sft {'steps': 32, 'optimizer_updates': 32, 'seconds': 24.116822763000073, 'peak_allocated_gib': 3.3901567459106445, 'peak_reserved_gib': 14.044921875, 'max_prompt_tokens': 217, 'max_label_tokens': 132, 'examples': 288, 'learning_rate': 0.0002, 'roster_supervised_tokens': 31748, 'examples_per_update': 8}\n"
     ]
    }
   ],
   "source": [
    "base_parent = checkpoint_receipt(MODEL_ID)\n",
    "warm_path, warm_stats = fit_sft(warm_rows, tok, \"06-sft\", source=verified_parent(base_parent), steps=SFT_STEPS)\n",
    "warm_merged = merge_adapter(MODEL_ID, warm_path, \"06-sft-merged\")\n",
    "warm_stage = record_stage(base_parent, warm_path, warm_merged)\n",
    "warm_parent = warm_stage[\"merged\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f08ac513",
   "metadata": {},
   "source": [
    "## 5. Select one learning rate on development families\n",
    "\n",
    "Start both probes from the same saved SFT anchor. Fit on the probe training pool and score only\n",
    "the development invoices. Sort by exact record rate, then line-item F1, then ascending learning\n",
    "rate. Carry the chosen rate into both scored reward arms. Each starts from its declared parent."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c23a837e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='3' max='3' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [3/3 00:11, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-screen-0 {'steps': 3, 'optimizer_updates': 3, 'seconds': 18.808421439000085, 'peak_allocated_gib': 3.2891359329223633, 'peak_reserved_gib': 3.5859375, 'max_prompt_tokens': 217, 'max_label_tokens': 0, 'reward_kind': 'semantic', 'learning_rate': 8e-06, 'beta': 0.0, 'initial_adapter_sha256': 05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170, 'prompt_roster_sha256': a9940ffe34f6dd973290978a0b4b635dd80ac7f9806848759cfc511c80a070b8, 'prompt_ids_sha256': 86a1fcd53fc47d711de602276f670d682d8ea0239692f49bd13dcb1cd01c8dc8, 'generation_group_size': 4, 'rollout_invoice_ids': ['SF-563210', 'SF-885244', 'SF-850619'], 'completions_sampled': 12, 'generation_settings': {'max_new_tokens': 256, 'do_sample': True, 'temperature': 0.8, 'top_k': None, 'pad_token_id': 151643, 'eos_token_id': 151645, 'transformers_version': '4.51.3'}, 'adapter_sha256': 489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='3' max='3' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [3/3 00:10, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-screen-1 {'steps': 3, 'optimizer_updates': 3, 'seconds': 17.724870507000105, 'peak_allocated_gib': 3.2891359329223633, 'peak_reserved_gib': 3.5859375, 'max_prompt_tokens': 217, 'max_label_tokens': 0, 'reward_kind': 'semantic', 'learning_rate': 2e-05, 'beta': 0.0, 'initial_adapter_sha256': 05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170, 'prompt_roster_sha256': a9940ffe34f6dd973290978a0b4b635dd80ac7f9806848759cfc511c80a070b8, 'prompt_ids_sha256': 86a1fcd53fc47d711de602276f670d682d8ea0239692f49bd13dcb1cd01c8dc8, 'generation_group_size': 4, 'rollout_invoice_ids': ['SF-563210', 'SF-885244', 'SF-850619'], 'completions_sampled': 12, 'generation_settings': {'max_new_tokens': 256, 'do_sample': True, 'temperature': 0.8, 'top_k': None, 'pad_token_id': 151643, 'eos_token_id': 151645, 'transformers_version': '4.51.3'}, 'adapter_sha256': 489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Selected GRPO rate on development rows: 8e-06\n"
     ]
    }
   ],
   "source": [
    "screen = {}\n",
    "for index, rate in enumerate(SCREEN_RATES):\n",
    "    trial_source = verified_parent(warm_parent)\n",
    "    trial_adapter, trial_stats = fit_grpo(\n",
    "        trial_source, tok, screen_prompts, f\"06-screen-{index}\", steps=SCREEN_STEPS, lr=rate,\n",
    "    )\n",
    "    trial_stage = record_stage(warm_parent, trial_adapter)\n",
    "    trial_eval = evaluate_at(trial_source, tok, dev, adapter=verified_parent(trial_stage[\"adapter\"]))\n",
    "    require_same_eval_roster(trial_eval, dev)\n",
    "    screen[rate] = {\"training\": trial_stats, \"development\": summary(trial_eval), \"checkpoint\": trial_stage}\n",
    "assert_matched_grpo(\n",
    "    *(trial[\"training\"] for trial in screen.values()), SCREEN_STEPS, splits[\"screen\"][\"ids\"], same_rate=False,\n",
    ")\n",
    "chosen_rate = select_rate(screen)\n",
    "print(\"Selected GRPO rate on development rows:\", chosen_rate)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c16f5094",
   "metadata": {},
   "source": [
    "## 6. Add the preference stage\n",
    "\n",
    "Direct Preference Optimisation ranks the literal printed total ahead of a one-unit corruption.\n",
    "TRL scores the untruncated chosen and rejected completion tokens. It disables the new PEFT adapter\n",
    "to obtain reference scores from the SFT parent. Merge the DPO update so evaluation and the next\n",
    "training stage both load the same saved weights."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "683429f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='20' max='20' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [20/20 00:17, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.685900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>0.655500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>0.626500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>0.590800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>20</td>\n",
       "      <td>0.560300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-dpo {'steps': 20, 'optimizer_updates': 20, 'seconds': 18.62419223200004, 'peak_allocated_gib': 2.172210216522217, 'peak_reserved_gib': 6.556640625, 'verified_pairs': 96, 'max_prompt_tokens': 215, 'max_completion_tokens': 132, 'implicit_reference': True, 'beta': 0.1, 'learning_rate': 1e-05, 'pairs_per_update': 4, 'initial_loss_scale': 1.0}\n"
     ]
    }
   ],
   "source": [
    "dpo_source = verified_parent(warm_parent)\n",
    "dpo_path, dpo_stats = fit_dpo(dpo_source, tok, pairs, \"06-dpo\", steps=DPO_STEPS)\n",
    "dpo_merged = merge_adapter(dpo_source, dpo_path, \"06-dpo-merged\")\n",
    "dpo_stage = record_stage(warm_parent, dpo_path, dpo_merged)\n",
    "dpo_parent = dpo_stage[\"merged\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bca58e87",
   "metadata": {},
   "source": [
    "## 7. Apply the same reward stage to both parents\n",
    "\n",
    "Start GRPO once from SFT and once from SFT plus DPO. Keep the initial GRPO adapter, learning rate,\n",
    "ordered prompts, seed, generation settings and rollout budget matched. The starting policy weights\n",
    "can produce different completions. Set the GRPO KL coefficient to zero in both fits."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b35a0615",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='10' max='10' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [10/10 00:56, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-sft-grpo {'steps': 10, 'optimizer_updates': 10, 'seconds': 62.491439963000175, 'peak_allocated_gib': 3.346090316772461, 'peak_reserved_gib': 4.158203125, 'max_prompt_tokens': 216, 'max_label_tokens': 0, 'reward_kind': 'semantic', 'learning_rate': 8e-06, 'beta': 0.0, 'initial_adapter_sha256': 05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170, 'prompt_roster_sha256': d981fe9a5e7690265ab124c9804ffa09da63ef1da3a82005124b72f28cf3b7b2, 'prompt_ids_sha256': a42f7b26c86e52c8c07c82b8a3fd6eb1d6b93fa1ede2f95c465be22c902a8986, 'generation_group_size': 4, 'rollout_invoice_ids': ['SF-325677', 'SF-642032', 'SF-835115', 'SF-287134', 'SF-866376', 'SF-630607', 'SF-469507', 'SF-617742', 'SF-501056', 'SF-428057'], 'completions_sampled': 40, 'generation_settings': {'max_new_tokens': 256, 'do_sample': True, 'temperature': 0.8, 'top_k': None, 'pad_token_id': 151643, 'eos_token_id': 151645, 'transformers_version': '4.51.3'}, 'adapter_sha256': 489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='10' max='10' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [10/10 00:51, Epoch 0/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "06-sft-dpo-grpo {'steps': 10, 'optimizer_updates': 10, 'seconds': 57.57017438499997, 'peak_allocated_gib': 3.346090316772461, 'peak_reserved_gib': 4.158203125, 'max_prompt_tokens': 216, 'max_label_tokens': 0, 'reward_kind': 'semantic', 'learning_rate': 8e-06, 'beta': 0.0, 'initial_adapter_sha256': 05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170, 'prompt_roster_sha256': d981fe9a5e7690265ab124c9804ffa09da63ef1da3a82005124b72f28cf3b7b2, 'prompt_ids_sha256': a42f7b26c86e52c8c07c82b8a3fd6eb1d6b93fa1ede2f95c465be22c902a8986, 'generation_group_size': 4, 'rollout_invoice_ids': ['SF-325677', 'SF-642032', 'SF-835115', 'SF-287134', 'SF-866376', 'SF-630607', 'SF-469507', 'SF-617742', 'SF-501056', 'SF-428057'], 'completions_sampled': 40, 'generation_settings': {'max_new_tokens': 256, 'do_sample': True, 'temperature': 0.8, 'top_k': None, 'pad_token_id': 151643, 'eos_token_id': 151645, 'transformers_version': '4.51.3'}, 'adapter_sha256': 74fa3b0bb5968e631a0e7ba59b97dfbc47d5b2a1893b8dd713480154efd880c2}\n"
     ]
    }
   ],
   "source": [
    "grpo_path, grpo_stats = fit_grpo(\n",
    "    verified_parent(warm_parent), tok, rollouts, \"06-sft-grpo\", steps=GRPO_STEPS, lr=chosen_rate,\n",
    ")\n",
    "stack_path, stack_stats = fit_grpo(\n",
    "    verified_parent(dpo_parent), tok, rollouts, \"06-sft-dpo-grpo\", steps=GRPO_STEPS, lr=chosen_rate,\n",
    ")\n",
    "grpo_stage = record_stage(warm_parent, grpo_path)\n",
    "stack_stage = record_stage(dpo_parent, stack_path)\n",
    "assert_matched_grpo(grpo_stats, stack_stats, GRPO_STEPS, splits[\"grpo\"][\"ids\"], same_rate=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b146c219",
   "metadata": {},
   "source": [
    "## 8. Compare all five checkpoints on the same held-out invoices\n",
    "\n",
    "Score one greedy extraction per invoice with the independent record evaluator. The exact score\n",
    "requires the whole record to match, including the printed total and every line. The two-by-two\n",
    "interaction subtracts the GRPO gain from SFT from the GRPO gain after DPO. Resample invoice families\n",
    "for the uncertainty interval."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1e853020",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"df-bb2fc52b-98d3-4cea-8214-6e1422e68b48\" class=\"colab-df-container\">\n",
       "    <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>n</th>\n",
       "      <th>exact</th>\n",
       "      <th>valid</th>\n",
       "      <th>row_f1</th>\n",
       "      <th>natural_completion</th>\n",
       "      <th>mean_generated_tokens</th>\n",
       "      <th>mean_ms_per_example_in_batch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Prompted base</th>\n",
       "      <td>240.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.733333</td>\n",
       "      <td>206.675000</td>\n",
       "      <td>1030.829700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SFT</th>\n",
       "      <td>240.0</td>\n",
       "      <td>0.591667</td>\n",
       "      <td>0.983333</td>\n",
       "      <td>0.904167</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>111.379167</td>\n",
       "      <td>527.379650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SFT \u2192 DPO</th>\n",
       "      <td>240.0</td>\n",
       "      <td>0.604167</td>\n",
       "      <td>0.979167</td>\n",
       "      <td>0.916667</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>111.541667</td>\n",
       "      <td>549.242952</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SFT \u2192 GRPO</th>\n",
       "      <td>240.0</td>\n",
       "      <td>0.591667</td>\n",
       "      <td>0.983333</td>\n",
       "      <td>0.904167</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>111.379167</td>\n",
       "      <td>775.370077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SFT \u2192 DPO \u2192 GRPO</th>\n",
       "      <td>240.0</td>\n",
       "      <td>0.604167</td>\n",
       "      <td>0.979167</td>\n",
       "      <td>0.916667</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>111.541667</td>\n",
       "      <td>762.319180</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "    <div class=\"colab-df-buttons\">\n",
       "      \n",
       "  <div class=\"colab-df-container\">\n",
       "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-bb2fc52b-98d3-4cea-8214-6e1422e68b48')\"\n",
       "            title=\"Convert this dataframe to an interactive table.\"\n",
       "            style=\"display:none;\">\n",
       "      \n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
       "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
       "  </svg>\n",
       "    </button>\n",
       "    \n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    .colab-df-buttons div {\n",
       "      margin-bottom: 4px;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "    <script>\n",
       "      const buttonEl =\n",
       "        document.querySelector('#df-bb2fc52b-98d3-4cea-8214-6e1422e68b48 button.colab-df-convert');\n",
       "      buttonEl.style.display =\n",
       "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "      async function convertToInteractive(key) {\n",
       "        const element = document.querySelector('#df-bb2fc52b-98d3-4cea-8214-6e1422e68b48');\n",
       "        const dataTable =\n",
       "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                    [key], {});\n",
       "        if (!dataTable) return;\n",
       "\n",
       "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "          + ' to learn more about interactive tables.';\n",
       "        element.innerHTML = '';\n",
       "        dataTable['output_type'] = 'display_data';\n",
       "        await google.colab.output.renderOutput(dataTable, element);\n",
       "        const docLink = document.createElement('div');\n",
       "        docLink.innerHTML = docLinkHtml;\n",
       "        element.appendChild(docLink);\n",
       "      }\n",
       "    </script>\n",
       "  </div>\n",
       "  \n",
       "    </div>\n",
       "  </div>\n",
       "  "
      ],
      "text/plain": [
       "                      n     exact     valid    row_f1  natural_completion  \\\n",
       "Prompted base     240.0  0.000000  0.000000  0.000000            0.733333   \n",
       "SFT               240.0  0.591667  0.983333  0.904167            1.000000   \n",
       "SFT \u2192 DPO         240.0  0.604167  0.979167  0.916667            1.000000   \n",
       "SFT \u2192 GRPO        240.0  0.591667  0.983333  0.904167            1.000000   \n",
       "SFT \u2192 DPO \u2192 GRPO  240.0  0.604167  0.979167  0.916667            1.000000   \n",
       "\n",
       "                  mean_generated_tokens  mean_ms_per_example_in_batch  \n",
       "Prompted base                206.675000                   1030.829700  \n",
       "SFT                          111.379167                    527.379650  \n",
       "SFT \u2192 DPO                    111.541667                    549.242952  \n",
       "SFT \u2192 GRPO                   111.379167                    775.370077  \n",
       "SFT \u2192 DPO \u2192 GRPO             111.541667                    762.319180  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paired stage interaction {'delta': 0.0, 'n': 240, 'families': 20, 'improved': 0, 'regressed': 0, 'tied': 240, 'paired_family_bootstrap_95': [0.0, 0.0]}\n"
     ]
    }
   ],
   "source": [
    "score_inputs = {\n",
    "    \"Prompted base\": (base_parent, None),\n",
    "    \"SFT\": (warm_parent, None),\n",
    "    \"SFT \u2192 DPO\": (dpo_parent, None),\n",
    "    \"SFT \u2192 GRPO\": (warm_parent, grpo_stage[\"adapter\"]),\n",
    "    \"SFT \u2192 DPO \u2192 GRPO\": (dpo_parent, stack_stage[\"adapter\"]),\n",
    "}\n",
    "results = {}\n",
    "for name, (parent, adapter) in score_inputs.items():\n",
    "    scores_for_stage = evaluate_at(\n",
    "        verified_parent(parent), tok, teaching, adapter=verified_parent(adapter) if adapter else None,\n",
    "    )\n",
    "    require_same_eval_roster(scores_for_stage, teaching)\n",
    "    results[name] = scores_for_stage\n",
    "base_scores, sft_scores, dpo_scores, grpo_scores, stack_scores = results.values()\n",
    "scores = {name: summary(rows) for name, rows in results.items()}\n",
    "increments = {\n",
    "    \"SFT minus base\": paired_change(base_scores, sft_scores),\n",
    "    \"DPO minus SFT\": paired_change(sft_scores, dpo_scores),\n",
    "    \"GRPO minus SFT\": paired_change(sft_scores, grpo_scores),\n",
    "    \"GRPO after DPO\": paired_change(dpo_scores, stack_scores),\n",
    "    \"combined minus SFT\": paired_change(sft_scores, stack_scores),\n",
    "}\n",
    "interaction = stage_interaction([sft_scores, dpo_scores, grpo_scores, stack_scores])\n",
    "display(pd.DataFrame(scores).T)\n",
    "print(\"Paired stage interaction\", interaction)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f552c9e",
   "metadata": {},
   "source": [
    "## 9. Export the comparisons, checkpoint chain and costs\n",
    "\n",
    "Keep the visible invoice, expected record and each observed completion so a reader can inspect a\n",
    "win or regression. Record fitted-stage time and peak VRAM separately from learning-rate selection,\n",
    "checkpoint loads and evaluation. The full stack carries the cost of all of its training stages."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6051b6b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"model\": \"Qwen/Qwen2.5-0.5B-Instruct\",\n",
      "  \"revision\": \"7ae557604adf67be50417f59c2c2f167def9a775\",\n",
      "  \"seed\": 42,\n",
      "  \"hardware\": \"Tesla T4\",\n",
      "  \"packages\": {\n",
      "    \"torch\": \"2.14.1+cu130\",\n",
      "    \"transformers\": \"4.51.3\",\n",
      "    \"peft\": \"0.15.2\",\n",
      "    \"trl\": \"0.19.1\",\n",
      "    \"accelerate\": \"1.6.0\",\n",
      "    \"datasets\": \"3.6.0\"\n",
      "  },\n",
      "  \"prompt_token_cap\": 512,\n",
      "  \"completion_token_cap\": 256,\n",
      "  \"catalog_version\": \"course-invoice-v1\",\n",
      "  \"catalog_sha256\": \"37510d1b8180e77bec12cef75d53e8381c8e70120ba215a29395f22b4b0a9403\",\n",
      "  \"split_rosters\": {\n",
      "    \"sft\": {\n",
      "      \"n\": 288,\n",
      "      \"families\": [\n",
      "        \"train-00\",\n",
      "        \"train-01\",\n",
      "        \"train-02\",\n",
      "        \"train-03\",\n",
      "        \"train-04\",\n",
      "        \"train-05\",\n",
      "        \"train-06\",\n",
      "        \"train-07\",\n",
      "        \"train-08\",\n",
      "        \"train-09\",\n",
      "        \"train-10\",\n",
      "        \"train-11\",\n",
      "        \"train-12\",\n",
      "        \"train-13\",\n",
      "        \"train-14\",\n",
      "        \"train-15\",\n",
      "        \"train-16\",\n",
      "        \"train-17\",\n",
      "        \"train-18\",\n",
      "        \"train-19\",\n",
      "        \"train-20\",\n",
      "        \"train-21\",\n",
      "        \"train-22\",\n",
      "        \"train-23\"\n",
      "      ],\n",
      "      \"sha256\": \"bdbecb7acb0de75e54f3d6b87c9fbeace7de9d176bf3453d48eb67a967e12031\",\n",
      "      \"ids\": [\n",
      "        \"SF-932834\",\n",
      "        \"SF-701137\",\n",
      "        \"SF-919659\",\n",
      "        \"SF-628174\",\n",
      "        \"SF-773278\",\n",
      "        \"SF-252477\",\n",
      "        \"SF-941883\",\n",
      "        \"SF-531542\",\n",
      "        \"SF-604836\",\n",
      "        \"SF-721421\",\n",
      "        \"SF-467393\",\n",
      "        \"SF-407040\",\n",
      "        \"SF-681271\",\n",
      "        \"SF-279605\",\n",
      "        \"SF-927524\",\n",
      "        \"SF-529320\",\n",
      "        \"SF-325026\",\n",
      "        \"SF-604047\",\n",
      "        \"SF-736493\",\n",
      "        \"SF-239765\",\n",
      "        \"SF-908750\",\n",
      "        \"SF-440401\",\n",
      "        \"SF-340283\",\n",
      "        \"SF-103688\",\n",
      "        \"SF-877976\",\n",
      "        \"SF-795500\",\n",
      "        \"SF-931622\",\n",
      "        \"SF-135390\",\n",
      "        \"SF-157637\",\n",
      "        \"SF-132488\",\n",
      "        \"SF-771661\",\n",
      "        \"SF-898991\",\n",
      "        \"SF-746585\",\n",
      "        \"SF-556118\",\n",
      "        \"SF-233487\",\n",
      "        \"SF-202696\",\n",
      "        \"SF-712695\",\n",
      "        \"SF-460078\",\n",
      "        \"SF-585083\",\n",
      "        \"SF-496183\",\n",
      "        \"SF-998772\",\n",
      "        \"SF-720523\",\n",
      "        \"SF-527427\",\n",
      "        \"SF-322072\",\n",
      "        \"SF-652885\",\n",
      "        \"SF-972099\",\n",
      "        \"SF-854497\",\n",
      "        \"SF-975629\",\n",
      "        \"SF-573034\",\n",
      "        \"SF-697493\",\n",
      "        \"SF-326916\",\n",
      "        \"SF-796098\",\n",
      "        \"SF-790226\",\n",
      "        \"SF-458807\",\n",
      "        \"SF-368719\",\n",
      "        \"SF-471938\",\n",
      "        \"SF-644023\",\n",
      "        \"SF-644547\",\n",
      "        \"SF-730575\",\n",
      "        \"SF-732619\",\n",
      "        \"SF-397858\",\n",
      "        \"SF-325675\",\n",
      "        \"SF-689260\",\n",
      "        \"SF-911020\",\n",
      "        \"SF-168785\",\n",
      "        \"SF-302292\",\n",
      "        \"SF-157053\",\n",
      "        \"SF-155467\",\n",
      "        \"SF-291811\",\n",
      "        \"SF-595338\",\n",
      "        \"SF-861899\",\n",
      "        \"SF-458686\",\n",
      "        \"SF-651716\",\n",
      "        \"SF-915225\",\n",
      "        \"SF-573548\",\n",
      "        \"SF-437167\",\n",
      "        \"SF-600245\",\n",
      "        \"SF-885222\",\n",
      "        \"SF-163812\",\n",
      "        \"SF-458294\",\n",
      "        \"SF-475319\",\n",
      "        \"SF-630677\",\n",
      "        \"SF-814870\",\n",
      "        \"SF-606170\",\n",
      "        \"SF-568718\",\n",
      "        \"SF-393890\",\n",
      "        \"SF-237194\",\n",
      "        \"SF-389115\",\n",
      "        \"SF-576979\",\n",
      "        \"SF-413160\",\n",
      "        \"SF-666823\",\n",
      "        \"SF-807448\",\n",
      "        \"SF-371721\",\n",
      "        \"SF-520324\",\n",
      "        \"SF-676878\",\n",
      "        \"SF-305531\",\n",
      "        \"SF-781895\",\n",
      "        \"SF-370306\",\n",
      "        \"SF-428921\",\n",
      "        \"SF-653181\",\n",
      "        \"SF-929321\",\n",
      "        \"SF-652493\",\n",
      "        \"SF-695426\",\n",
      "        \"SF-236695\",\n",
      "        \"SF-883807\",\n",
      "        \"SF-212544\",\n",
      "        \"SF-518848\",\n",
      "        \"SF-631626\",\n",
      "        \"SF-323078\",\n",
      "        \"SF-350233\",\n",
      "        \"SF-400936\",\n",
      "        \"SF-282641\",\n",
      "        \"SF-242181\",\n",
      "        \"SF-758076\",\n",
      "        \"SF-942300\",\n",
      "        \"SF-273372\",\n",
      "        \"SF-660749\",\n",
      "        \"SF-939601\",\n",
      "        \"SF-389116\",\n",
      "        \"SF-660620\",\n",
      "        \"SF-955599\",\n",
      "        \"SF-369184\",\n",
      "        \"SF-807546\",\n",
      "        \"SF-584656\",\n",
      "        \"SF-609797\",\n",
      "        \"SF-372440\",\n",
      "        \"SF-313932\",\n",
      "        \"SF-993678\",\n",
      "        \"SF-348113\",\n",
      "        \"SF-455114\",\n",
      "        \"SF-416095\",\n",
      "        \"SF-539732\",\n",
      "        \"SF-550701\",\n",
      "        \"SF-853410\",\n",
      "        \"SF-463978\",\n",
      "        \"SF-428633\",\n",
      "        \"SF-426040\",\n",
      "        \"SF-739044\",\n",
      "        \"SF-309003\",\n",
      "        \"SF-878130\",\n",
      "        \"SF-756708\",\n",
      "        \"SF-849389\",\n",
      "        \"SF-685959\",\n",
      "        \"SF-514614\",\n",
      "        \"SF-519321\",\n",
      "        \"SF-942931\",\n",
      "        \"SF-992196\",\n",
      "        \"SF-409021\",\n",
      "        \"SF-984689\",\n",
      "        \"SF-382917\",\n",
      "        \"SF-852113\",\n",
      "        \"SF-864693\",\n",
      "        \"SF-355937\",\n",
      "        \"SF-148275\",\n",
      "        \"SF-421980\",\n",
      "        \"SF-411401\",\n",
      "        \"SF-742797\",\n",
      "        \"SF-204172\",\n",
      "        \"SF-975546\",\n",
      "        \"SF-238946\",\n",
      "        \"SF-415645\",\n",
      "        \"SF-818214\",\n",
      "        \"SF-657194\",\n",
      "        \"SF-643147\",\n",
      "        \"SF-645757\",\n",
      "        \"SF-462232\",\n",
      "        \"SF-212224\",\n",
      "        \"SF-860676\",\n",
      "        \"SF-100002\",\n",
      "        \"SF-294075\",\n",
      "        \"SF-993060\",\n",
      "        \"SF-569622\",\n",
      "        \"SF-832858\",\n",
      "        \"SF-775409\",\n",
      "        \"SF-378447\",\n",
      "        \"SF-360826\",\n",
      "        \"SF-762616\",\n",
      "        \"SF-485416\",\n",
      "        \"SF-766219\",\n",
      "        \"SF-129547\",\n",
      "        \"SF-272691\",\n",
      "        \"SF-771360\",\n",
      "        \"SF-866503\",\n",
      "        \"SF-794721\",\n",
      "        \"SF-960816\",\n",
      "        \"SF-148730\",\n",
      "        \"SF-957361\",\n",
      "        \"SF-947071\",\n",
      "        \"SF-769358\",\n",
      "        \"SF-612414\",\n",
      "        \"SF-953140\",\n",
      "        \"SF-829705\",\n",
      "        \"SF-852757\",\n",
      "        \"SF-894377\",\n",
      "        \"SF-556235\",\n",
      "        \"SF-648455\",\n",
      "        \"SF-278819\",\n",
      "        \"SF-273124\",\n",
      "        \"SF-228875\",\n",
      "        \"SF-847065\",\n",
      "        \"SF-796866\",\n",
      "        \"SF-633896\",\n",
      "        \"SF-748605\",\n",
      "        \"SF-470387\",\n",
      "        \"SF-519457\",\n",
      "        \"SF-329071\",\n",
      "        \"SF-637261\",\n",
      "        \"SF-834749\",\n",
      "        \"SF-960465\",\n",
      "        \"SF-144214\",\n",
      "        \"SF-870167\",\n",
      "        \"SF-275818\",\n",
      "        \"SF-475519\",\n",
      "        \"SF-970938\",\n",
      "        \"SF-851512\",\n",
      "        \"SF-990750\",\n",
      "        \"SF-229561\",\n",
      "        \"SF-269638\",\n",
      "        \"SF-265594\",\n",
      "        \"SF-951217\",\n",
      "        \"SF-518592\",\n",
      "        \"SF-322124\",\n",
      "        \"SF-185500\",\n",
      "        \"SF-231446\",\n",
      "        \"SF-569228\",\n",
      "        \"SF-659953\",\n",
      "        \"SF-717039\",\n",
      "        \"SF-229805\",\n",
      "        \"SF-299244\",\n",
      "        \"SF-394802\",\n",
      "        \"SF-913263\",\n",
      "        \"SF-910338\",\n",
      "        \"SF-613737\",\n",
      "        \"SF-159606\",\n",
      "        \"SF-370239\",\n",
      "        \"SF-523401\",\n",
      "        \"SF-595442\",\n",
      "        \"SF-919819\",\n",
      "        \"SF-406553\",\n",
      "        \"SF-935074\",\n",
      "        \"SF-231789\",\n",
      "        \"SF-275635\",\n",
      "        \"SF-974560\",\n",
      "        \"SF-110618\",\n",
      "        \"SF-819549\",\n",
      "        \"SF-411860\",\n",
      "        \"SF-174897\",\n",
      "        \"SF-892093\",\n",
      "        \"SF-109206\",\n",
      "        \"SF-725462\",\n",
      "        \"SF-374017\",\n",
      "        \"SF-705617\",\n",
      "        \"SF-240856\",\n",
      "        \"SF-748164\",\n",
      "        \"SF-226852\",\n",
      "        \"SF-868812\",\n",
      "        \"SF-857729\",\n",
      "        \"SF-189486\",\n",
      "        \"SF-585533\",\n",
      "        \"SF-651779\",\n",
      "        \"SF-208270\",\n",
      "        \"SF-273171\",\n",
      "        \"SF-763703\",\n",
      "        \"SF-722636\",\n",
      "        \"SF-963495\",\n",
      "        \"SF-797890\",\n",
      "        \"SF-198511\",\n",
      "        \"SF-495228\",\n",
      "        \"SF-583218\",\n",
      "        \"SF-538519\",\n",
      "        \"SF-775230\",\n",
      "        \"SF-230687\",\n",
      "        \"SF-231152\",\n",
      "        \"SF-556618\",\n",
      "        \"SF-669723\",\n",
      "        \"SF-169838\",\n",
      "        \"SF-159877\",\n",
      "        \"SF-788442\",\n",
      "        \"SF-946338\",\n",
      "        \"SF-881131\",\n",
      "        \"SF-664941\",\n",
      "        \"SF-492841\",\n",
      "        \"SF-652092\",\n",
      "        \"SF-358345\",\n",
      "        \"SF-245778\",\n",
      "        \"SF-630820\",\n",
      "        \"SF-873814\",\n",
      "        \"SF-542531\"\n",
      "      ]\n",
      "    },\n",
      "    \"dpo_candidates\": {\n",
      "      \"n\": 168,\n",
      "      \"families\": [\n",
      "        \"train-00\",\n",
      "        \"train-01\",\n",
      "        \"train-02\",\n",
      "        \"train-03\",\n",
      "        \"train-04\",\n",
      "        \"train-05\",\n",
      "        \"train-06\",\n",
      "        \"train-07\",\n",
      "        \"train-08\",\n",
      "        \"train-09\",\n",
      "        \"train-10\",\n",
      "        \"train-11\",\n",
      "        \"train-12\",\n",
      "        \"train-13\",\n",
      "        \"train-14\",\n",
      "        \"train-15\",\n",
      "        \"train-16\",\n",
      "        \"train-17\",\n",
      "        \"train-18\",\n",
      "        \"train-19\",\n",
      "        \"train-20\",\n",
      "        \"train-21\",\n",
      "        \"train-22\",\n",
      "        \"train-23\"\n",
      "      ],\n",
      "      \"sha256\": \"fa868fe523986b54a16cd50a9e4286f92e1152ec9e353ce795f95188ef8e803c\",\n",
      "      \"ids\": [\n",
      "        \"SF-651508\",\n",
      "        \"SF-779735\",\n",
      "        \"SF-513412\",\n",
      "        \"SF-234277\",\n",
      "        \"SF-157375\",\n",
      "        \"SF-681994\",\n",
      "        \"SF-277352\",\n",
      "        \"SF-540371\",\n",
      "        \"SF-419924\",\n",
      "        \"SF-257731\",\n",
      "        \"SF-278734\",\n",
      "        \"SF-838331\",\n",
      "        \"SF-681852\",\n",
      "        \"SF-703937\",\n",
      "        \"SF-955241\",\n",
      "        \"SF-302305\",\n",
      "        \"SF-294698\",\n",
      "        \"SF-305025\",\n",
      "        \"SF-406495\",\n",
      "        \"SF-309658\",\n",
      "        \"SF-847838\",\n",
      "        \"SF-626332\",\n",
      "        \"SF-108715\",\n",
      "        \"SF-425310\",\n",
      "        \"SF-536066\",\n",
      "        \"SF-158596\",\n",
      "        \"SF-406272\",\n",
      "        \"SF-335651\",\n",
      "        \"SF-342794\",\n",
      "        \"SF-684858\",\n",
      "        \"SF-440161\",\n",
      "        \"SF-740586\",\n",
      "        \"SF-473923\",\n",
      "        \"SF-719829\",\n",
      "        \"SF-327852\",\n",
      "        \"SF-471428\",\n",
      "        \"SF-302828\",\n",
      "        \"SF-400509\",\n",
      "        \"SF-606165\",\n",
      "        \"SF-184577\",\n",
      "        \"SF-988466\",\n",
      "        \"SF-424194\",\n",
      "        \"SF-815017\",\n",
      "        \"SF-409733\",\n",
      "        \"SF-915055\",\n",
      "        \"SF-379315\",\n",
      "        \"SF-232799\",\n",
      "        \"SF-616570\",\n",
      "        \"SF-444107\",\n",
      "        \"SF-399518\",\n",
      "        \"SF-825649\",\n",
      "        \"SF-203063\",\n",
      "        \"SF-617677\",\n",
      "        \"SF-399624\",\n",
      "        \"SF-184367\",\n",
      "        \"SF-488356\",\n",
      "        \"SF-308492\",\n",
      "        \"SF-574810\",\n",
      "        \"SF-365741\",\n",
      "        \"SF-659895\",\n",
      "        \"SF-422935\",\n",
      "        \"SF-122389\",\n",
      "        \"SF-770304\",\n",
      "        \"SF-470426\",\n",
      "        \"SF-421431\",\n",
      "        \"SF-957778\",\n",
      "        \"SF-705959\",\n",
      "        \"SF-891006\",\n",
      "        \"SF-120329\",\n",
      "        \"SF-588006\",\n",
      "        \"SF-246857\",\n",
      "        \"SF-191073\",\n",
      "        \"SF-678143\",\n",
      "        \"SF-482700\",\n",
      "        \"SF-902388\",\n",
      "        \"SF-350981\",\n",
      "        \"SF-897602\",\n",
      "        \"SF-204891\",\n",
      "        \"SF-594010\",\n",
      "        \"SF-748453\",\n",
      "        \"SF-800980\",\n",
      "        \"SF-306925\",\n",
      "        \"SF-998520\",\n",
      "        \"SF-540623\",\n",
      "        \"SF-771322\",\n",
      "        \"SF-785612\",\n",
      "        \"SF-181050\",\n",
      "        \"SF-589807\",\n",
      "        \"SF-240903\",\n",
      "        \"SF-106348\",\n",
      "        \"SF-428518\",\n",
      "        \"SF-134926\",\n",
      "        \"SF-860353\",\n",
      "        \"SF-669120\",\n",
      "        \"SF-616152\",\n",
      "        \"SF-340287\",\n",
      "        \"SF-729479\",\n",
      "        \"SF-837068\",\n",
      "        \"SF-620359\",\n",
      "        \"SF-828548\",\n",
      "        \"SF-810251\",\n",
      "        \"SF-486495\",\n",
      "        \"SF-577519\",\n",
      "        \"SF-921659\",\n",
      "        \"SF-999146\",\n",
      "        \"SF-387083\",\n",
      "        \"SF-698995\",\n",
      "        \"SF-507012\",\n",
      "        \"SF-832989\",\n",
      "        \"SF-915678\",\n",
      "        \"SF-715260\",\n",
      "        \"SF-254805\",\n",
      "        \"SF-482947\",\n",
      "        \"SF-998847\",\n",
      "        \"SF-540283\",\n",
      "        \"SF-306623\",\n",
      "        \"SF-541015\",\n",
      "        \"SF-625099\",\n",
      "        \"SF-676348\",\n",
      "        \"SF-744057\",\n",
      "        \"SF-360010\",\n",
      "        \"SF-908693\",\n",
      "        \"SF-406567\",\n",
      "        \"SF-235614\",\n",
      "        \"SF-441515\",\n",
      "        \"SF-297947\",\n",
      "        \"SF-930937\",\n",
      "        \"SF-980763\",\n",
      "        \"SF-951232\",\n",
      "        \"SF-366204\",\n",
      "        \"SF-311381\",\n",
      "        \"SF-664234\",\n",
      "        \"SF-431495\",\n",
      "        \"SF-407094\",\n",
      "        \"SF-680003\",\n",
      "        \"SF-962495\",\n",
      "        \"SF-816846\",\n",
      "        \"SF-426839\",\n",
      "        \"SF-500406\",\n",
      "        \"SF-337591\",\n",
      "        \"SF-783565\",\n",
      "        \"SF-880157\",\n",
      "        \"SF-581781\",\n",
      "        \"SF-931691\",\n",
      "        \"SF-146966\",\n",
      "        \"SF-439186\",\n",
      "        \"SF-428317\",\n",
      "        \"SF-960888\",\n",
      "        \"SF-246594\",\n",
      "        \"SF-987675\",\n",
      "        \"SF-820432\",\n",
      "        \"SF-500930\",\n",
      "        \"SF-409809\",\n",
      "        \"SF-781457\",\n",
      "        \"SF-918875\",\n",
      "        \"SF-629378\",\n",
      "        \"SF-315349\",\n",
      "        \"SF-278613\",\n",
      "        \"SF-382886\",\n",
      "        \"SF-531933\",\n",
      "        \"SF-527310\",\n",
      "        \"SF-734300\",\n",
      "        \"SF-243219\",\n",
      "        \"SF-280550\",\n",
      "        \"SF-308989\",\n",
      "        \"SF-649982\",\n",
      "        \"SF-221819\",\n",
      "        \"SF-878021\"\n",
      "      ]\n",
      "    },\n",
      "    \"grpo\": {\n",
      "      \"n\": 64,\n",
      "      \"families\": [\n",
      "        \"train-00\",\n",
      "        \"train-01\",\n",
      "        \"train-02\",\n",
      "        \"train-03\",\n",
      "        \"train-04\",\n",
      "        \"train-05\",\n",
      "        \"train-06\",\n",
      "        \"train-07\",\n",
      "        \"train-08\",\n",
      "        \"train-09\",\n",
      "        \"train-10\",\n",
      "        \"train-11\",\n",
      "        \"train-12\",\n",
      "        \"train-13\",\n",
      "        \"train-14\",\n",
      "        \"train-15\",\n",
      "        \"train-16\",\n",
      "        \"train-17\",\n",
      "        \"train-18\",\n",
      "        \"train-19\",\n",
      "        \"train-20\",\n",
      "        \"train-21\",\n",
      "        \"train-22\",\n",
      "        \"train-23\"\n",
      "      ],\n",
      "      \"sha256\": \"251b307b583651d202a775d434fc3d1a4d9695cbbf9a15fd9d24f4aa5bba9317\",\n",
      "      \"ids\": [\n",
      "        \"SF-213426\",\n",
      "        \"SF-660042\",\n",
      "        \"SF-128983\",\n",
      "        \"SF-913480\",\n",
      "        \"SF-827575\",\n",
      "        \"SF-704254\",\n",
      "        \"SF-698951\",\n",
      "        \"SF-396874\",\n",
      "        \"SF-428057\",\n",
      "        \"SF-972516\",\n",
      "        \"SF-866376\",\n",
      "        \"SF-496094\",\n",
      "        \"SF-592251\",\n",
      "        \"SF-944410\",\n",
      "        \"SF-754076\",\n",
      "        \"SF-686567\",\n",
      "        \"SF-153218\",\n",
      "        \"SF-485982\",\n",
      "        \"SF-471917\",\n",
      "        \"SF-277169\",\n",
      "        \"SF-401354\",\n",
      "        \"SF-515915\",\n",
      "        \"SF-501056\",\n",
      "        \"SF-153095\",\n",
      "        \"SF-642032\",\n",
      "        \"SF-621041\",\n",
      "        \"SF-337936\",\n",
      "        \"SF-299223\",\n",
      "        \"SF-289746\",\n",
      "        \"SF-630607\",\n",
      "        \"SF-449191\",\n",
      "        \"SF-743351\",\n",
      "        \"SF-615629\",\n",
      "        \"SF-769540\",\n",
      "        \"SF-907941\",\n",
      "        \"SF-164838\",\n",
      "        \"SF-469507\",\n",
      "        \"SF-993877\",\n",
      "        \"SF-325677\",\n",
      "        \"SF-765828\",\n",
      "        \"SF-177975\",\n",
      "        \"SF-959343\",\n",
      "        \"SF-436932\",\n",
      "        \"SF-271949\",\n",
      "        \"SF-652695\",\n",
      "        \"SF-971015\",\n",
      "        \"SF-565022\",\n",
      "        \"SF-409458\",\n",
      "        \"SF-835115\",\n",
      "        \"SF-481238\",\n",
      "        \"SF-266450\",\n",
      "        \"SF-617742\",\n",
      "        \"SF-496845\",\n",
      "        \"SF-872584\",\n",
      "        \"SF-292199\",\n",
      "        \"SF-799076\",\n",
      "        \"SF-387217\",\n",
      "        \"SF-779471\",\n",
      "        \"SF-995414\",\n",
      "        \"SF-841720\",\n",
      "        \"SF-371879\",\n",
      "        \"SF-912644\",\n",
      "        \"SF-259112\",\n",
      "        \"SF-287134\"\n",
      "      ]\n",
      "    },\n",
      "    \"screen\": {\n",
      "      \"n\": 32,\n",
      "      \"families\": [\n",
      "        \"train-01\",\n",
      "        \"train-02\",\n",
      "        \"train-03\",\n",
      "        \"train-04\",\n",
      "        \"train-05\",\n",
      "        \"train-06\",\n",
      "        \"train-08\",\n",
      "        \"train-09\",\n",
      "        \"train-11\",\n",
      "        \"train-12\",\n",
      "        \"train-14\",\n",
      "        \"train-15\",\n",
      "        \"train-16\",\n",
      "        \"train-19\",\n",
      "        \"train-22\",\n",
      "        \"train-23\"\n",
      "      ],\n",
      "      \"sha256\": \"f666dfe85e33313798fca13e8287958e291c0d6b337f69b8f041e73c72d9b3c3\",\n",
      "      \"ids\": [\n",
      "        \"SF-491719\",\n",
      "        \"SF-409672\",\n",
      "        \"SF-679012\",\n",
      "        \"SF-989939\",\n",
      "        \"SF-463320\",\n",
      "        \"SF-466033\",\n",
      "        \"SF-563210\",\n",
      "        \"SF-417919\",\n",
      "        \"SF-440433\",\n",
      "        \"SF-495627\",\n",
      "        \"SF-984690\",\n",
      "        \"SF-939833\",\n",
      "        \"SF-948847\",\n",
      "        \"SF-885244\",\n",
      "        \"SF-982405\",\n",
      "        \"SF-906769\",\n",
      "        \"SF-824103\",\n",
      "        \"SF-332209\",\n",
      "        \"SF-850619\",\n",
      "        \"SF-290671\",\n",
      "        \"SF-703737\",\n",
      "        \"SF-747324\",\n",
      "        \"SF-122213\",\n",
      "        \"SF-979156\",\n",
      "        \"SF-574194\",\n",
      "        \"SF-806282\",\n",
      "        \"SF-212962\",\n",
      "        \"SF-767582\",\n",
      "        \"SF-216024\",\n",
      "        \"SF-260556\",\n",
      "        \"SF-842479\",\n",
      "        \"SF-907815\"\n",
      "      ]\n",
      "    },\n",
      "    \"unused_train\": {\n",
      "      \"n\": 24,\n",
      "      \"families\": [\n",
      "        \"train-00\",\n",
      "        \"train-01\",\n",
      "        \"train-03\",\n",
      "        \"train-04\",\n",
      "        \"train-05\",\n",
      "        \"train-06\",\n",
      "        \"train-08\",\n",
      "        \"train-09\",\n",
      "        \"train-10\",\n",
      "        \"train-11\",\n",
      "        \"train-17\",\n",
      "        \"train-18\",\n",
      "        \"train-19\",\n",
      "        \"train-21\",\n",
      "        \"train-23\"\n",
      "      ],\n",
      "      \"sha256\": \"df60a5868688312b8ab03ce43b5acd52df16e4dbc925bb9fbe41976bcf733072\",\n",
      "      \"ids\": [\n",
      "        \"SF-456995\",\n",
      "        \"SF-196133\",\n",
      "        \"SF-349372\",\n",
      "        \"SF-811594\",\n",
      "        \"SF-542526\",\n",
      "        \"SF-130633\",\n",
      "        \"SF-255802\",\n",
      "        \"SF-642941\",\n",
      "        \"SF-514186\",\n",
      "        \"SF-312650\",\n",
      "        \"SF-954931\",\n",
      "        \"SF-657203\",\n",
      "        \"SF-688778\",\n",
      "        \"SF-460472\",\n",
      "        \"SF-474746\",\n",
      "        \"SF-583748\",\n",
      "        \"SF-232889\",\n",
      "        \"SF-682775\",\n",
      "        \"SF-460242\",\n",
      "        \"SF-219059\",\n",
      "        \"SF-128446\",\n",
      "        \"SF-781574\",\n",
      "        \"SF-537040\",\n",
      "        \"SF-923986\"\n",
      "      ]\n",
      "    },\n",
      "    \"development\": {\n",
      "      \"n\": 12,\n",
      "      \"families\": [\n",
      "        \"dev-00\",\n",
      "        \"dev-01\",\n",
      "        \"dev-02\",\n",
      "        \"dev-04\"\n",
      "      ],\n",
      "      \"sha256\": \"8c4923fba2d566240026b0c961314c11c8765efc9fe1bff48d6cb4ea183772f8\",\n",
      "      \"ids\": [\n",
      "        \"SF-217022\",\n",
      "        \"SF-764673\",\n",
      "        \"SF-247981\",\n",
      "        \"SF-119095\",\n",
      "        \"SF-520437\",\n",
      "        \"SF-633294\",\n",
      "        \"SF-616349\",\n",
      "        \"SF-560072\",\n",
      "        \"SF-164925\",\n",
      "        \"SF-961128\",\n",
      "        \"SF-790927\",\n",
      "        \"SF-408575\"\n",
      "      ]\n",
      "    },\n",
      "    \"teaching\": {\n",
      "      \"n\": 240,\n",
      "      \"families\": [\n",
      "        \"familiar-00\",\n",
      "        \"familiar-01\",\n",
      "        \"familiar-02\",\n",
      "        \"familiar-03\",\n",
      "        \"familiar-04\",\n",
      "        \"familiar-05\",\n",
      "        \"familiar-06\",\n",
      "        \"familiar-07\",\n",
      "        \"independent-00\",\n",
      "        \"independent-01\",\n",
      "        \"independent-02\",\n",
      "        \"independent-03\",\n",
      "        \"novel-00\",\n",
      "        \"novel-01\",\n",
      "        \"novel-02\",\n",
      "        \"novel-03\",\n",
      "        \"novel-04\",\n",
      "        \"novel-05\",\n",
      "        \"novel-06\",\n",
      "        \"novel-07\"\n",
      "      ],\n",
      "      \"sha256\": \"1adfe68dde819bbf4aa95dfc8a64f78239de32caf4e71a861d81de10fbdaff28\",\n",
      "      \"ids\": [\n",
      "        \"SF-228794\",\n",
      "        \"SF-159804\",\n",
      "        \"SF-221570\",\n",
      "        \"SF-624231\",\n",
      "        \"SF-925400\",\n",
      "        \"SF-269212\",\n",
      "        \"SF-691062\",\n",
      "        \"SF-890511\",\n",
      "        \"SF-840063\",\n",
      "        \"SF-341606\",\n",
      "        \"SF-638331\",\n",
      "        \"SF-570135\",\n",
      "        \"SF-429916\",\n",
      "        \"SF-576379\",\n",
      "        \"SF-115343\",\n",
      "        \"SF-535585\",\n",
      "        \"SF-656977\",\n",
      "        \"SF-125620\",\n",
      "        \"SF-820677\",\n",
      "        \"SF-244377\",\n",
      "        \"SF-879624\",\n",
      "        \"SF-101362\",\n",
      "        \"SF-540511\",\n",
      "        \"SF-400702\",\n",
      "        \"SF-862527\",\n",
      "        \"SF-121864\",\n",
      "        \"SF-524553\",\n",
      "        \"SF-594508\",\n",
      "        \"SF-795507\",\n",
      "        \"SF-227429\",\n",
      "        \"SF-814577\",\n",
      "        \"SF-602629\",\n",
      "        \"SF-423905\",\n",
      "        \"SF-761156\",\n",
      "        \"SF-307640\",\n",
      "        \"SF-747944\",\n",
      "        \"SF-112096\",\n",
      "        \"SF-173476\",\n",
      "        \"SF-222568\",\n",
      "        \"SF-360326\",\n",
      "        \"SF-444543\",\n",
      "        \"SF-425535\",\n",
      "        \"SF-101117\",\n",
      "        \"SF-961161\",\n",
      "        \"SF-326149\",\n",
      "        \"SF-583861\",\n",
      "        \"SF-189777\",\n",
      "        \"SF-984838\",\n",
      "        \"SF-482832\",\n",
      "        \"SF-405682\",\n",
      "        \"SF-900335\",\n",
      "        \"SF-170922\",\n",
      "        \"SF-632745\",\n",
      "        \"SF-354674\",\n",
      "        \"SF-214424\",\n",
      "        \"SF-754577\",\n",
      "        \"SF-979869\",\n",
      "        \"SF-321619\",\n",
      "        \"SF-294113\",\n",
      "        \"SF-846025\",\n",
      "        \"SF-915589\",\n",
      "        \"SF-356438\",\n",
      "        \"SF-195376\",\n",
      "        \"SF-879674\",\n",
      "        \"SF-732205\",\n",
      "        \"SF-425158\",\n",
      "        \"SF-719047\",\n",
      "        \"SF-743181\",\n",
      "        \"SF-214454\",\n",
      "        \"SF-718477\",\n",
      "        \"SF-900897\",\n",
      "        \"SF-724228\",\n",
      "        \"SF-439970\",\n",
      "        \"SF-130995\",\n",
      "        \"SF-717709\",\n",
      "        \"SF-972666\",\n",
      "        \"SF-493288\",\n",
      "        \"SF-719087\",\n",
      "        \"SF-429216\",\n",
      "        \"SF-662352\",\n",
      "        \"SF-232089\",\n",
      "        \"SF-126816\",\n",
      "        \"SF-993765\",\n",
      "        \"SF-400427\",\n",
      "        \"SF-535315\",\n",
      "        \"SF-181336\",\n",
      "        \"SF-216245\",\n",
      "        \"SF-195902\",\n",
      "        \"SF-983022\",\n",
      "        \"SF-456433\",\n",
      "        \"SF-543218\",\n",
      "        \"SF-749889\",\n",
      "        \"SF-691814\",\n",
      "        \"SF-945985\",\n",
      "        \"SF-107997\",\n",
      "        \"SF-347126\",\n",
      "        \"SF-177277\",\n",
      "        \"SF-265176\",\n",
      "        \"SF-797533\",\n",
      "        \"SF-809721\",\n",
      "        \"SF-914755\",\n",
      "        \"SF-543235\",\n",
      "        \"SF-990836\",\n",
      "        \"SF-862677\",\n",
      "        \"SF-220439\",\n",
      "        \"SF-411187\",\n",
      "        \"SF-973701\",\n",
      "        \"SF-884235\",\n",
      "        \"SF-781239\",\n",
      "        \"SF-548824\",\n",
      "        \"SF-840609\",\n",
      "        \"SF-147721\",\n",
      "        \"SF-858135\",\n",
      "        \"SF-241401\",\n",
      "        \"SF-854708\",\n",
      "        \"SF-235300\",\n",
      "        \"SF-852990\",\n",
      "        \"SF-524399\",\n",
      "        \"SF-987667\",\n",
      "        \"SF-901964\",\n",
      "        \"SF-357240\",\n",
      "        \"SF-587791\",\n",
      "        \"SF-427614\",\n",
      "        \"SF-591204\",\n",
      "        \"SF-770084\",\n",
      "        \"SF-411464\",\n",
      "        \"SF-751836\",\n",
      "        \"SF-228773\",\n",
      "        \"SF-925112\",\n",
      "        \"SF-951132\",\n",
      "        \"SF-254647\",\n",
      "        \"SF-850856\",\n",
      "        \"SF-820102\",\n",
      "        \"SF-931161\",\n",
      "        \"SF-828365\",\n",
      "        \"SF-344359\",\n",
      "        \"SF-378664\",\n",
      "        \"SF-610572\",\n",
      "        \"SF-366356\",\n",
      "        \"SF-246869\",\n",
      "        \"SF-177298\",\n",
      "        \"SF-868618\",\n",
      "        \"SF-915455\",\n",
      "        \"SF-120555\",\n",
      "        \"SF-388963\",\n",
      "        \"SF-652364\",\n",
      "        \"SF-416814\",\n",
      "        \"SF-750969\",\n",
      "        \"SF-279855\",\n",
      "        \"SF-989930\",\n",
      "        \"SF-330319\",\n",
      "        \"SF-633995\",\n",
      "        \"SF-370379\",\n",
      "        \"SF-869067\",\n",
      "        \"SF-949394\",\n",
      "        \"SF-751357\",\n",
      "        \"SF-254979\",\n",
      "        \"SF-551781\",\n",
      "        \"SF-566082\",\n",
      "        \"SF-816742\",\n",
      "        \"SF-535443\",\n",
      "        \"SF-537373\",\n",
      "        \"SF-786276\",\n",
      "        \"SF-452878\",\n",
      "        \"SF-469903\",\n",
      "        \"SF-187426\",\n",
      "        \"SF-657315\",\n",
      "        \"SF-345814\",\n",
      "        \"SF-526862\",\n",
      "        \"SF-852562\",\n",
      "        \"SF-704155\",\n",
      "        \"SF-120100\",\n",
      "        \"SF-491110\",\n",
      "        \"SF-391879\",\n",
      "        \"SF-426350\",\n",
      "        \"SF-147048\",\n",
      "        \"SF-248079\",\n",
      "        \"SF-197153\",\n",
      "        \"SF-552493\",\n",
      "        \"SF-966054\",\n",
      "        \"SF-474019\",\n",
      "        \"SF-374305\",\n",
      "        \"SF-821023\",\n",
      "        \"SF-251393\",\n",
      "        \"SF-369874\",\n",
      "        \"SF-442748\",\n",
      "        \"SF-972267\",\n",
      "        \"SF-805939\",\n",
      "        \"SF-553951\",\n",
      "        \"SF-437712\",\n",
      "        \"SF-895238\",\n",
      "        \"SF-327109\",\n",
      "        \"SF-375561\",\n",
      "        \"SF-467138\",\n",
      "        \"SF-426781\",\n",
      "        \"SF-718383\",\n",
      "        \"SF-747871\",\n",
      "        \"SF-424245\",\n",
      "        \"SF-250465\",\n",
      "        \"SF-830444\",\n",
      "        \"SF-229399\",\n",
      "        \"SF-689446\",\n",
      "        \"SF-371233\",\n",
      "        \"SF-948458\",\n",
      "        \"SF-334284\",\n",
      "        \"SF-826464\",\n",
      "        \"SF-776084\",\n",
      "        \"SF-809353\",\n",
      "        \"SF-862316\",\n",
      "        \"SF-805001\",\n",
      "        \"SF-969998\",\n",
      "        \"SF-129961\",\n",
      "        \"SF-995305\",\n",
      "        \"SF-499102\",\n",
      "        \"SF-360240\",\n",
      "        \"SF-146673\",\n",
      "        \"SF-704341\",\n",
      "        \"SF-707944\",\n",
      "        \"SF-887948\",\n",
      "        \"SF-904644\",\n",
      "        \"SF-475818\",\n",
      "        \"SF-613077\",\n",
      "        \"SF-944670\",\n",
      "        \"SF-970654\",\n",
      "        \"SF-779662\",\n",
      "        \"SF-746078\",\n",
      "        \"SF-538993\",\n",
      "        \"SF-310486\",\n",
      "        \"SF-604934\",\n",
      "        \"SF-967042\",\n",
      "        \"SF-685565\",\n",
      "        \"SF-510228\",\n",
      "        \"SF-140134\",\n",
      "        \"SF-740590\",\n",
      "        \"SF-786222\",\n",
      "        \"SF-877097\",\n",
      "        \"SF-435018\",\n",
      "        \"SF-915897\",\n",
      "        \"SF-567011\",\n",
      "        \"SF-673704\"\n",
      "      ]\n",
      "    },\n",
      "    \"release\": {\n",
      "      \"n\": 120,\n",
      "      \"families\": [\n",
      "        \"release-00\",\n",
      "        \"release-01\",\n",
      "        \"release-02\",\n",
      "        \"release-03\",\n",
      "        \"release-04\",\n",
      "        \"release-05\",\n",
      "        \"release-06\",\n",
      "        \"release-07\",\n",
      "        \"release-08\",\n",
      "        \"release-09\"\n",
      "      ],\n",
      "      \"sha256\": \"ce7d04d318df326d1059955a916bba1407f9e175873b6a5aa5354d0ca71d135f\",\n",
      "      \"ids\": [\n",
      "        \"SF-750705\",\n",
      "        \"SF-854358\",\n",
      "        \"SF-884047\",\n",
      "        \"SF-969378\",\n",
      "        \"SF-686550\",\n",
      "        \"SF-109126\",\n",
      "        \"SF-856696\",\n",
      "        \"SF-294897\",\n",
      "        \"SF-562566\",\n",
      "        \"SF-701371\",\n",
      "        \"SF-415441\",\n",
      "        \"SF-958232\",\n",
      "        \"SF-732765\",\n",
      "        \"SF-362338\",\n",
      "        \"SF-700275\",\n",
      "        \"SF-912081\",\n",
      "        \"SF-869943\",\n",
      "        \"SF-290683\",\n",
      "        \"SF-146856\",\n",
      "        \"SF-466864\",\n",
      "        \"SF-566200\",\n",
      "        \"SF-888578\",\n",
      "        \"SF-142669\",\n",
      "        \"SF-188863\",\n",
      "        \"SF-931925\",\n",
      "        \"SF-254418\",\n",
      "        \"SF-550356\",\n",
      "        \"SF-371516\",\n",
      "        \"SF-663374\",\n",
      "        \"SF-982949\",\n",
      "        \"SF-183637\",\n",
      "        \"SF-518628\",\n",
      "        \"SF-654197\",\n",
      "        \"SF-940772\",\n",
      "        \"SF-461483\",\n",
      "        \"SF-182433\",\n",
      "        \"SF-474321\",\n",
      "        \"SF-344570\",\n",
      "        \"SF-376171\",\n",
      "        \"SF-959920\",\n",
      "        \"SF-180510\",\n",
      "        \"SF-875920\",\n",
      "        \"SF-688770\",\n",
      "        \"SF-978905\",\n",
      "        \"SF-584520\",\n",
      "        \"SF-470685\",\n",
      "        \"SF-196156\",\n",
      "        \"SF-280337\",\n",
      "        \"SF-193839\",\n",
      "        \"SF-528105\",\n",
      "        \"SF-970212\",\n",
      "        \"SF-397734\",\n",
      "        \"SF-538406\",\n",
      "        \"SF-347879\",\n",
      "        \"SF-966752\",\n",
      "        \"SF-100929\",\n",
      "        \"SF-387321\",\n",
      "        \"SF-964666\",\n",
      "        \"SF-160547\",\n",
      "        \"SF-392417\",\n",
      "        \"SF-798364\",\n",
      "        \"SF-471185\",\n",
      "        \"SF-660319\",\n",
      "        \"SF-292214\",\n",
      "        \"SF-475318\",\n",
      "        \"SF-148299\",\n",
      "        \"SF-734078\",\n",
      "        \"SF-855426\",\n",
      "        \"SF-591018\",\n",
      "        \"SF-824891\",\n",
      "        \"SF-638434\",\n",
      "        \"SF-411548\",\n",
      "        \"SF-777503\",\n",
      "        \"SF-764611\",\n",
      "        \"SF-792326\",\n",
      "        \"SF-406184\",\n",
      "        \"SF-948670\",\n",
      "        \"SF-490922\",\n",
      "        \"SF-641546\",\n",
      "        \"SF-386930\",\n",
      "        \"SF-473732\",\n",
      "        \"SF-664301\",\n",
      "        \"SF-110329\",\n",
      "        \"SF-546758\",\n",
      "        \"SF-508077\",\n",
      "        \"SF-551989\",\n",
      "        \"SF-987644\",\n",
      "        \"SF-950539\",\n",
      "        \"SF-429854\",\n",
      "        \"SF-442680\",\n",
      "        \"SF-547135\",\n",
      "        \"SF-151032\",\n",
      "        \"SF-432911\",\n",
      "        \"SF-323925\",\n",
      "        \"SF-614952\",\n",
      "        \"SF-790880\",\n",
      "        \"SF-562034\",\n",
      "        \"SF-548515\",\n",
      "        \"SF-148114\",\n",
      "        \"SF-180190\",\n",
      "        \"SF-746591\",\n",
      "        \"SF-285575\",\n",
      "        \"SF-268404\",\n",
      "        \"SF-369151\",\n",
      "        \"SF-101257\",\n",
      "        \"SF-259705\",\n",
      "        \"SF-622523\",\n",
      "        \"SF-718777\",\n",
      "        \"SF-996370\",\n",
      "        \"SF-891637\",\n",
      "        \"SF-484685\",\n",
      "        \"SF-866719\",\n",
      "        \"SF-985671\",\n",
      "        \"SF-925349\",\n",
      "        \"SF-106031\",\n",
      "        \"SF-348329\",\n",
      "        \"SF-218166\",\n",
      "        \"SF-288871\",\n",
      "        \"SF-436548\",\n",
      "        \"SF-912917\"\n",
      "      ]\n",
      "    },\n",
      "    \"dpo_pairs\": {\n",
      "      \"n\": 96,\n",
      "      \"ids\": [\n",
      "        \"SF-651508\",\n",
      "        \"SF-779735\",\n",
      "        \"SF-513412\",\n",
      "        \"SF-234277\",\n",
      "        \"SF-157375\",\n",
      "        \"SF-681994\",\n",
      "        \"SF-277352\",\n",
      "        \"SF-540371\",\n",
      "        \"SF-419924\",\n",
      "        \"SF-257731\",\n",
      "        \"SF-278734\",\n",
      "        \"SF-838331\",\n",
      "        \"SF-681852\",\n",
      "        \"SF-703937\",\n",
      "        \"SF-955241\",\n",
      "        \"SF-302305\",\n",
      "        \"SF-294698\",\n",
      "        \"SF-305025\",\n",
      "        \"SF-406495\",\n",
      "        \"SF-309658\",\n",
      "        \"SF-847838\",\n",
      "        \"SF-626332\",\n",
      "        \"SF-108715\",\n",
      "        \"SF-425310\",\n",
      "        \"SF-536066\",\n",
      "        \"SF-158596\",\n",
      "        \"SF-406272\",\n",
      "        \"SF-335651\",\n",
      "        \"SF-342794\",\n",
      "        \"SF-684858\",\n",
      "        \"SF-440161\",\n",
      "        \"SF-740586\",\n",
      "        \"SF-473923\",\n",
      "        \"SF-719829\",\n",
      "        \"SF-327852\",\n",
      "        \"SF-471428\",\n",
      "        \"SF-302828\",\n",
      "        \"SF-400509\",\n",
      "        \"SF-606165\",\n",
      "        \"SF-184577\",\n",
      "        \"SF-988466\",\n",
      "        \"SF-424194\",\n",
      "        \"SF-815017\",\n",
      "        \"SF-409733\",\n",
      "        \"SF-915055\",\n",
      "        \"SF-379315\",\n",
      "        \"SF-232799\",\n",
      "        \"SF-616570\",\n",
      "        \"SF-444107\",\n",
      "        \"SF-399518\",\n",
      "        \"SF-825649\",\n",
      "        \"SF-203063\",\n",
      "        \"SF-617677\",\n",
      "        \"SF-399624\",\n",
      "        \"SF-184367\",\n",
      "        \"SF-488356\",\n",
      "        \"SF-308492\",\n",
      "        \"SF-574810\",\n",
      "        \"SF-365741\",\n",
      "        \"SF-659895\",\n",
      "        \"SF-422935\",\n",
      "        \"SF-122389\",\n",
      "        \"SF-770304\",\n",
      "        \"SF-470426\",\n",
      "        \"SF-421431\",\n",
      "        \"SF-957778\",\n",
      "        \"SF-705959\",\n",
      "        \"SF-891006\",\n",
      "        \"SF-120329\",\n",
      "        \"SF-588006\",\n",
      "        \"SF-246857\",\n",
      "        \"SF-191073\",\n",
      "        \"SF-678143\",\n",
      "        \"SF-482700\",\n",
      "        \"SF-902388\",\n",
      "        \"SF-350981\",\n",
      "        \"SF-897602\",\n",
      "        \"SF-204891\",\n",
      "        \"SF-594010\",\n",
      "        \"SF-748453\",\n",
      "        \"SF-800980\",\n",
      "        \"SF-306925\",\n",
      "        \"SF-998520\",\n",
      "        \"SF-540623\",\n",
      "        \"SF-771322\",\n",
      "        \"SF-785612\",\n",
      "        \"SF-181050\",\n",
      "        \"SF-589807\",\n",
      "        \"SF-240903\",\n",
      "        \"SF-106348\",\n",
      "        \"SF-428518\",\n",
      "        \"SF-134926\",\n",
      "        \"SF-860353\",\n",
      "        \"SF-669120\",\n",
      "        \"SF-616152\",\n",
      "        \"SF-340287\"\n",
      "      ],\n",
      "      \"sha256\": \"722cb0a96bf41cb6e2b6289198673c7b515ad1be959aea0696e87fd8fbeacd1b\"\n",
      "    }\n",
      "  },\n",
      "  \"learning_rate_screen\": {\n",
      "    \"8e-06\": {\n",
      "      \"training\": {\n",
      "        \"steps\": 3,\n",
      "        \"optimizer_updates\": 3,\n",
      "        \"seconds\": 18.808421439000085,\n",
      "        \"peak_allocated_gib\": 3.2891359329223633,\n",
      "        \"peak_reserved_gib\": 3.5859375,\n",
      "        \"log\": [\n",
      "          {\n",
      "            \"loss\": 0.0,\n",
      "            \"grad_norm\": 0.0,\n",
      "            \"learning_rate\": 8e-06,\n",
      "            \"num_tokens\": 1336.0,\n",
      "            \"completions/mean_length\": 128.0,\n",
      "            \"completions/min_length\": 128.0,\n",
      "            \"completions/max_length\": 128.0,\n",
      "            \"completions/clipped_ratio\": 0.0,\n",
      "            \"completions/mean_terminated_length\": 128.0,\n",
      "            \"completions/min_terminated_length\": 128.0,\n",
      "            \"completions/max_terminated_length\": 128.0,\n",
      "            \"rewards/semantic_reward/mean\": 1.0,\n",
      "            \"rewards/semantic_reward/std\": 0.0,\n",
      "            \"reward\": 1.0,\n",
      "            \"reward_std\": 0.0,\n",
      "            \"frac_reward_zero_std\": 1.0,\n",
      "            \"clip_ratio/low_mean\": 0.0,\n",
      "            \"clip_ratio/low_min\": 0.0,\n",
      "            \"clip_ratio/high_mean\": 0.0,\n",
      "            \"clip_ratio/high_max\": 0.0,\n",
      "            \"clip_ratio/region_mean\": 0.0,\n",
      "            \"epoch\": 0.03125,\n",
      "            \"step\": 1\n",
      "          },\n",
      "          {\n",
      "            \"loss\": 0.0,\n",
      "            \"grad_norm\": 0.0,\n",
      "            \"learning_rate\": 8e-06,\n",
      "            \"num_tokens\": 2580.0,\n",
      "            \"completions/mean_length\": 111.0,\n",
      "            \"completions/min_length\": 111.0,\n",
      "            \"completions/max_length\": 111.0,\n",
      "            \"completions/clipped_ratio\": 0.0,\n",
      "            \"completions/mean_terminated_length\": 111.0,\n",
      "            \"completions/min_terminated_length\": 111.0,\n",
      "            \"completions/max_terminated_length\": 111.0,\n",
      "            \"rewards/semantic_reward/mean\": 1.0,\n",
      "            \"rewards/semantic_reward/std\": 0.0,\n",
      "            \"reward\": 1.0,\n",
      "            \"reward_std\": 0.0,\n",
      "            \"frac_reward_zero_std\": 1.0,\n",
      "            \"clip_ratio/low_mean\": 0.0,\n",
      "            \"clip_ratio/low_min\": 0.0,\n",
      "            \"clip_ratio/high_mean\": 0.0,\n",
      "            \"clip_ratio/high_max\": 0.0,\n",
      "            \"clip_ratio/region_mean\": 0.0,\n",
      "            \"epoch\": 0.0625,\n",
      "            \"step\": 2\n",
      "          },\n",
      "          {\n",
      "            \"loss\": 0.0,\n",
      "            \"grad_norm\": 0.0,\n",
      "            \"learning_rate\": 8e-06,\n",
      "            \"num_tokens\": 3628.0,\n",
      "            \"completions/mean_length\": 92.0,\n",
      "            \"completions/min_length\": 92.0,\n",
      "            \"completions/max_length\": 92.0,\n",
      "            \"completions/clipped_ratio\": 0.0,\n",
      "            \"completions/mean_terminated_length\": 92.0,\n",
      "            \"completions/min_terminated_length\": 92.0,\n",
      "            \"completions/max_terminated_length\": 92.0,\n",
      "            \"rewards/semantic_reward/mean\": 1.0,\n",
      "            \"rewards/semantic_reward/std\": 0.0,\n",
      "            \"reward\": 1.0,\n",
      "            \"reward_std\": 0.0,\n",
      "            \"frac_reward_zero_std\": 1.0,\n",
      "            \"clip_ratio/low_mean\": 0.0,\n",
      "            \"clip_ratio/low_min\": 0.0,\n",
      "            \"clip_ratio/high_mean\": 0.0,\n",
      "            \"clip_ratio/high_max\": 0.0,\n",
      "            \"clip_ratio/region_mean\": 0.0,\n",
      "            \"epoch\": 0.09375,\n",
      "            \"step\": 3\n",
      "          },\n",
      "          {\n",
      "            \"train_runtime\": 18.2823,\n",
      "            \"train_samples_per_second\": 0.656,\n",
      "            \"train_steps_per_second\": 0.164,\n",
      "            \"total_flos\": 0.0,\n",
      "            \"train_loss\": 0.0,\n",
      "            \"epoch\": 0.09375,\n",
      "            \"step\": 3\n",
      "          }\n",
      "        ],\n",
      "        \"max_prompt_tokens\": 217,\n",
      "        \"max_label_tokens\": 0,\n",
      "        \"reward_kind\": \"semantic\",\n",
      "        \"learning_rate\": 8e-06,\n",
      "        \"beta\": 0.0,\n",
      "        \"initial_adapter_sha256\": \"05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170\",\n",
      "        \"prompt_roster_sha256\": \"a9940ffe34f6dd973290978a0b4b635dd80ac7f9806848759cfc511c80a070b8\",\n",
      "        \"prompt_ids_sha256\": \"86a1fcd53fc47d711de602276f670d682d8ea0239692f49bd13dcb1cd01c8dc8\",\n",
      "        \"generation_group_size\": 4,\n",
      "        \"audit\": [\n",
      "          {\n",
      "            \"rollout_group\": 1,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-563210\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 1.0,\n",
      "            \"semantic_mean\": 1.0,\n",
      "            \"field_mean\": 1.0,\n",
      "            \"row_f1_mean\": 1.0,\n",
      "            \"completion_rate\": 1.0,\n",
      "            \"mean_tokens\": 128.0,\n",
      "            \"max_tokens\": 128,\n",
      "            \"cap_hits_without_eos\": 0,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          },\n",
      "          {\n",
      "            \"rollout_group\": 2,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-885244\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 1.0,\n",
      "            \"semantic_mean\": 1.0,\n",
      "            \"field_mean\": 1.0,\n",
      "            \"row_f1_mean\": 1.0,\n",
      "            \"completion_rate\": 1.0,\n",
      "            \"mean_tokens\": 111.0,\n",
      "            \"max_tokens\": 111,\n",
      "            \"cap_hits_without_eos\": 0,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          },\n",
      "          {\n",
      "            \"rollout_group\": 3,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-850619\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 1.0,\n",
      "            \"semantic_mean\": 1.0,\n",
      "            \"field_mean\": 1.0,\n",
      "            \"row_f1_mean\": 1.0,\n",
      "            \"completion_rate\": 1.0,\n",
      "            \"mean_tokens\": 92.0,\n",
      "            \"max_tokens\": 92,\n",
      "            \"cap_hits_without_eos\": 0,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          }\n",
      "        ],\n",
      "        \"rollout_invoice_ids\": [\n",
      "          \"SF-563210\",\n",
      "          \"SF-885244\",\n",
      "          \"SF-850619\"\n",
      "        ],\n",
      "        \"completions_sampled\": 12,\n",
      "        \"generation_settings\": {\n",
      "          \"max_new_tokens\": 256,\n",
      "          \"do_sample\": true,\n",
      "          \"temperature\": 0.8,\n",
      "          \"top_k\": null,\n",
      "          \"pad_token_id\": 151643,\n",
      "          \"eos_token_id\": 151645,\n",
      "          \"transformers_version\": \"4.51.3\"\n",
      "        },\n",
      "        \"adapter_sha256\": \"489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd\"\n",
      "      },\n",
      "      \"development\": {\n",
      "        \"n\": 12,\n",
      "        \"exact\": 1.0,\n",
      "        \"valid\": 1.0,\n",
      "        \"row_f1\": 1.0,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 112.75,\n",
      "        \"mean_ms_per_example_in_batch\": 977.824962416662\n",
      "      },\n",
      "      \"checkpoint\": {\n",
      "        \"parent\": {\n",
      "          \"path\": \"lesson-results/06-sft-merged\",\n",
      "          \"sha256\": \"7952969b63edb58bee78a23e303d741c74bc90d459784657e9d46ee89eb5be3f\"\n",
      "        },\n",
      "        \"adapter\": {\n",
      "          \"path\": \"lesson-results/06-screen-0\",\n",
      "          \"sha256\": \"489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd\"\n",
      "        },\n",
      "        \"adapter_sha256\": \"58ad20fc60b2a476624ca009dd4fa6df2e5d0fd0af9d0d80ed0178549fdcd052\",\n",
      "        \"merged\": null\n",
      "      }\n",
      "    },\n",
      "    \"2e-05\": {\n",
      "      \"training\": {\n",
      "        \"steps\": 3,\n",
      "        \"optimizer_updates\": 3,\n",
      "        \"seconds\": 17.724870507000105,\n",
      "        \"peak_allocated_gib\": 3.2891359329223633,\n",
      "        \"peak_reserved_gib\": 3.5859375,\n",
      "        \"log\": [\n",
      "          {\n",
      "            \"loss\": 0.0,\n",
      "            \"grad_norm\": 0.0,\n",
      "            \"learning_rate\": 2e-05,\n",
      "            \"num_tokens\": 1336.0,\n",
      "            \"completions/mean_length\": 128.0,\n",
      "            \"completions/min_length\": 128.0,\n",
      "            \"completions/max_length\": 128.0,\n",
      "            \"completions/clipped_ratio\": 0.0,\n",
      "            \"completions/mean_terminated_length\": 128.0,\n",
      "            \"completions/min_terminated_length\": 128.0,\n",
      "            \"completions/max_terminated_length\": 128.0,\n",
      "            \"rewards/semantic_reward/mean\": 1.0,\n",
      "            \"rewards/semantic_reward/std\": 0.0,\n",
      "            \"reward\": 1.0,\n",
      "            \"reward_std\": 0.0,\n",
      "            \"frac_reward_zero_std\": 1.0,\n",
      "            \"clip_ratio/low_mean\": 0.0,\n",
      "            \"clip_ratio/low_min\": 0.0,\n",
      "            \"clip_ratio/high_mean\": 0.0,\n",
      "            \"clip_ratio/high_max\": 0.0,\n",
      "            \"clip_ratio/region_mean\": 0.0,\n",
      "            \"epoch\": 0.03125,\n",
      "            \"step\": 1\n",
      "          },\n",
      "          {\n",
      "            \"loss\": 0.0,\n",
      "            \"grad_norm\": 0.0,\n",
      "            \"learning_rate\": 2e-05,\n",
      "            \"num_tokens\": 2580.0,\n",
      "            \"completions/mean_length\": 111.0,\n",
      "            \"completions/min_length\": 111.0,\n",
      "            \"completions/max_length\": 111.0,\n",
      "            \"completions/clipped_ratio\": 0.0,\n",
      "            \"completions/mean_terminated_length\": 111.0,\n",
      "            \"completions/min_terminated_length\": 111.0,\n",
      "            \"completions/max_terminated_length\": 111.0,\n",
      "            \"rewards/semantic_reward/mean\": 1.0,\n",
      "            \"rewards/semantic_reward/std\": 0.0,\n",
      "            \"reward\": 1.0,\n",
      "            \"reward_std\": 0.0,\n",
      "            \"frac_reward_zero_std\": 1.0,\n",
      "            \"clip_ratio/low_mean\": 0.0,\n",
      "            \"clip_ratio/low_min\": 0.0,\n",
      "            \"clip_ratio/high_mean\": 0.0,\n",
      "            \"clip_ratio/high_max\": 0.0,\n",
      "            \"clip_ratio/region_mean\": 0.0,\n",
      "            \"epoch\": 0.0625,\n",
      "            \"step\": 2\n",
      "          },\n",
      "          {\n",
      "            \"loss\": 0.0,\n",
      "            \"grad_norm\": 0.0,\n",
      "            \"learning_rate\": 2e-05,\n",
      "            \"num_tokens\": 3628.0,\n",
      "            \"completions/mean_length\": 92.0,\n",
      "            \"completions/min_length\": 92.0,\n",
      "            \"completions/max_length\": 92.0,\n",
      "            \"completions/clipped_ratio\": 0.0,\n",
      "            \"completions/mean_terminated_length\": 92.0,\n",
      "            \"completions/min_terminated_length\": 92.0,\n",
      "            \"completions/max_terminated_length\": 92.0,\n",
      "            \"rewards/semantic_reward/mean\": 1.0,\n",
      "            \"rewards/semantic_reward/std\": 0.0,\n",
      "            \"reward\": 1.0,\n",
      "            \"reward_std\": 0.0,\n",
      "            \"frac_reward_zero_std\": 1.0,\n",
      "            \"clip_ratio/low_mean\": 0.0,\n",
      "            \"clip_ratio/low_min\": 0.0,\n",
      "            \"clip_ratio/high_mean\": 0.0,\n",
      "            \"clip_ratio/high_max\": 0.0,\n",
      "            \"clip_ratio/region_mean\": 0.0,\n",
      "            \"epoch\": 0.09375,\n",
      "            \"step\": 3\n",
      "          },\n",
      "          {\n",
      "            \"train_runtime\": 17.1926,\n",
      "            \"train_samples_per_second\": 0.698,\n",
      "            \"train_steps_per_second\": 0.174,\n",
      "            \"total_flos\": 0.0,\n",
      "            \"train_loss\": 0.0,\n",
      "            \"epoch\": 0.09375,\n",
      "            \"step\": 3\n",
      "          }\n",
      "        ],\n",
      "        \"max_prompt_tokens\": 217,\n",
      "        \"max_label_tokens\": 0,\n",
      "        \"reward_kind\": \"semantic\",\n",
      "        \"learning_rate\": 2e-05,\n",
      "        \"beta\": 0.0,\n",
      "        \"initial_adapter_sha256\": \"05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170\",\n",
      "        \"prompt_roster_sha256\": \"a9940ffe34f6dd973290978a0b4b635dd80ac7f9806848759cfc511c80a070b8\",\n",
      "        \"prompt_ids_sha256\": \"86a1fcd53fc47d711de602276f670d682d8ea0239692f49bd13dcb1cd01c8dc8\",\n",
      "        \"generation_group_size\": 4,\n",
      "        \"audit\": [\n",
      "          {\n",
      "            \"rollout_group\": 1,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-563210\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 1.0,\n",
      "            \"semantic_mean\": 1.0,\n",
      "            \"field_mean\": 1.0,\n",
      "            \"row_f1_mean\": 1.0,\n",
      "            \"completion_rate\": 1.0,\n",
      "            \"mean_tokens\": 128.0,\n",
      "            \"max_tokens\": 128,\n",
      "            \"cap_hits_without_eos\": 0,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          },\n",
      "          {\n",
      "            \"rollout_group\": 2,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-885244\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 1.0,\n",
      "            \"semantic_mean\": 1.0,\n",
      "            \"field_mean\": 1.0,\n",
      "            \"row_f1_mean\": 1.0,\n",
      "            \"completion_rate\": 1.0,\n",
      "            \"mean_tokens\": 111.0,\n",
      "            \"max_tokens\": 111,\n",
      "            \"cap_hits_without_eos\": 0,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          },\n",
      "          {\n",
      "            \"rollout_group\": 3,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-850619\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 1.0,\n",
      "            \"semantic_mean\": 1.0,\n",
      "            \"field_mean\": 1.0,\n",
      "            \"row_f1_mean\": 1.0,\n",
      "            \"completion_rate\": 1.0,\n",
      "            \"mean_tokens\": 92.0,\n",
      "            \"max_tokens\": 92,\n",
      "            \"cap_hits_without_eos\": 0,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          }\n",
      "        ],\n",
      "        \"rollout_invoice_ids\": [\n",
      "          \"SF-563210\",\n",
      "          \"SF-885244\",\n",
      "          \"SF-850619\"\n",
      "        ],\n",
      "        \"completions_sampled\": 12,\n",
      "        \"generation_settings\": {\n",
      "          \"max_new_tokens\": 256,\n",
      "          \"do_sample\": true,\n",
      "          \"temperature\": 0.8,\n",
      "          \"top_k\": null,\n",
      "          \"pad_token_id\": 151643,\n",
      "          \"eos_token_id\": 151645,\n",
      "          \"transformers_version\": \"4.51.3\"\n",
      "        },\n",
      "        \"adapter_sha256\": \"489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd\"\n",
      "      },\n",
      "      \"development\": {\n",
      "        \"n\": 12,\n",
      "        \"exact\": 1.0,\n",
      "        \"valid\": 1.0,\n",
      "        \"row_f1\": 1.0,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 112.75,\n",
      "        \"mean_ms_per_example_in_batch\": 1001.5159935000307\n",
      "      },\n",
      "      \"checkpoint\": {\n",
      "        \"parent\": {\n",
      "          \"path\": \"lesson-results/06-sft-merged\",\n",
      "          \"sha256\": \"7952969b63edb58bee78a23e303d741c74bc90d459784657e9d46ee89eb5be3f\"\n",
      "        },\n",
      "        \"adapter\": {\n",
      "          \"path\": \"lesson-results/06-screen-1\",\n",
      "          \"sha256\": \"489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd\"\n",
      "        },\n",
      "        \"adapter_sha256\": \"58ad20fc60b2a476624ca009dd4fa6df2e5d0fd0af9d0d80ed0178549fdcd052\",\n",
      "        \"merged\": null\n",
      "      }\n",
      "    }\n",
      "  },\n",
      "  \"selected_grpo_rate\": 8e-06,\n",
      "  \"scores\": {\n",
      "    \"Prompted base\": {\n",
      "      \"n\": 240,\n",
      "      \"exact\": 0.0,\n",
      "      \"valid\": 0.0,\n",
      "      \"row_f1\": 0.0,\n",
      "      \"natural_completion\": 0.7333333333333333,\n",
      "      \"mean_generated_tokens\": 206.675,\n",
      "      \"mean_ms_per_example_in_batch\": 1030.8296998333315\n",
      "    },\n",
      "    \"SFT\": {\n",
      "      \"n\": 240,\n",
      "      \"exact\": 0.5916666666666667,\n",
      "      \"valid\": 0.9833333333333333,\n",
      "      \"row_f1\": 0.9041666666666667,\n",
      "      \"natural_completion\": 1.0,\n",
      "      \"mean_generated_tokens\": 111.37916666666666,\n",
      "      \"mean_ms_per_example_in_batch\": 527.3796498416724\n",
      "    },\n",
      "    \"SFT \\u2192 DPO\": {\n",
      "      \"n\": 240,\n",
      "      \"exact\": 0.6041666666666666,\n",
      "      \"valid\": 0.9791666666666666,\n",
      "      \"row_f1\": 0.9166666666666666,\n",
      "      \"natural_completion\": 1.0,\n",
      "      \"mean_generated_tokens\": 111.54166666666667,\n",
      "      \"mean_ms_per_example_in_batch\": 549.2429516958301\n",
      "    },\n",
      "    \"SFT \\u2192 GRPO\": {\n",
      "      \"n\": 240,\n",
      "      \"exact\": 0.5916666666666667,\n",
      "      \"valid\": 0.9833333333333333,\n",
      "      \"row_f1\": 0.9041666666666667,\n",
      "      \"natural_completion\": 1.0,\n",
      "      \"mean_generated_tokens\": 111.37916666666666,\n",
      "      \"mean_ms_per_example_in_batch\": 775.3700765749993\n",
      "    },\n",
      "    \"SFT \\u2192 DPO \\u2192 GRPO\": {\n",
      "      \"n\": 240,\n",
      "      \"exact\": 0.6041666666666666,\n",
      "      \"valid\": 0.9791666666666666,\n",
      "      \"row_f1\": 0.9166666666666666,\n",
      "      \"natural_completion\": 1.0,\n",
      "      \"mean_generated_tokens\": 111.54166666666667,\n",
      "      \"mean_ms_per_example_in_batch\": 762.3191801166646\n",
      "    }\n",
      "  },\n",
      "  \"splits\": {\n",
      "    \"Prompted base\": {\n",
      "      \"familiar\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": 0.75,\n",
      "        \"mean_generated_tokens\": 206.27083333333334,\n",
      "        \"mean_ms_per_example_in_batch\": 1004.0659259062513\n",
      "      },\n",
      "      \"novel\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": 0.6875,\n",
      "        \"mean_generated_tokens\": 208.47916666666666,\n",
      "        \"mean_ms_per_example_in_batch\": 1050.7440708958266\n",
      "      },\n",
      "      \"independent\": {\n",
      "        \"n\": 48,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": 0.7916666666666666,\n",
      "        \"mean_generated_tokens\": 203.875,\n",
      "        \"mean_ms_per_example_in_batch\": 1044.528505562501\n",
      "      }\n",
      "    },\n",
      "    \"SFT\": {\n",
      "      \"familiar\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.9479166666666666,\n",
      "        \"valid\": 0.9895833333333334,\n",
      "        \"row_f1\": 0.9861111111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 114.28125,\n",
      "        \"mean_ms_per_example_in_batch\": 527.4135244895841\n",
      "      },\n",
      "      \"novel\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.53125,\n",
      "        \"valid\": 0.9791666666666666,\n",
      "        \"row_f1\": 0.8298611111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 108.67708333333333,\n",
      "        \"mean_ms_per_example_in_batch\": 527.7100890937589\n",
      "      },\n",
      "      \"independent\": {\n",
      "        \"n\": 48,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.9791666666666666,\n",
      "        \"row_f1\": 0.8888888888888888,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 110.97916666666667,\n",
      "        \"mean_ms_per_example_in_batch\": 526.6510220416762\n",
      "      }\n",
      "    },\n",
      "    \"SFT \\u2192 DPO\": {\n",
      "      \"familiar\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.9583333333333334,\n",
      "        \"valid\": 0.9895833333333334,\n",
      "        \"row_f1\": 0.9861111111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 114.29166666666667,\n",
      "        \"mean_ms_per_example_in_batch\": 568.0217413645845\n",
      "      },\n",
      "      \"novel\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.5520833333333334,\n",
      "        \"valid\": 0.9895833333333334,\n",
      "        \"row_f1\": 0.8611111111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 109.15625,\n",
      "        \"mean_ms_per_example_in_batch\": 540.6272079687398\n",
      "      },\n",
      "      \"independent\": {\n",
      "        \"n\": 48,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.9375,\n",
      "        \"row_f1\": 0.8888888888888888,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 110.8125,\n",
      "        \"mean_ms_per_example_in_batch\": 528.9168598125021\n",
      "      }\n",
      "    },\n",
      "    \"SFT \\u2192 GRPO\": {\n",
      "      \"familiar\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.9479166666666666,\n",
      "        \"valid\": 0.9895833333333334,\n",
      "        \"row_f1\": 0.9861111111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 114.28125,\n",
      "        \"mean_ms_per_example_in_batch\": 763.5581403229139\n",
      "      },\n",
      "      \"novel\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.53125,\n",
      "        \"valid\": 0.9791666666666666,\n",
      "        \"row_f1\": 0.8298611111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 108.67708333333333,\n",
      "        \"mean_ms_per_example_in_batch\": 791.7664079062566\n",
      "      },\n",
      "      \"independent\": {\n",
      "        \"n\": 48,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.9791666666666666,\n",
      "        \"row_f1\": 0.8888888888888888,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 110.97916666666667,\n",
      "        \"mean_ms_per_example_in_batch\": 766.2012864166551\n",
      "      }\n",
      "    },\n",
      "    \"SFT \\u2192 DPO \\u2192 GRPO\": {\n",
      "      \"familiar\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.9583333333333334,\n",
      "        \"valid\": 0.9895833333333334,\n",
      "        \"row_f1\": 0.9861111111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 114.29166666666667,\n",
      "        \"mean_ms_per_example_in_batch\": 757.6665317395879\n",
      "      },\n",
      "      \"novel\": {\n",
      "        \"n\": 96,\n",
      "        \"exact\": 0.5520833333333334,\n",
      "        \"valid\": 0.9895833333333334,\n",
      "        \"row_f1\": 0.8611111111111112,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 109.15625,\n",
      "        \"mean_ms_per_example_in_batch\": 769.5286535416557\n",
      "      },\n",
      "      \"independent\": {\n",
      "        \"n\": 48,\n",
      "        \"exact\": 0.0,\n",
      "        \"valid\": 0.9375,\n",
      "        \"row_f1\": 0.8888888888888888,\n",
      "        \"natural_completion\": 1.0,\n",
      "        \"mean_generated_tokens\": 110.8125,\n",
      "        \"mean_ms_per_example_in_batch\": 757.2055300208358\n",
      "      }\n",
      "    }\n",
      "  },\n",
      "  \"increments\": {\n",
      "    \"SFT minus base\": {\n",
      "      \"delta\": 0.5916666666666667,\n",
      "      \"n\": 240,\n",
      "      \"families\": 20,\n",
      "      \"improved\": 142,\n",
      "      \"regressed\": 0,\n",
      "      \"tied\": 98,\n",
      "      \"paired_family_bootstrap_95\": [\n",
      "        0.4166666666666667,\n",
      "        0.7583333333333333\n",
      "      ]\n",
      "    },\n",
      "    \"DPO minus SFT\": {\n",
      "      \"delta\": 0.0125,\n",
      "      \"n\": 240,\n",
      "      \"families\": 20,\n",
      "      \"improved\": 7,\n",
      "      \"regressed\": 4,\n",
      "      \"tied\": 229,\n",
      "      \"paired_family_bootstrap_95\": [\n",
      "        -0.020833333333333332,\n",
      "        0.041666666666666664\n",
      "      ]\n",
      "    },\n",
      "    \"GRPO minus SFT\": {\n",
      "      \"delta\": 0.0,\n",
      "      \"n\": 240,\n",
      "      \"families\": 20,\n",
      "      \"improved\": 0,\n",
      "      \"regressed\": 0,\n",
      "      \"tied\": 240,\n",
      "      \"paired_family_bootstrap_95\": [\n",
      "        0.0,\n",
      "        0.0\n",
      "      ]\n",
      "    },\n",
      "    \"GRPO after DPO\": {\n",
      "      \"delta\": 0.0,\n",
      "      \"n\": 240,\n",
      "      \"families\": 20,\n",
      "      \"improved\": 0,\n",
      "      \"regressed\": 0,\n",
      "      \"tied\": 240,\n",
      "      \"paired_family_bootstrap_95\": [\n",
      "        0.0,\n",
      "        0.0\n",
      "      ]\n",
      "    },\n",
      "    \"combined minus SFT\": {\n",
      "      \"delta\": 0.0125,\n",
      "      \"n\": 240,\n",
      "      \"families\": 20,\n",
      "      \"improved\": 7,\n",
      "      \"regressed\": 4,\n",
      "      \"tied\": 229,\n",
      "      \"paired_family_bootstrap_95\": [\n",
      "        -0.020833333333333332,\n",
      "        0.041666666666666664\n",
      "      ]\n",
      "    }\n",
      "  },\n",
      "  \"interaction\": {\n",
      "    \"delta\": 0.0,\n",
      "    \"n\": 240,\n",
      "    \"families\": 20,\n",
      "    \"improved\": 0,\n",
      "    \"regressed\": 0,\n",
      "    \"tied\": 240,\n",
      "    \"paired_family_bootstrap_95\": [\n",
      "      0.0,\n",
      "      0.0\n",
      "    ]\n",
      "  },\n",
      "  \"training\": {\n",
      "    \"sft\": {\n",
      "      \"steps\": 32,\n",
      "      \"optimizer_updates\": 32,\n",
      "      \"seconds\": 24.116822763000073,\n",
      "      \"peak_allocated_gib\": 3.3901567459106445,\n",
      "      \"peak_reserved_gib\": 14.044921875,\n",
      "      \"log\": [\n",
      "        {\n",
      "          \"loss\": 0.1627,\n",
      "          \"grad_norm\": 0.8246138095855713,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 9497.0,\n",
      "          \"mean_token_accuracy\": 0.9580884277820587,\n",
      "          \"epoch\": 0.1111111111111111,\n",
      "          \"step\": 4\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0486,\n",
      "          \"grad_norm\": 0.5431462526321411,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 19019.0,\n",
      "          \"mean_token_accuracy\": 0.986443929374218,\n",
      "          \"epoch\": 0.2222222222222222,\n",
      "          \"step\": 8\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0205,\n",
      "          \"grad_norm\": 0.32450446486473083,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 28813.0,\n",
      "          \"mean_token_accuracy\": 0.9937882795929909,\n",
      "          \"epoch\": 0.3333333333333333,\n",
      "          \"step\": 12\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0103,\n",
      "          \"grad_norm\": 0.22007694840431213,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 38552.0,\n",
      "          \"mean_token_accuracy\": 0.9986164271831512,\n",
      "          \"epoch\": 0.4444444444444444,\n",
      "          \"step\": 16\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0045,\n",
      "          \"grad_norm\": 0.050281114876270294,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 48364.0,\n",
      "          \"mean_token_accuracy\": 0.9991486743092537,\n",
      "          \"epoch\": 0.5555555555555556,\n",
      "          \"step\": 20\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0055,\n",
      "          \"grad_norm\": 0.528340756893158,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 58049.0,\n",
      "          \"mean_token_accuracy\": 0.9991725757718086,\n",
      "          \"epoch\": 0.6666666666666666,\n",
      "          \"step\": 24\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0013,\n",
      "          \"grad_norm\": 0.060688138008117676,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 67927.0,\n",
      "          \"mean_token_accuracy\": 1.0,\n",
      "          \"epoch\": 0.7777777777777778,\n",
      "          \"step\": 28\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0065,\n",
      "          \"grad_norm\": 0.9583326578140259,\n",
      "          \"learning_rate\": 0.0002,\n",
      "          \"num_tokens\": 77466.0,\n",
      "          \"mean_token_accuracy\": 0.9991422519087791,\n",
      "          \"epoch\": 0.8888888888888888,\n",
      "          \"step\": 32\n",
      "        },\n",
      "        {\n",
      "          \"train_runtime\": 23.5896,\n",
      "          \"train_samples_per_second\": 10.852,\n",
      "          \"train_steps_per_second\": 1.357,\n",
      "          \"total_flos\": 184408643346432.0,\n",
      "          \"train_loss\": 0.03247731414739974,\n",
      "          \"epoch\": 0.8888888888888888,\n",
      "          \"step\": 32\n",
      "        }\n",
      "      ],\n",
      "      \"max_prompt_tokens\": 217,\n",
      "      \"max_label_tokens\": 132,\n",
      "      \"examples\": 288,\n",
      "      \"learning_rate\": 0.0002,\n",
      "      \"roster_supervised_tokens\": 31748,\n",
      "      \"examples_per_update\": 8\n",
      "    },\n",
      "    \"dpo\": {\n",
      "      \"steps\": 20,\n",
      "      \"optimizer_updates\": 20,\n",
      "      \"seconds\": 18.62419223200004,\n",
      "      \"peak_allocated_gib\": 2.172210216522217,\n",
      "      \"peak_reserved_gib\": 6.556640625,\n",
      "      \"log\": [\n",
      "        {\n",
      "          \"loss\": 0.6859,\n",
      "          \"grad_norm\": 2.991234302520752,\n",
      "          \"learning_rate\": 1e-05,\n",
      "          \"rewards/chosen\": 4.575252751237713e-05,\n",
      "          \"rewards/rejected\": -0.014502739533782005,\n",
      "          \"rewards/accuracies\": 0.75,\n",
      "          \"rewards/margins\": 0.01454849261790514,\n",
      "          \"logps/chosen\": -0.06021928787231445,\n",
      "          \"logps/rejected\": -14.91740894317627,\n",
      "          \"logits/chosen\": -1.6793713569641113,\n",
      "          \"logits/rejected\": -1.6816143989562988,\n",
      "          \"epoch\": 0.16666666666666666,\n",
      "          \"step\": 4\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.6555,\n",
      "          \"grad_norm\": 3.430604934692383,\n",
      "          \"learning_rate\": 1e-05,\n",
      "          \"rewards/chosen\": 9.262555977329612e-06,\n",
      "          \"rewards/rejected\": -0.07687968760728836,\n",
      "          \"rewards/accuracies\": 1.0,\n",
      "          \"rewards/margins\": 0.07688894867897034,\n",
      "          \"logps/chosen\": -0.0596846342086792,\n",
      "          \"logps/rejected\": -16.865175247192383,\n",
      "          \"logits/chosen\": -1.6527705192565918,\n",
      "          \"logits/rejected\": -1.6542212963104248,\n",
      "          \"epoch\": 0.3333333333333333,\n",
      "          \"step\": 8\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.6265,\n",
      "          \"grad_norm\": 3.273916721343994,\n",
      "          \"learning_rate\": 1e-05,\n",
      "          \"rewards/chosen\": -0.008444118313491344,\n",
      "          \"rewards/rejected\": -0.14676295220851898,\n",
      "          \"rewards/accuracies\": 1.0,\n",
      "          \"rewards/margins\": 0.13831883668899536,\n",
      "          \"logps/chosen\": -0.7323412895202637,\n",
      "          \"logps/rejected\": -17.685853958129883,\n",
      "          \"logits/chosen\": -1.615613341331482,\n",
      "          \"logits/rejected\": -1.6178100109100342,\n",
      "          \"epoch\": 0.5,\n",
      "          \"step\": 12\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.5908,\n",
      "          \"grad_norm\": 3.6657633781433105,\n",
      "          \"learning_rate\": 1e-05,\n",
      "          \"rewards/chosen\": 0.0007377624278888106,\n",
      "          \"rewards/rejected\": -0.21597889065742493,\n",
      "          \"rewards/accuracies\": 1.0,\n",
      "          \"rewards/margins\": 0.21671664714813232,\n",
      "          \"logps/chosen\": -0.0748671293258667,\n",
      "          \"logps/rejected\": -18.30255889892578,\n",
      "          \"logits/chosen\": -1.5891242027282715,\n",
      "          \"logits/rejected\": -1.5913166999816895,\n",
      "          \"epoch\": 0.6666666666666666,\n",
      "          \"step\": 16\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.5603,\n",
      "          \"grad_norm\": 3.984619140625,\n",
      "          \"learning_rate\": 1e-05,\n",
      "          \"rewards/chosen\": -0.008470834232866764,\n",
      "          \"rewards/rejected\": -0.29497069120407104,\n",
      "          \"rewards/accuracies\": 1.0,\n",
      "          \"rewards/margins\": 0.28649985790252686,\n",
      "          \"logps/chosen\": -0.5319710969924927,\n",
      "          \"logps/rejected\": -17.85367202758789,\n",
      "          \"logits/chosen\": -1.5399917364120483,\n",
      "          \"logits/rejected\": -1.5448194742202759,\n",
      "          \"epoch\": 0.8333333333333334,\n",
      "          \"step\": 20\n",
      "        },\n",
      "        {\n",
      "          \"train_runtime\": 18.1133,\n",
      "          \"train_samples_per_second\": 4.417,\n",
      "          \"train_steps_per_second\": 1.104,\n",
      "          \"total_flos\": 0.0,\n",
      "          \"train_loss\": 0.6237917900085449,\n",
      "          \"epoch\": 0.8333333333333334,\n",
      "          \"step\": 20\n",
      "        }\n",
      "      ],\n",
      "      \"verified_pairs\": 96,\n",
      "      \"max_prompt_tokens\": 215,\n",
      "      \"max_completion_tokens\": 132,\n",
      "      \"implicit_reference\": true,\n",
      "      \"beta\": 0.1,\n",
      "      \"learning_rate\": 1e-05,\n",
      "      \"pairs_per_update\": 4,\n",
      "      \"initial_loss_scale\": 1.0\n",
      "    },\n",
      "    \"grpo\": {\n",
      "      \"steps\": 10,\n",
      "      \"optimizer_updates\": 10,\n",
      "      \"seconds\": 62.491439963000175,\n",
      "      \"peak_allocated_gib\": 3.346090316772461,\n",
      "      \"peak_reserved_gib\": 4.158203125,\n",
      "      \"log\": [\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 1172.0,\n",
      "          \"completions/mean_length\": 110.0,\n",
      "          \"completions/min_length\": 110.0,\n",
      "          \"completions/max_length\": 110.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 110.0,\n",
      "          \"completions/min_terminated_length\": 110.0,\n",
      "          \"completions/max_terminated_length\": 110.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.015625,\n",
      "          \"step\": 1\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 2544.0,\n",
      "          \"completions/mean_length\": 129.0,\n",
      "          \"completions/min_length\": 129.0,\n",
      "          \"completions/max_length\": 129.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 129.0,\n",
      "          \"completions/min_terminated_length\": 129.0,\n",
      "          \"completions/max_terminated_length\": 129.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.03125,\n",
      "          \"step\": 2\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 3720.0,\n",
      "          \"completions/mean_length\": 108.0,\n",
      "          \"completions/min_length\": 108.0,\n",
      "          \"completions/max_length\": 108.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 108.0,\n",
      "          \"completions/min_terminated_length\": 108.0,\n",
      "          \"completions/max_terminated_length\": 108.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.046875,\n",
      "          \"step\": 3\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 4752.0,\n",
      "          \"completions/mean_length\": 89.0,\n",
      "          \"completions/min_length\": 89.0,\n",
      "          \"completions/max_length\": 89.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 89.0,\n",
      "          \"completions/min_terminated_length\": 89.0,\n",
      "          \"completions/max_terminated_length\": 89.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.0625,\n",
      "          \"step\": 4\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 5968.0,\n",
      "          \"completions/mean_length\": 111.0,\n",
      "          \"completions/min_length\": 111.0,\n",
      "          \"completions/max_length\": 111.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 111.0,\n",
      "          \"completions/min_terminated_length\": 111.0,\n",
      "          \"completions/max_terminated_length\": 111.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.078125,\n",
      "          \"step\": 5\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 7332.0,\n",
      "          \"completions/mean_length\": 128.0,\n",
      "          \"completions/min_length\": 128.0,\n",
      "          \"completions/max_length\": 128.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 128.0,\n",
      "          \"completions/min_terminated_length\": 128.0,\n",
      "          \"completions/max_terminated_length\": 128.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.09375,\n",
      "          \"step\": 6\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 8528.0,\n",
      "          \"completions/mean_length\": 111.0,\n",
      "          \"completions/min_length\": 111.0,\n",
      "          \"completions/max_length\": 111.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 111.0,\n",
      "          \"completions/min_terminated_length\": 111.0,\n",
      "          \"completions/max_terminated_length\": 111.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.109375,\n",
      "          \"step\": 7\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 9564.0,\n",
      "          \"completions/mean_length\": 91.0,\n",
      "          \"completions/min_length\": 91.0,\n",
      "          \"completions/max_length\": 91.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 91.0,\n",
      "          \"completions/min_terminated_length\": 91.0,\n",
      "          \"completions/max_terminated_length\": 91.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.125,\n",
      "          \"step\": 8\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 10572.0,\n",
      "          \"completions/mean_length\": 86.0,\n",
      "          \"completions/min_length\": 86.0,\n",
      "          \"completions/max_length\": 86.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 86.0,\n",
      "          \"completions/min_terminated_length\": 86.0,\n",
      "          \"completions/max_terminated_length\": 86.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.140625,\n",
      "          \"step\": 9\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 11916.0,\n",
      "          \"completions/mean_length\": 129.0,\n",
      "          \"completions/min_length\": 129.0,\n",
      "          \"completions/max_length\": 129.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 129.0,\n",
      "          \"completions/min_terminated_length\": 129.0,\n",
      "          \"completions/max_terminated_length\": 129.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.15625,\n",
      "          \"step\": 10\n",
      "        },\n",
      "        {\n",
      "          \"train_runtime\": 61.9783,\n",
      "          \"train_samples_per_second\": 0.645,\n",
      "          \"train_steps_per_second\": 0.161,\n",
      "          \"total_flos\": 0.0,\n",
      "          \"train_loss\": 0.0,\n",
      "          \"epoch\": 0.15625,\n",
      "          \"step\": 10\n",
      "        }\n",
      "      ],\n",
      "      \"max_prompt_tokens\": 216,\n",
      "      \"max_label_tokens\": 0,\n",
      "      \"reward_kind\": \"semantic\",\n",
      "      \"learning_rate\": 8e-06,\n",
      "      \"beta\": 0.0,\n",
      "      \"initial_adapter_sha256\": \"05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170\",\n",
      "      \"prompt_roster_sha256\": \"d981fe9a5e7690265ab124c9804ffa09da63ef1da3a82005124b72f28cf3b7b2\",\n",
      "      \"prompt_ids_sha256\": \"a42f7b26c86e52c8c07c82b8a3fd6eb1d6b93fa1ede2f95c465be22c902a8986\",\n",
      "      \"generation_group_size\": 4,\n",
      "      \"audit\": [\n",
      "        {\n",
      "          \"rollout_group\": 1,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-325677\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 110.0,\n",
      "          \"max_tokens\": 110,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 2,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-642032\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 129.0,\n",
      "          \"max_tokens\": 129,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 3,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-835115\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 108.0,\n",
      "          \"max_tokens\": 108,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 4,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-287134\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 89.0,\n",
      "          \"max_tokens\": 89,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 5,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-866376\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 111.0,\n",
      "          \"max_tokens\": 111,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 6,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-630607\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 128.0,\n",
      "          \"max_tokens\": 128,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 7,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-469507\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 111.0,\n",
      "          \"max_tokens\": 111,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 8,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-617742\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 91.0,\n",
      "          \"max_tokens\": 91,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 9,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-501056\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 86.0,\n",
      "          \"max_tokens\": 86,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 10,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-428057\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 129.0,\n",
      "          \"max_tokens\": 129,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        }\n",
      "      ],\n",
      "      \"rollout_invoice_ids\": [\n",
      "        \"SF-325677\",\n",
      "        \"SF-642032\",\n",
      "        \"SF-835115\",\n",
      "        \"SF-287134\",\n",
      "        \"SF-866376\",\n",
      "        \"SF-630607\",\n",
      "        \"SF-469507\",\n",
      "        \"SF-617742\",\n",
      "        \"SF-501056\",\n",
      "        \"SF-428057\"\n",
      "      ],\n",
      "      \"completions_sampled\": 40,\n",
      "      \"generation_settings\": {\n",
      "        \"max_new_tokens\": 256,\n",
      "        \"do_sample\": true,\n",
      "        \"temperature\": 0.8,\n",
      "        \"top_k\": null,\n",
      "        \"pad_token_id\": 151643,\n",
      "        \"eos_token_id\": 151645,\n",
      "        \"transformers_version\": \"4.51.3\"\n",
      "      },\n",
      "      \"adapter_sha256\": \"489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd\"\n",
      "    },\n",
      "    \"stack\": {\n",
      "      \"steps\": 10,\n",
      "      \"optimizer_updates\": 10,\n",
      "      \"seconds\": 57.57017438499997,\n",
      "      \"peak_allocated_gib\": 3.346090316772461,\n",
      "      \"peak_reserved_gib\": 4.158203125,\n",
      "      \"log\": [\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 1172.0,\n",
      "          \"completions/mean_length\": 110.0,\n",
      "          \"completions/min_length\": 110.0,\n",
      "          \"completions/max_length\": 110.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 110.0,\n",
      "          \"completions/min_terminated_length\": 110.0,\n",
      "          \"completions/max_terminated_length\": 110.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.015625,\n",
      "          \"step\": 1\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 2544.0,\n",
      "          \"completions/mean_length\": 129.0,\n",
      "          \"completions/min_length\": 129.0,\n",
      "          \"completions/max_length\": 129.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 129.0,\n",
      "          \"completions/min_terminated_length\": 129.0,\n",
      "          \"completions/max_terminated_length\": 129.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.03125,\n",
      "          \"step\": 2\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 3720.0,\n",
      "          \"completions/mean_length\": 108.0,\n",
      "          \"completions/min_length\": 108.0,\n",
      "          \"completions/max_length\": 108.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 108.0,\n",
      "          \"completions/min_terminated_length\": 108.0,\n",
      "          \"completions/max_terminated_length\": 108.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.046875,\n",
      "          \"step\": 3\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 4752.0,\n",
      "          \"completions/mean_length\": 89.0,\n",
      "          \"completions/min_length\": 89.0,\n",
      "          \"completions/max_length\": 89.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 89.0,\n",
      "          \"completions/min_terminated_length\": 89.0,\n",
      "          \"completions/max_terminated_length\": 89.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.0625,\n",
      "          \"step\": 4\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 5968.0,\n",
      "          \"completions/mean_length\": 111.0,\n",
      "          \"completions/min_length\": 111.0,\n",
      "          \"completions/max_length\": 111.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 111.0,\n",
      "          \"completions/min_terminated_length\": 111.0,\n",
      "          \"completions/max_terminated_length\": 111.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.078125,\n",
      "          \"step\": 5\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 7332.0,\n",
      "          \"completions/mean_length\": 128.0,\n",
      "          \"completions/min_length\": 128.0,\n",
      "          \"completions/max_length\": 128.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 128.0,\n",
      "          \"completions/min_terminated_length\": 128.0,\n",
      "          \"completions/max_terminated_length\": 128.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.09375,\n",
      "          \"step\": 6\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 8528.0,\n",
      "          \"completions/mean_length\": 111.0,\n",
      "          \"completions/min_length\": 111.0,\n",
      "          \"completions/max_length\": 111.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 111.0,\n",
      "          \"completions/min_terminated_length\": 111.0,\n",
      "          \"completions/max_terminated_length\": 111.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.109375,\n",
      "          \"step\": 7\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 9564.0,\n",
      "          \"completions/mean_length\": 91.0,\n",
      "          \"completions/min_length\": 91.0,\n",
      "          \"completions/max_length\": 91.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 91.0,\n",
      "          \"completions/min_terminated_length\": 91.0,\n",
      "          \"completions/max_terminated_length\": 91.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.125,\n",
      "          \"step\": 8\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 10572.0,\n",
      "          \"completions/mean_length\": 86.0,\n",
      "          \"completions/min_length\": 86.0,\n",
      "          \"completions/max_length\": 86.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 86.0,\n",
      "          \"completions/min_terminated_length\": 86.0,\n",
      "          \"completions/max_terminated_length\": 86.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.140625,\n",
      "          \"step\": 9\n",
      "        },\n",
      "        {\n",
      "          \"loss\": 0.0,\n",
      "          \"grad_norm\": 0.0,\n",
      "          \"learning_rate\": 8e-06,\n",
      "          \"num_tokens\": 11916.0,\n",
      "          \"completions/mean_length\": 129.0,\n",
      "          \"completions/min_length\": 129.0,\n",
      "          \"completions/max_length\": 129.0,\n",
      "          \"completions/clipped_ratio\": 0.0,\n",
      "          \"completions/mean_terminated_length\": 129.0,\n",
      "          \"completions/min_terminated_length\": 129.0,\n",
      "          \"completions/max_terminated_length\": 129.0,\n",
      "          \"rewards/semantic_reward/mean\": 1.0,\n",
      "          \"rewards/semantic_reward/std\": 0.0,\n",
      "          \"reward\": 1.0,\n",
      "          \"reward_std\": 0.0,\n",
      "          \"frac_reward_zero_std\": 1.0,\n",
      "          \"clip_ratio/low_mean\": 0.0,\n",
      "          \"clip_ratio/low_min\": 0.0,\n",
      "          \"clip_ratio/high_mean\": 0.0,\n",
      "          \"clip_ratio/high_max\": 0.0,\n",
      "          \"clip_ratio/region_mean\": 0.0,\n",
      "          \"epoch\": 0.15625,\n",
      "          \"step\": 10\n",
      "        },\n",
      "        {\n",
      "          \"train_runtime\": 57.0611,\n",
      "          \"train_samples_per_second\": 0.701,\n",
      "          \"train_steps_per_second\": 0.175,\n",
      "          \"total_flos\": 0.0,\n",
      "          \"train_loss\": 0.0,\n",
      "          \"epoch\": 0.15625,\n",
      "          \"step\": 10\n",
      "        }\n",
      "      ],\n",
      "      \"max_prompt_tokens\": 216,\n",
      "      \"max_label_tokens\": 0,\n",
      "      \"reward_kind\": \"semantic\",\n",
      "      \"learning_rate\": 8e-06,\n",
      "      \"beta\": 0.0,\n",
      "      \"initial_adapter_sha256\": \"05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170\",\n",
      "      \"prompt_roster_sha256\": \"d981fe9a5e7690265ab124c9804ffa09da63ef1da3a82005124b72f28cf3b7b2\",\n",
      "      \"prompt_ids_sha256\": \"a42f7b26c86e52c8c07c82b8a3fd6eb1d6b93fa1ede2f95c465be22c902a8986\",\n",
      "      \"generation_group_size\": 4,\n",
      "      \"audit\": [\n",
      "        {\n",
      "          \"rollout_group\": 1,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-325677\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 110.0,\n",
      "          \"max_tokens\": 110,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 2,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-642032\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 129.0,\n",
      "          \"max_tokens\": 129,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 3,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-835115\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 108.0,\n",
      "          \"max_tokens\": 108,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 4,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-287134\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 89.0,\n",
      "          \"max_tokens\": 89,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 5,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-866376\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 111.0,\n",
      "          \"max_tokens\": 111,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 6,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-630607\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 128.0,\n",
      "          \"max_tokens\": 128,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 7,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-469507\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 111.0,\n",
      "          \"max_tokens\": 111,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 8,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-617742\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 91.0,\n",
      "          \"max_tokens\": 91,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 9,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-501056\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 86.0,\n",
      "          \"max_tokens\": 86,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        },\n",
      "        {\n",
      "          \"rollout_group\": 10,\n",
      "          \"rollout_invoice_ids\": [\n",
      "            \"SF-428057\"\n",
      "          ],\n",
      "          \"completions\": 4,\n",
      "          \"format_mean\": 1.0,\n",
      "          \"semantic_mean\": 1.0,\n",
      "          \"field_mean\": 1.0,\n",
      "          \"row_f1_mean\": 1.0,\n",
      "          \"completion_rate\": 1.0,\n",
      "          \"mean_tokens\": 129.0,\n",
      "          \"max_tokens\": 129,\n",
      "          \"cap_hits_without_eos\": 0,\n",
      "          \"zero_variance_group_share\": 1.0\n",
      "        }\n",
      "      ],\n",
      "      \"rollout_invoice_ids\": [\n",
      "        \"SF-325677\",\n",
      "        \"SF-642032\",\n",
      "        \"SF-835115\",\n",
      "        \"SF-287134\",\n",
      "        \"SF-866376\",\n",
      "        \"SF-630607\",\n",
      "        \"SF-469507\",\n",
      "        \"SF-617742\",\n",
      "        \"SF-501056\",\n",
      "        \"SF-428057\"\n",
      "      ],\n",
      "      \"completions_sampled\": 40,\n",
      "      \"generation_settings\": {\n",
      "        \"max_new_tokens\": 256,\n",
      "        \"do_sample\": true,\n",
      "        \"temperature\": 0.8,\n",
      "        \"top_k\": null,\n",
      "        \"pad_token_id\": 151643,\n",
      "        \"eos_token_id\": 151645,\n",
      "        \"transformers_version\": \"4.51.3\"\n",
      "      },\n",
      "      \"adapter_sha256\": \"74fa3b0bb5968e631a0e7ba59b97dfbc47d5b2a1893b8dd713480154efd880c2\"\n",
      "    }\n",
      "  },\n",
      "  \"lineage\": {\n",
      "    \"SFT\": {\n",
      "      \"parent\": {\n",
      "        \"path\": \"Qwen/Qwen2.5-0.5B-Instruct\",\n",
      "        \"revision\": \"7ae557604adf67be50417f59c2c2f167def9a775\"\n",
      "      },\n",
      "      \"adapter\": {\n",
      "        \"path\": \"lesson-results/06-sft\",\n",
      "        \"sha256\": \"1849b2272ecb25c0262e4d72ff9b322c73e6210578581ba91c940b2e66a366eb\"\n",
      "      },\n",
      "      \"adapter_sha256\": \"ef7f6a30671b600010b98841e0bd9d9a02fb06928e9469e3075e38dd9a6b1cd6\",\n",
      "      \"merged\": {\n",
      "        \"path\": \"lesson-results/06-sft-merged\",\n",
      "        \"sha256\": \"7952969b63edb58bee78a23e303d741c74bc90d459784657e9d46ee89eb5be3f\"\n",
      "      }\n",
      "    },\n",
      "    \"SFT \\u2192 DPO\": {\n",
      "      \"parent\": {\n",
      "        \"path\": \"lesson-results/06-sft-merged\",\n",
      "        \"sha256\": \"7952969b63edb58bee78a23e303d741c74bc90d459784657e9d46ee89eb5be3f\"\n",
      "      },\n",
      "      \"adapter\": {\n",
      "        \"path\": \"lesson-results/06-dpo\",\n",
      "        \"sha256\": \"c25c25de12f5d25bad40b9317665c635ecc2e0c26523aee3a1db91d597f102ee\"\n",
      "      },\n",
      "      \"adapter_sha256\": \"e09139e7e06c78c8078c33eae61351228c61d551688976b99e75b469be934a76\",\n",
      "      \"merged\": {\n",
      "        \"path\": \"lesson-results/06-dpo-merged\",\n",
      "        \"sha256\": \"84732ff2ac723acb6f0d4fc9ab53580fb40bee5fb648884ca6468085d077de9c\"\n",
      "      }\n",
      "    },\n",
      "    \"SFT \\u2192 GRPO\": {\n",
      "      \"parent\": {\n",
      "        \"path\": \"lesson-results/06-sft-merged\",\n",
      "        \"sha256\": \"7952969b63edb58bee78a23e303d741c74bc90d459784657e9d46ee89eb5be3f\"\n",
      "      },\n",
      "      \"adapter\": {\n",
      "        \"path\": \"lesson-results/06-sft-grpo\",\n",
      "        \"sha256\": \"489850dd75183dcc9b3346d8e9cf0573cf4b75b1a7939056e046a9df5fd5e3dd\"\n",
      "      },\n",
      "      \"adapter_sha256\": \"58ad20fc60b2a476624ca009dd4fa6df2e5d0fd0af9d0d80ed0178549fdcd052\",\n",
      "      \"merged\": null\n",
      "    },\n",
      "    \"SFT \\u2192 DPO \\u2192 GRPO\": {\n",
      "      \"parent\": {\n",
      "        \"path\": \"lesson-results/06-dpo-merged\",\n",
      "        \"sha256\": \"84732ff2ac723acb6f0d4fc9ab53580fb40bee5fb648884ca6468085d077de9c\"\n",
      "      },\n",
      "      \"adapter\": {\n",
      "        \"path\": \"lesson-results/06-sft-dpo-grpo\",\n",
      "        \"sha256\": \"74fa3b0bb5968e631a0e7ba59b97dfbc47d5b2a1893b8dd713480154efd880c2\"\n",
      "      },\n",
      "      \"adapter_sha256\": \"58ad20fc60b2a476624ca009dd4fa6df2e5d0fd0af9d0d80ed0178549fdcd052\",\n",
      "      \"merged\": null\n",
      "    }\n",
      "  },\n",
      "  \"base_checkpoint\": {\n",
      "    \"path\": \"Qwen/Qwen2.5-0.5B-Instruct\",\n",
      "    \"revision\": \"7ae557604adf67be50417f59c2c2f167def9a775\"\n",
      "  },\n",
      "  \"t4_profile\": {\n",
      "    \"hardware\": \"Tesla T4\",\n",
      "    \"device_gib\": 14.56317138671875,\n",
      "    \"cuda\": \"13.0\",\n",
      "    \"parent_revision\": \"7ae557604adf67be50417f59c2c2f167def9a775\",\n",
      "    \"profiles\": {\n",
      "      \"SFT\": {\n",
      "        \"steps\": 1,\n",
      "        \"optimizer_updates\": 1,\n",
      "        \"seconds\": 3.6310774180001317,\n",
      "        \"peak_allocated_gib\": 3.383582592010498,\n",
      "        \"peak_reserved_gib\": 4.759765625,\n",
      "        \"max_prompt_tokens\": 217,\n",
      "        \"max_label_tokens\": 132,\n",
      "        \"examples\": 8,\n",
      "        \"learning_rate\": 0.0002,\n",
      "        \"roster_supervised_tokens\": 1051,\n",
      "        \"examples_per_update\": 8,\n",
      "        \"wall_seconds\": 6.05097271700015,\n",
      "        \"free_before_gib\": 14.46075439453125,\n",
      "        \"allocated_before_gib\": 0.0,\n",
      "        \"allocated_after_gib\": 0.015869140625,\n",
      "        \"pass\": true,\n",
      "        \"reserved_limit_gib\": 12.378695678710937,\n",
      "        \"train_seconds_limit\": 35\n",
      "      },\n",
      "      \"DPO\": {\n",
      "        \"steps\": 1,\n",
      "        \"optimizer_updates\": 1,\n",
      "        \"seconds\": 1.5227429520000442,\n",
      "        \"peak_allocated_gib\": 1.9237313270568848,\n",
      "        \"peak_reserved_gib\": 3.15234375,\n",
      "        \"verified_pairs\": 4,\n",
      "        \"max_prompt_tokens\": 215,\n",
      "        \"max_completion_tokens\": 130,\n",
      "        \"implicit_reference\": true,\n",
      "        \"beta\": 0.1,\n",
      "        \"learning_rate\": 1e-05,\n",
      "        \"pairs_per_update\": 4,\n",
      "        \"initial_loss_scale\": 1.0,\n",
      "        \"wall_seconds\": 3.827166546999706,\n",
      "        \"free_before_gib\": 13.24981689453125,\n",
      "        \"allocated_before_gib\": 0.015869140625,\n",
      "        \"allocated_after_gib\": 0.015869140625,\n",
      "        \"pass\": true,\n",
      "        \"reserved_limit_gib\": 11.24981689453125,\n",
      "        \"train_seconds_limit\": 45\n",
      "      },\n",
      "      \"GRPO\": {\n",
      "        \"steps\": 1,\n",
      "        \"optimizer_updates\": 1,\n",
      "        \"seconds\": 13.518826016000276,\n",
      "        \"peak_allocated_gib\": 4.791354179382324,\n",
      "        \"peak_reserved_gib\": 5.232421875,\n",
      "        \"max_prompt_tokens\": 216,\n",
      "        \"max_label_tokens\": 0,\n",
      "        \"reward_kind\": \"semantic\",\n",
      "        \"learning_rate\": 2e-05,\n",
      "        \"beta\": 0.0,\n",
      "        \"initial_adapter_sha256\": \"05c4f6b62233931f06fb7dbf3124c8651d1173c69738b2f9a9ce1fcefc057170\",\n",
      "        \"prompt_roster_sha256\": \"cf1f53f55e6af5fb5de4ea3664b190a5dee21d8f37ba3d1002f09364ed5c4d4e\",\n",
      "        \"prompt_ids_sha256\": \"924bdfba07d2a919ef30496e43fb7fe51dc950f0011d360e859a111dee5dc366\",\n",
      "        \"generation_group_size\": 4,\n",
      "        \"audit\": [\n",
      "          {\n",
      "            \"rollout_group\": 1,\n",
      "            \"rollout_invoice_ids\": [\n",
      "              \"SF-396874\"\n",
      "            ],\n",
      "            \"completions\": 4,\n",
      "            \"format_mean\": 0.0,\n",
      "            \"semantic_mean\": 0.0,\n",
      "            \"field_mean\": 0.0,\n",
      "            \"row_f1_mean\": 0.0,\n",
      "            \"completion_rate\": 0.5,\n",
      "            \"mean_tokens\": 242.0,\n",
      "            \"max_tokens\": 256,\n",
      "            \"cap_hits_without_eos\": 2,\n",
      "            \"zero_variance_group_share\": 1.0\n",
      "          }\n",
      "        ],\n",
      "        \"rollout_invoice_ids\": [\n",
      "          \"SF-396874\"\n",
      "        ],\n",
      "        \"completions_sampled\": 4,\n",
      "        \"generation_settings\": {\n",
      "          \"max_new_tokens\": 256,\n",
      "          \"do_sample\": true,\n",
      "          \"temperature\": 0.8,\n",
      "          \"top_k\": null,\n",
      "          \"pad_token_id\": 151643,\n",
      "          \"eos_token_id\": 151645,\n",
      "          \"transformers_version\": \"4.51.3\"\n",
      "        },\n",
      "        \"wall_seconds\": 15.123694217999855,\n",
      "        \"free_before_gib\": 13.24981689453125,\n",
      "        \"allocated_before_gib\": 0.015869140625,\n",
      "        \"allocated_after_gib\": 0.015869140625,\n",
      "        \"pass\": true,\n",
      "        \"reserved_limit_gib\": 11.24981689453125,\n",
      "        \"train_seconds_limit\": 60\n",
      "      }\n",
      "    },\n",
      "    \"projected_training_seconds\": 498.13881283201226\n",
      "  },\n",
      "  \"fresh_optimizer_at_each_stage\": true,\n",
      "  \"worked_preference\": {\n",
      "    \"key\": \"SF-651508\",\n",
      "    \"visible_invoice\": \"Sample Supplier 3103 billing memo / 2025-12-09\\nAccount invoice SF-651508 [EUR]\\n4 x Meter label @ 146,22 per unit\\n1 x Bench calibration @ 148,13 per unit\\nTotal due 828,30 including tax 95,29; net amount 733,01.\",\n",
      "    \"chosen\": \"{\\\"invoice_id\\\":\\\"SF-651508\\\",\\\"issued_on\\\":\\\"2025-12-09\\\",\\\"supplier\\\":\\\"Sample Supplier 3103\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Meter label\\\",\\\"quantity\\\":4,\\\"unit_minor\\\":14622},{\\\"description\\\":\\\"Bench calibration\\\",\\\"quantity\\\":1,\\\"unit_minor\\\":14813}],\\\"subtotal_minor\\\":73301,\\\"tax_minor\\\":9529,\\\"total_minor\\\":82830}\",\n",
      "    \"rejected\": \"{\\\"invoice_id\\\":\\\"SF-651508\\\",\\\"issued_on\\\":\\\"2025-12-09\\\",\\\"supplier\\\":\\\"Sample Supplier 3103\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Meter label\\\",\\\"quantity\\\":4,\\\"unit_minor\\\":14622},{\\\"description\\\":\\\"Bench calibration\\\",\\\"quantity\\\":1,\\\"unit_minor\\\":14813}],\\\"subtotal_minor\\\":73301,\\\"tax_minor\\\":9529,\\\"total_minor\\\":82831}\",\n",
      "    \"completion_tokens\": 109\n",
      "  },\n",
      "  \"worked_teaching\": {\n",
      "    \"key\": \"SF-228773\",\n",
      "    \"split\": \"novel\",\n",
      "    \"family\": \"novel-02\",\n",
      "    \"visible_invoice\": \"Ref SF-228773 / EUR\\nService fee notice, 2026-05-10\\nSample Supplier 4464\\nUnit 31,75 / 9 times / Cable sleeve\\nUnit 74,11 / 6 times / Cooling filter\\nFee subtotal 730,41\\nPlus tax 94,95\\nAmount requested 826,37\",\n",
      "    \"expected_record_json\": \"{\\\"invoice_id\\\":\\\"SF-228773\\\",\\\"issued_on\\\":\\\"2026-05-10\\\",\\\"supplier\\\":\\\"Sample Supplier 4464\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Cable sleeve\\\",\\\"quantity\\\":9,\\\"unit_minor\\\":3175},{\\\"description\\\":\\\"Cooling filter\\\",\\\"quantity\\\":6,\\\"unit_minor\\\":7411}],\\\"subtotal_minor\\\":73041,\\\"tax_minor\\\":9495,\\\"total_minor\\\":82637}\",\n",
      "    \"outputs\": {\n",
      "      \"Prompted base\": {\n",
      "        \"key\": \"SF-228773\",\n",
      "        \"family\": \"novel-02\",\n",
      "        \"split\": \"novel\",\n",
      "        \"valid\": 0.0,\n",
      "        \"exact\": 0.0,\n",
      "        \"fields\": 0.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": true,\n",
      "        \"generated_tokens\": 188,\n",
      "        \"ms_per_example_in_batch\": 1477.6569249999625,\n",
      "        \"completion\": \"```json\\n{\\n  \\\"invoice_id\\\": \\\"SF-228773\\\",\\n  \\\"issued_on\\\": \\\"2026-05-10\\\",\\n  \\\"supplier\\\": \\\"Sample Supplier 4464\\\",\\n  \\\"currency\\\": \\\"EUR\\\",\\n  \\\"line_items\\\": [\\n    {\\n      \\\"description\\\": \\\"Cable sleeve\\\",\\n      \\\"quantity\\\": 31,\\n      \\\"unit_minor\\\": 9\\n    },\\n    {\\n      \\\"description\\\": \\\"Cooling filter\\\",\\n      \\\"quantity\\\": 6,\\n      \\\"unit_minor\\\": 6\\n    },\\n    {\\n      \\\"description\\\": \\\"Total\\\",\\n      \\\"quantity\\\": 0,\\n      \\\"unit_minor\\\": 0\\n    }\\n  ],\\n  \\\"subtotal_minor\\\": 730.41,\\n  \\\"tax_minor\\\": 94.95,\\n  \\\"total_minor\\\": 826.37\\n}\\n```\"\n",
      "      },\n",
      "      \"SFT\": {\n",
      "        \"key\": \"SF-228773\",\n",
      "        \"family\": \"novel-02\",\n",
      "        \"split\": \"novel\",\n",
      "        \"valid\": 1.0,\n",
      "        \"exact\": 0.0,\n",
      "        \"fields\": 1.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": true,\n",
      "        \"generated_tokens\": 108,\n",
      "        \"ms_per_example_in_batch\": 467.2450543750415,\n",
      "        \"completion\": \"{\\\"invoice_id\\\":\\\"SF-228773\\\",\\\"issued_on\\\":\\\"2026-05-10\\\",\\\"supplier\\\":\\\"Sample Supplier 4464\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Cable sleeve\\\",\\\"quantity\\\":3175,\\\"unit_minor\\\":9},{\\\"description\\\":\\\"Cooling filter\\\",\\\"quantity\\\":7411,\\\"unit_minor\\\":6}],\\\"subtotal_minor\\\":73041,\\\"tax_minor\\\":9495,\\\"total_minor\\\":82637}\"\n",
      "      },\n",
      "      \"SFT \\u2192 DPO\": {\n",
      "        \"key\": \"SF-228773\",\n",
      "        \"family\": \"novel-02\",\n",
      "        \"split\": \"novel\",\n",
      "        \"valid\": 1.0,\n",
      "        \"exact\": 0.0,\n",
      "        \"fields\": 1.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": true,\n",
      "        \"generated_tokens\": 108,\n",
      "        \"ms_per_example_in_batch\": 523.861609249991,\n",
      "        \"completion\": \"{\\\"invoice_id\\\":\\\"SF-228773\\\",\\\"issued_on\\\":\\\"2026-05-10\\\",\\\"supplier\\\":\\\"Sample Supplier 4464\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Cable sleeve\\\",\\\"quantity\\\":3175,\\\"unit_minor\\\":9},{\\\"description\\\":\\\"Cooling filter\\\",\\\"quantity\\\":7411,\\\"unit_minor\\\":6}],\\\"subtotal_minor\\\":73041,\\\"tax_minor\\\":9495,\\\"total_minor\\\":82637}\"\n",
      "      },\n",
      "      \"SFT \\u2192 GRPO\": {\n",
      "        \"key\": \"SF-228773\",\n",
      "        \"family\": \"novel-02\",\n",
      "        \"split\": \"novel\",\n",
      "        \"valid\": 1.0,\n",
      "        \"exact\": 0.0,\n",
      "        \"fields\": 1.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": true,\n",
      "        \"generated_tokens\": 108,\n",
      "        \"ms_per_example_in_batch\": 743.9032868750246,\n",
      "        \"completion\": \"{\\\"invoice_id\\\":\\\"SF-228773\\\",\\\"issued_on\\\":\\\"2026-05-10\\\",\\\"supplier\\\":\\\"Sample Supplier 4464\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Cable sleeve\\\",\\\"quantity\\\":3175,\\\"unit_minor\\\":9},{\\\"description\\\":\\\"Cooling filter\\\",\\\"quantity\\\":7411,\\\"unit_minor\\\":6}],\\\"subtotal_minor\\\":73041,\\\"tax_minor\\\":9495,\\\"total_minor\\\":82637}\"\n",
      "      },\n",
      "      \"SFT \\u2192 DPO \\u2192 GRPO\": {\n",
      "        \"key\": \"SF-228773\",\n",
      "        \"family\": \"novel-02\",\n",
      "        \"split\": \"novel\",\n",
      "        \"valid\": 1.0,\n",
      "        \"exact\": 0.0,\n",
      "        \"fields\": 1.0,\n",
      "        \"row_f1\": 0.0,\n",
      "        \"natural_completion\": true,\n",
      "        \"generated_tokens\": 108,\n",
      "        \"ms_per_example_in_batch\": 682.9937658749827,\n",
      "        \"completion\": \"{\\\"invoice_id\\\":\\\"SF-228773\\\",\\\"issued_on\\\":\\\"2026-05-10\\\",\\\"supplier\\\":\\\"Sample Supplier 4464\\\",\\\"currency\\\":\\\"EUR\\\",\\\"line_items\\\":[{\\\"description\\\":\\\"Cable sleeve\\\",\\\"quantity\\\":3175,\\\"unit_minor\\\":9},{\\\"description\\\":\\\"Cooling filter\\\",\\\"quantity\\\":7411,\\\"unit_minor\\\":6}],\\\"subtotal_minor\\\":73041,\\\"tax_minor\\\":9495,\\\"total_minor\\\":82637}\"\n",
      "      }\n",
      "    }\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "by_split = {\n",
    "    name: {split: summary([row for row in rows if row[\"split\"] == split])\n",
    "           for split in (\"familiar\", \"novel\", \"independent\")}\n",
    "    for name, rows in results.items()\n",
    "}\n",
    "lineage = {\"SFT\": warm_stage, \"SFT \u2192 DPO\": dpo_stage, \"SFT \u2192 GRPO\": grpo_stage,\n",
    "           \"SFT \u2192 DPO \u2192 GRPO\": stack_stage}\n",
    "roster_rows = [\n",
    "    {\"key\": invoice.key, \"split\": invoice.split, \"family\": invoice.family,\n",
    "     \"visible_invoice\": invoice_text(invoice), \"expected_record_json\": packed(invoice_record(invoice))}\n",
    "    for invoice in teaching\n",
    "]\n",
    "training_example = pairs[0]\n",
    "teaching_example = next(row for row in roster_rows if row[\"key\"] == \"SF-228773\")\n",
    "write_report(\"06\", {\n",
    "    \"catalog_version\": CATALOG_VERSION, \"catalog_sha256\": manifest(catalog), \"split_rosters\": splits,\n",
    "    \"learning_rate_screen\": screen, \"selected_grpo_rate\": chosen_rate,\n",
    "    \"scores\": scores, \"splits\": by_split, \"increments\": increments, \"interaction\": interaction,\n",
    "    \"training\": {\"sft\": warm_stats, \"dpo\": dpo_stats, \"grpo\": grpo_stats, \"stack\": stack_stats},\n",
    "    \"lineage\": lineage, \"base_checkpoint\": base_parent, \"t4_profile\": profile,\n",
    "    \"fresh_optimizer_at_each_stage\": True,\n",
    "    \"worked_preference\": {\n",
    "        \"key\": training_example[\"record_key\"], \"visible_invoice\": training_example[\"prompt\"][-1][\"content\"],\n",
    "        \"chosen\": training_example[\"chosen\"][0][\"content\"], \"rejected\": training_example[\"rejected\"][0][\"content\"],\n",
    "        \"completion_tokens\": sum(preference_features(training_example, tok)[0][\"completion_mask\"]),\n",
    "    },\n",
    "    \"worked_teaching\": {\n",
    "        **teaching_example, \"outputs\": {\n",
    "            name: next(row for row in rows if row[\"key\"] == teaching_example[\"key\"]) for name, rows in results.items()\n",
    "        },\n",
    "    },\n",
    "}, roster=roster_rows, examples=[\n",
    "    {\"checkpoint\": name, **row, \"fields\": packed(row[\"fields\"])}\n",
    "    for name, rows in results.items() for row in rows\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "34f79632",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\" width=\"576pt\" height=\"230.4pt\" viewBox=\"0 0 576 230.4\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2026-11-27T09:08:41.836601</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.10.8, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 230.4  L 576 230.4  L 576 0  L 0 0  z \" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 139.93 188.44  L 565.2 188.44  L 565.2 10.8  L 139.93 10.8  z \" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <defs>\n",
       "       <path id=\"mdb803ad35f\" d=\"M 0 0  L 0 3.5  \" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"169.597596\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"169.597596\" y=\"203.038437\" transform=\"rotate(-0 169.597596 203.038437)\">0</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_2\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"219.215875\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"219.215875\" y=\"203.038437\" transform=\"rotate(-0 219.215875 203.038437)\">10</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"268.834154\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"268.834154\" y=\"203.038437\" transform=\"rotate(-0 268.834154 203.038437)\">20</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"318.452433\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"318.452433\" y=\"203.038437\" transform=\"rotate(-0 318.452433 203.038437)\">30</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"368.070712\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"368.070712\" y=\"203.038437\" transform=\"rotate(-0 368.070712 203.038437)\">40</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"417.688991\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"417.688991\" y=\"203.038437\" transform=\"rotate(-0 417.688991 203.038437)\">50</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"467.30727\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"467.30727\" y=\"203.038437\" transform=\"rotate(-0 467.30727 203.038437)\">60</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_8\">\n",
       "     <g id=\"line2d_8\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mdb803ad35f\" x=\"516.925549\" y=\"188.44\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"516.925549\" y=\"203.038437\" transform=\"rotate(-0 516.925549 203.038437)\">70</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_9\">\n",
       "     <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: middle\" x=\"352.565\" y=\"216.716562\" transform=\"rotate(-0 352.565 216.716562)\">Exact complete records, percentage-point difference</text>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <defs>\n",
       "       <path id=\"m4678125d12\" d=\"M 0 0  L -3.5 0  \" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m4678125d12\" x=\"139.93\" y=\"18.874545\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: end\" x=\"132.93\" y=\"22.673764\" transform=\"rotate(-0 132.93 22.673764)\">SFT minus base</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m4678125d12\" x=\"139.93\" y=\"51.172727\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: end\" x=\"132.93\" y=\"54.971946\" transform=\"rotate(-0 132.93 54.971946)\">DPO minus SFT</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m4678125d12\" x=\"139.93\" y=\"83.470909\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: end\" x=\"132.93\" y=\"87.270128\" transform=\"rotate(-0 132.93 87.270128)\">GRPO minus SFT</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m4678125d12\" x=\"139.93\" y=\"115.769091\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: end\" x=\"132.93\" y=\"119.56831\" transform=\"rotate(-0 132.93 119.56831)\">GRPO after DPO</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m4678125d12\" x=\"139.93\" y=\"148.067273\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: end\" x=\"132.93\" y=\"151.866491\" transform=\"rotate(-0 132.93 151.866491)\">combined minus SFT</text>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m4678125d12\" x=\"139.93\" y=\"180.365455\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_15\">\n",
       "      <text style=\"font-size: 10px; font-family: 'DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', sans-serif; text-anchor: end\" x=\"132.93\" y=\"184.164673\" transform=\"rotate(-0 132.93 184.164673)\">GRPO \u00d7 DPO interaction</text>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_1\">\n",
       "    <path d=\"M 376.340425 18.874545  L 545.869545 18.874545  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #44698a; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_2\">\n",
       "    <path d=\"M 159.260455 51.172727  L 190.271879 51.172727  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #44698a; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_3\">\n",
       "    <path d=\"M 169.597596 83.470909  L 169.597596 83.470909  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #44698a; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_4\">\n",
       "    <path d=\"M 169.597596 115.769091  L 169.597596 115.769091  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #44698a; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_5\">\n",
       "    <path d=\"M 159.260455 148.067273  L 190.271879 148.067273  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #44698a; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"LineCollection_6\">\n",
       "    <path d=\"M 169.597596 180.365455  L 169.597596 180.365455  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #44698a; stroke-width: 1.5\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_15\">\n",
       "    <path d=\"M 169.597596 188.44  L 169.597596 10.8  \" clip-path=\"url(#p52920f2594)\" style=\"fill: none; stroke: #737a81; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 139.93 188.44  L 139.93 10.8  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 565.2 188.44  L 565.2 10.8  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 139.93 188.44  L 565.2 188.44  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 139.93 10.8  L 565.2 10.8  \" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_1\">\n",
       "    <defs>\n",
       "     <path id=\"m610a38e4e9\" d=\"M 0 3  C 0.795609 3 1.55874 2.683901 2.12132 2.12132  C 2.683901 1.55874 3 0.795609 3 0  C 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132  C 1.55874 -2.683901 0.795609 -3 0 -3  C -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132  C -2.683901 -1.55874 -3 -0.795609 -3 0  C -3 0.795609 -2.683901 1.55874 -2.12132 2.12132  C -1.55874 2.683901 -0.795609 3 0 3  z \" style=\"stroke: #254864\"/>\n",
       "    </defs>\n",
       "    <g clip-path=\"url(#p52920f2594)\">\n",
       "     <use xlink:href=\"#m610a38e4e9\" x=\"463.172414\" y=\"18.874545\" style=\"fill: #254864; stroke: #254864\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_2\">\n",
       "    <g clip-path=\"url(#p52920f2594)\">\n",
       "     <use xlink:href=\"#m610a38e4e9\" x=\"175.799881\" y=\"51.172727\" style=\"fill: #254864; stroke: #254864\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_3\">\n",
       "    <g clip-path=\"url(#p52920f2594)\">\n",
       "     <use xlink:href=\"#m610a38e4e9\" x=\"169.597596\" y=\"83.470909\" style=\"fill: #254864; stroke: #254864\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_4\">\n",
       "    <g clip-path=\"url(#p52920f2594)\">\n",
       "     <use xlink:href=\"#m610a38e4e9\" x=\"169.597596\" y=\"115.769091\" style=\"fill: #254864; stroke: #254864\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_5\">\n",
       "    <g clip-path=\"url(#p52920f2594)\">\n",
       "     <use xlink:href=\"#m610a38e4e9\" x=\"175.799881\" y=\"148.067273\" style=\"fill: #254864; stroke: #254864\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_6\">\n",
       "    <g clip-path=\"url(#p52920f2594)\">\n",
       "     <use xlink:href=\"#m610a38e4e9\" x=\"169.597596\" y=\"180.365455\" style=\"fill: #254864; stroke: #254864\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p52920f2594\">\n",
       "   <rect x=\"139.93\" y=\"10.8\" width=\"425.27\" height=\"177.64\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import SVG\n",
    "\n",
    "plt.rcParams[\"svg.fonttype\"] = \"none\"\n",
    "figure, axis = plt.subplots(figsize=(8, 3.2))\n",
    "names = list(increments) + [\"GRPO \u00d7 DPO interaction\"]\n",
    "values = list(increments.values()) + [interaction]\n",
    "for position, receipt in enumerate(values):\n",
    "    low, high = (100 * x for x in receipt[\"paired_family_bootstrap_95\"])\n",
    "    axis.hlines(position, low, high, color=\"#44698a\")\n",
    "    axis.scatter(100 * receipt[\"delta\"], position, color=\"#254864\", zorder=3)\n",
    "axis.axvline(0, color=\"#737a81\", linewidth=1)\n",
    "axis.set(yticks=range(len(names)), yticklabels=names, xlabel=\"Exact complete records, percentage-point difference\")\n",
    "axis.invert_yaxis()\n",
    "figure.tight_layout()\n",
    "svg = OUT / \"06-stage-effects.svg\"\n",
    "figure.savefig(svg, format=\"svg\")\n",
    "plt.close(figure)\n",
    "display(SVG(filename=str(svg)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ed19b7e",
   "metadata": {},
   "source": [
    "## Sources\n",
    "\n",
    "[Ai2 T\u00fclu 3](https://arxiv.org/abs/2411.15124) \u00b7\n",
    "[NVIDIA Nemotron 3.5 Parse](https://huggingface.co/blog/nvidia/building-on-nemotron-35-parse-open-data-fine-tunin) \u00b7\n",
    "[Direct Preference Optimization](https://arxiv.org/abs/2305.18290) \u00b7\n",
    "[DeepSeekMath GRPO](https://arxiv.org/abs/2402.03300) \u00b7\n",
    "[Cookbook weights-only handoff](https://github.com/togethercomputer/post-training-cookbook/blob/226e03ca225d6f13434047cf0f45ab3070a29801/recipes/sft_then_grpo.py)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5cdd758",
   "metadata": {},
   "source": [
    "## Read the result\n",
    "\n",
    "Ask what each new stage added on the same inputs and how much extra compute it used.\n",
    "\n",
    "[Return to the lesson](https://docs.recohut.com/courses/advanced-llm-fine-tuning/2-compare-training-stages/06-test-the-training-stack)."
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
