{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-1 fw=all -->\n",
    "\n",
    "# Scaling Laws and the Modern Recipe\n",
    "\n",
    "The models of this chapter differ from the deployed ones mainly by a\n",
    "number. Same block, same causal wiring, same training loop; what separates\n",
    "our minute of GPU time from a frontier run is parameters, tokens, and the\n",
    "floating-point operations that couple them. This closing section is about\n",
    "that number. One boundary first: that section in the optimization\n",
    "chapter asked how to *tune* across scale — muP transfers a learning rate\n",
    "found on a small model to a large one. Here we ask what scale itself buys,\n",
    "and how a training budget should be split between model size and data. We\n",
    "learn to count parameters and FLOPs, deriving the $6ND$ rule and checking\n",
    "it against a profiler; we run a scaling study small enough for one GPU\n",
    "that shows both the celebrated straight line and its less celebrated end;\n",
    "and we read the 2023–2025 open-weights reports as a table\n",
    "whose rows are, almost verbatim, constructor calls of the `GPT` class from\n",
    "that section."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-scaling-laws-and-the-modern-recipe"
   },
   "source": [
    "%matplotlib inline\n",
    "from d2l import torch as d2l\n",
    "import time\n",
    "import torch\n",
    "from torch.nn import functional as F\n",
    "from torch.profiler import ProfilerActivity, profile"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-2 fw=all -->\n",
    "\n",
    "## Counting Parameters and FLOPs\n",
    "\n",
    "### A Parameter Census\n",
    "\n",
    "A GPT holds two kinds of parameters, and they scale differently. The\n",
    "blocks hold $12d^2$ each — $4d^2$ of attention, $8d^2$ of feed-forward\n",
    "network, however the activation slices it\n",
    "(that section) — for about $12Ld^2$ across $L$ blocks.\n",
    "The embedding holds $Vd$ for a vocabulary of size $V$, used twice thanks\n",
    "to weight tying but stored once; a learned position table adds another\n",
    "$\\textrm{max\\_len} \\times d$. The census below runs the accounting on our\n",
    "default configuration and on the GPT-2 configuration from\n",
    "that section:"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-a-parameter-census"
   },
   "source": [
    "count = lambda m: sum(p.numel() for p in m.parameters())\n",
    "\n",
    "def census(model, d, num_blks):\n",
    "    emb = count(model.token_emb) + (\n",
    "        count(model.pos_emb) if model.pos == 'learned' else 0)\n",
    "    total = count(model)\n",
    "    print(f'embedding {emb / 1e6:6.2f}M ({emb / total:4.0%}),  '\n",
    "          f'blocks {(total - emb) / 1e6:6.2f}M '\n",
    "          f'= {(total - emb) / (num_blks * d ** 2):.2f} L d^2,  '\n",
    "          f'total {total / 1e6:.2f}M')\n",
    "\n",
    "census(d2l.GPT(vocab_size=28), d=256, num_blks=6)\n",
    "census(d2l.GPT(vocab_size=50257, num_hiddens=768, num_heads=12,\n",
    "               num_blks=12, pos='learned', norm='layer', act='gelu',\n",
    "               bias=True), d=768, num_blks=12)"
   ],
   "execution_count": 2,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "embedding   0.01M (  0%),  blocks   4.72M = 12.01 L d^2,  total 4.73M\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "embedding  39.38M ( 32%),  blocks  85.06M = 12.02 L d^2,  total 124.44M\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-3 fw=all -->\n",
    "\n",
    "Both rows confirm the $12Ld^2$ rule to a fraction of a percent (the\n",
    "residue is normalization weights and, for GPT-2, biases). The interesting\n",
    "column is the embedding share: negligible for our character model with its\n",
    "28 symbols, but nearly a third of GPT-2. Comparing $Vd$ against $12Ld^2$\n",
    "says the embedding dominates when $V \\gtrsim 12Ld$ — small models with\n",
    "real vocabularies. GPT-2's \"124M parameters\" is in this sense a generous\n",
    "description of an 85M-parameter transformer attached to a 39M-parameter\n",
    "lookup table. Scaling-law papers accordingly count *non-embedding*\n",
    "parameters [@kaplan2020scaling]: the embedding's size tracks the\n",
    "tokenizer's vocabulary, not the computation each token receives, and\n",
    "including it bends the low-end of every curve for accounting reasons\n",
    "rather than scientific ones. We adopt the same convention; $N$ below means\n",
    "non-embedding parameters.\n",
    "\n",
    "### Six FLOPs per Parameter and Token\n",
    "\n",
    "Training cost has an equally compact rule. Multiplying one token's\n",
    "activation vector by a weight matrix $\\mathbf{W} \\in \\mathbb{R}^{m \\times\n",
    "n}$ takes $mn$ multiply–add pairs: 2 FLOPs per parameter, so a forward\n",
    "pass costs about $2N$ per token. The backward pass costs twice the\n",
    "forward: each linear layer must produce *two* gradients, one with respect\n",
    "to its input ($\\mathbf{W}^\\top \\boldsymbol{\\delta}$, to keep the chain\n",
    "rule moving) and one with respect to its weights ($\\boldsymbol{\\delta}\n",
    "\\mathbf{x}^\\top$, to learn), and each is a matrix multiply of the same\n",
    "size as the forward one. Training on $D$ tokens therefore costs\n",
    "\n",
    "$$\n",
    "C \\approx \\underbrace{2ND}_{\\textrm{forward}} +\n",
    "\\underbrace{4ND}_{\\textrm{backward}} = 6ND\n",
    "$$\n",
    "\n",
    "floating-point operations [@kaplan2020scaling]. This is training\n",
    "arithmetic; the corresponding decode-time accounting — why *generating* a\n",
    "token costs about $2N$ and why the KV cache turns generation into a\n",
    "memory problem rather than a compute one — was the business of\n",
    "that section.\n",
    "\n",
    "What the rule rounds away is worth knowing. The attention scores\n",
    "$\\mathbf{q}^\\top \\mathbf{k}$ and the mixture $\\mathbf{A}\\mathbf{V}$ cost\n",
    "about $4nd$ per token per layer against the linear layers' $24d^2$, a\n",
    "correction of $n/(6d)$ — about 8% at our context 128 and width 256,\n",
    "growing to parity only at contexts around $6d$. Normalization, softmax,\n",
    "and the optimizer update are all vector work, $\\mathcal{O}(d)$ or\n",
    "$\\mathcal{O}(N)$ per step rather than per token: noise. A useful habit\n",
    "follows: the cost of any dense transformer run is two numbers multiplied,\n",
    "which is how our one-minute run in that section could be placed at\n",
    "$5 \\times 10^{14}$ FLOPs, the 124M GPT-2's near $7 \\times 10^{18}$, and\n",
    "frontier runs near $10^{25}$, all without consulting a profiler.\n",
    "\n",
    "### Checking the Arithmetic\n",
    "\n",
    "A formula this convenient deserves a check against an authority that has\n",
    "not read our derivation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-4 fw=pytorch -->\n",
    "\n",
    "PyTorch's profiler attributes FLOPs to the operations it recognizes —\n",
    "above all the `aten::mm` matrix multiplies behind every linear layer. The\n",
    "fused attention kernel keeps its score arithmetic to itself and reports\n",
    "none, so the profiler and the equation ignore the *same* subleading\n",
    "term. For the count, $N$ plus the tied output head is exactly the 2-D\n",
    "parameters of the RoPE configuration (the embedding earns its FLOPs as\n",
    "the head; a gather costs nothing)."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-checking-the-arithmetic"
   },
   "source": [
    "device = d2l.try_gpu()\n",
    "model = d2l.GPT(vocab_size=28).to(device)\n",
    "X = torch.randint(0, 28, (64, 128), device=device)\n",
    "Y = torch.randint(0, 28, (64, 128), device=device)\n",
    "N = sum(p.numel() for p in model.parameters() if p.ndim == 2)\n",
    "\n",
    "def train_step():\n",
    "    loss = F.cross_entropy(model(X).flatten(0, 1), Y.flatten())\n",
    "    model.zero_grad()\n",
    "    loss.backward()\n",
    "\n",
    "for _ in range(3):\n",
    "    train_step()                    # warm up\n",
    "with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],\n",
    "             with_flops=True) as prof:\n",
    "    train_step()\n",
    "measured = sum(e.flops for e in prof.key_averages() if e.flops)\n",
    "print(f'6ND analytic: {6 * N * X.numel():.3e} FLOPs')\n",
    "print(f'profiler:     {measured:.3e} FLOPs '\n",
    "      f'(ratio {measured / (6 * N * X.numel()):.3f})')\n",
    "if device.type == 'cuda':\n",
    "    torch.cuda.synchronize()\n",
    "t0 = time.time()\n",
    "for _ in range(20):\n",
    "    train_step()\n",
    "if device.type == 'cuda':\n",
    "    torch.cuda.synchronize()\n",
    "dt = (time.time() - t0) / 20\n",
    "print(f'{dt * 1e3:.0f} ms per step: '\n",
    "      f'{6 * N * X.numel() / dt / 1e12:.1f} TFLOP/s achieved')"
   ],
   "execution_count": 3,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "/home/smola/d2l-neu/.venv-pytorch/lib/python3.12/site-packages/torch/profiler/profiler.py:224: UserWarning: Warning: Profiler clears events at the end of each cycle.Only events from the current cycle will be reported.To keep events across cycles, set acc_events=True.\n  _warn_once(\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "6ND analytic: 2.324e+11 FLOPs\nprofiler:     2.326e+11 FLOPs (ratio 1.001)\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "26 ms per step: 8.8 TFLOP/s achieved\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-5 fw=all -->\n",
    "\n",
    "Both authorities side with the formula. The PyTorch profiler's count\n",
    "agrees with $6ND$ to a fraction of a percent — matching so tightly only\n",
    "because both books omit the fused attention kernel's score work. XLA's\n",
    "static analysis, which counts everything, lands about ten percent above\n",
    "$6ND$, right where the $n/(6d)$ correction plus softmax and normalization\n",
    "put it, and splits forward to backward at almost exactly one to two: the\n",
    "derivation's 2-plus-4, read off a compiler's ledger. The timing line adds\n",
    "a sobering coda: our achieved throughput is roughly an order of magnitude\n",
    "below what the GPU can deliver, because a model this small cannot keep\n",
    "the machine fed. Production runs choose widths and batch sizes with the\n",
    "hardware's appetite in mind, which is one reason real models are as large\n",
    "as they are.\n",
    "\n",
    "## A Miniature Scaling Study\n",
    "\n",
    "Counting tells us what a run costs; it says nothing about what the cost\n",
    "buys. The empirical regularity that changed how budgets are planned is\n",
    "the *scaling law*: across many orders of magnitude, language-model loss\n",
    "falls as a power law in each of model size, data, and compute, provided\n",
    "none of the three is the bottleneck [@kaplan2020scaling]. On log-log\n",
    "axes a power law is a straight line, and straight lines extrapolate: a\n",
    "lab can fit the line on cheap runs and read off what a thousandfold more\n",
    "compute should deliver. The follow-up that named an era asked how to\n",
    "*split* a fixed compute budget between $N$ and $D$ and found the answer\n",
    "roughly balanced: parameters and tokens should grow together, about\n",
    "twenty tokens per parameter at the optimum\n",
    "[@hoffmann2022training] — the *Chinchilla* ratio. Its 70B-parameter\n",
    "model, trained on 1.4 trillion tokens, beat a 280B-parameter model\n",
    "trained on 300 billion at the same compute: the era's flagships had been\n",
    "oversized and underfed.\n",
    "\n",
    "We can watch both halves of that story — the line and the reason it\n",
    "breaks — on one GPU, by training one family of models on one fixed\n",
    "corpus.\n",
    "\n",
    "### A Corpus Bigger than a Novella\n",
    "\n",
    "that section already showed what a too-small corpus does: 4.7M\n",
    "parameters against 180 KB of Wells bottomed out their validation loss\n",
    "within a few hundred steps and spent the rest of the run memorizing. Our\n",
    "own preliminary check confirms the diagnosis for the whole size range: on\n",
    "*The Time Machine* alone, every configuration beyond about $10^5$\n",
    "parameters is saturated more or less immediately. A scaling study needs a\n",
    "corpus that can keep its larger sizes honest for at least a while, and we\n",
    "can assemble one without leaving the book's pantry: the Penn Treebank\n",
    "training text (5 MB of Wall Street Journal prose that\n",
    "that section uses for word vectors) concatenated onto the\n",
    "novel. The subclass below reuses the entire character pipeline of\n",
    "`d2l.TimeMachine` and changes two things: `_download` returns the\n",
    "concatenated text, and the windows stride by `num_steps` instead of\n",
    "overlapping (five million overlapping windows would be a five-gigabyte\n",
    "tensor for no statistical gain). One cosmetic note: PTB ships\n",
    "pre-tokenized, with rare words replaced by `<unk>` and numbers by `N`,\n",
    "which the character pipeline renders as the literal words *unk* and *n* —\n",
    "harmless static for a character model."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-a-corpus-bigger-than-a-novella"
   },
   "source": [
    "class ScalingCorpus(d2l.TimeMachine):\n",
    "    \"\"\"Character corpus: The Time Machine plus the PTB training text.\"\"\"\n",
    "    def _download(self):\n",
    "        data_dir = d2l.download_extract('ptb')\n",
    "        with open(f'{data_dir}/ptb.train.txt') as f:\n",
    "            ptb = f.read()\n",
    "        return super()._download() + ' ' + ptb\n",
    "\n",
    "    def __init__(self, batch_size, num_steps, num_val=2000):\n",
    "        d2l.DataModule.__init__(self)\n",
    "        self.save_hyperparameters()\n",
    "        corpus, self.vocab = self.build(self._download())\n",
    "        array = d2l.tensor([corpus[i:i + num_steps + 1] for i in\n",
    "                            range(0, len(corpus) - num_steps, num_steps)])\n",
    "        self.X, self.Y = array[:, :-1], array[:, 1:]\n",
    "        self.num_train = len(array) - num_val\n",
    "\n",
    "data = ScalingCorpus(batch_size=64, num_steps=128)\n",
    "print(f'{len(data.X) * 128 / 1e6:.1f}M characters in {len(data.X)} '\n",
    "      f'windows, vocabulary size {len(data.vocab)}')"
   ],
   "execution_count": 4,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "5.1M characters in 39491 windows, vocabulary size 28\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-6 fw=all -->\n",
    "\n",
    "Five million characters is still comically small — it is to a frontier\n",
    "corpus what our models are to a frontier model — but the ratio is what\n",
    "matters. Our sizes will run from roughly the largest model a corpus like\n",
    "this can feed at the published twenty-tokens-per-parameter optimum to\n",
    "fifty times past it, which is exactly the position a study of saturation\n",
    "wants to be in.\n",
    "\n",
    "### Five Sizes, One Diet\n",
    "\n",
    "The design: hold the data fixed and move only the model. Five sizes of\n",
    "`d2l.GPT`, widths 96 to 384 and depths 3 to 8 grown together the way real\n",
    "model families grow, spanning 0.33M to 14.2M non-embedding parameters —\n",
    "about a factor of forty. Every size consumes an identical diet of 16.4M\n",
    "tokens (2,000 steps of 64 sequences of 128 characters), roughly three\n",
    "passes over the corpus. Dropout is zero: it was a small-corpus crutch in\n",
    "that section, this experiment is *about* the corpus running out, and\n",
    "the recipe table below will show that models whose corpora outweigh their\n",
    "parameters do not use it either. The one hyperparameter that must not be\n",
    "held fixed is the learning rate: that section showed that the\n",
    "tuned optimum drifts with width, and a rate frozen at any single value\n",
    "would handicap one end of the family (our pilot grid confirmed it at\n",
    "both ends). We apply that section's transfer rule instead of re-tuning:\n",
    "anchor at $10^{-3}$ for width 256 and scale inversely with width. One\n",
    "seeded run per size; rerunning a point with a different seed moves it by\n",
    "less than a hundredth of a nat, well below the structure we are about to\n",
    "read."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-five-sizes-one-diet-1"
   },
   "source": [
    "def val_loss(model, data):\n",
    "    model.to(device).eval()\n",
    "    with torch.no_grad():\n",
    "        losses = [F.cross_entropy(\n",
    "            model(X.to(device)).flatten(0, 1), Y.to(device).flatten())\n",
    "            for X, Y in data.val_dataloader()]\n",
    "    model.train()\n",
    "    return sum(l.item() for l in losses) / len(losses)\n",
    "\n",
    "sizes = ((96, 3, 4), (128, 3, 4), (192, 4, 6), (256, 6, 8), (384, 8, 8))\n",
    "Ns, curves = [], {'train': [], 'validation': []}\n",
    "for d, num_blks, num_heads in sizes:\n",
    "    torch.manual_seed(0)\n",
    "    model = d2l.GPT(len(data.vocab), num_hiddens=d, num_heads=num_heads,\n",
    "                    num_blks=num_blks, dropout=0)\n",
    "    optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3 * 256 / d,\n",
    "                                  weight_decay=0.0)\n",
    "    losses = d2l.train_lm(model, data, optimizer, 2000)\n",
    "    Ns.append(count(model) - count(model.token_emb))\n",
    "    curves['train'].append(sum(losses[-50:]) / 50)\n",
    "    curves['validation'].append(val_loss(model, data))\n",
    "    print(f'd={d:3d}, {num_blks} blocks: {Ns[-1] / 1e6:5.2f}M parameters, '\n",
    "          f'train {curves[\"train\"][-1]:.2f}, '\n",
    "          f'validation {curves[\"validation\"][-1]:.2f}')"
   ],
   "execution_count": 5,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "d= 96, 3 blocks:  0.33M parameters, train 1.21, validation 1.20\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "d=128, 3 blocks:  0.59M parameters, train 1.17, validation 1.17\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "d=192, 4 blocks:  1.77M parameters, train 1.11, validation 1.12\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "d=256, 6 blocks:  4.72M parameters, train 1.06, validation 1.09\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "d=384, 8 blocks: 14.16M parameters, train 1.03, validation 1.07\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-five-sizes-one-diet-2"
   },
   "source": [
    "d2l.plot(Ns, [curves['train'], curves['validation']],\n",
    "         'parameters $N$ (non-embedding)', 'loss',\n",
    "         legend=['train', 'validation'], xscale='log', yscale='log',\n",
    "         fmts=('o-', 's--'))"
   ],
   "execution_count": 6,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"287.278125pt\" height=\"183.378125pt\" viewBox=\"0 0 287.278125 183.378125\" xmlns=\"http://www.w3.org/2000/svg\" 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-07-19T14:08:48.867108</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 183.378125 \nL 287.278125 183.378125 \nL 287.278125 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 84.778125 145.8 \nL 280.078125 145.8 \nL 280.078125 7.2 \nL 84.778125 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 145.769825 145.8 \nL 145.769825 7.2 \n\" clip-path=\"url(#p821a0a48c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"mcae1bf64cc\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mcae1bf64cc\" x=\"145.769825\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- $\\mathdefault{10^{6}}$ -->\n      <g transform=\"translate(136.969825 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(128.203125 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 254.732845 145.8 \nL 254.732845 7.2 \n\" clip-path=\"url(#p821a0a48c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mcae1bf64cc\" x=\"254.732845\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- $\\mathdefault{10^{7}}$ -->\n      <g transform=\"translate(245.932845 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-37\" d=\"M 525 4666 \nL 3525 4666 \nL 3525 4397 \nL 1831 0 \nL 1172 0 \nL 2766 4134 \nL 525 4134 \nL 525 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.684375)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0.684375)\"/>\n       <use xlink:href=\"#DejaVuSans-37\" transform=\"translate(128.203125 38.965625) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <defs>\n       <path id=\"m027ae1d3b4\" d=\"M 0 0 \nL 0 2 \n\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"88.795378\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"102.40908\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_7\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"112.968688\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_6\">\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"121.596515\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_7\">\n     <g id=\"line2d_9\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"128.89124\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_8\">\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"135.210217\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_9\">\n     <g id=\"line2d_11\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"140.783951\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_10\">\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"178.570962\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_11\">\n     <g id=\"line2d_13\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"197.758398\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_12\">\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"211.3721\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_13\">\n     <g id=\"line2d_15\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"221.931707\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_14\">\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"230.559535\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_15\">\n     <g id=\"line2d_17\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"237.854259\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_16\">\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"244.173237\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_17\">\n     <g id=\"line2d_19\">\n      <g>\n       <use xlink:href=\"#m027ae1d3b4\" x=\"249.74697\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_3\">\n     <!-- parameters $N$ (non-embedding) -->\n     <g transform=\"translate(103.128125 174.078125) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6d\" d=\"M 3328 2828 \nQ 3544 3216 3844 3400 \nQ 4144 3584 4550 3584 \nQ 5097 3584 5394 3201 \nQ 5691 2819 5691 2113 \nL 5691 0 \nL 5113 0 \nL 5113 2094 \nQ 5113 2597 4934 2840 \nQ 4756 3084 4391 3084 \nQ 3944 3084 3684 2787 \nQ 3425 2491 3425 1978 \nL 3425 0 \nL 2847 0 \nL 2847 2094 \nQ 2847 2600 2669 2842 \nQ 2491 3084 2119 3084 \nQ 1678 3084 1418 2786 \nQ 1159 2488 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1356 3278 1631 3431 \nQ 1906 3584 2284 3584 \nQ 2666 3584 2933 3390 \nQ 3200 3197 3328 2828 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-Oblique-4e\" d=\"M 1081 4666 \nL 1931 4666 \nL 3219 666 \nL 4000 4666 \nL 4616 4666 \nL 3706 0 \nL 2853 0 \nL 1569 4025 \nL 788 0 \nL 172 0 \nL 1081 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-2d\" d=\"M 313 2009 \nL 1997 2009 \nL 1997 1497 \nL 313 1497 \nL 313 2009 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-62\" d=\"M 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\nM 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2969 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \nQ 2906 2416 2648 2759 \nQ 2391 3103 1925 3103 \nQ 1463 3103 1205 2759 \nQ 947 2416 947 1791 \nQ 947 1169 1205 825 \nQ 1463 481 1925 481 \nQ 2391 481 2648 825 \nQ 2906 1169 2906 1791 \nz\nM 3481 434 \nQ 3481 -459 3084 -895 \nQ 2688 -1331 1869 -1331 \nQ 1566 -1331 1297 -1286 \nQ 1028 -1241 775 -1147 \nL 775 -588 \nQ 1028 -725 1275 -790 \nQ 1522 -856 1778 -856 \nQ 2344 -856 2625 -561 \nQ 2906 -266 2906 331 \nL 2906 616 \nQ 2728 306 2450 153 \nQ 2172 0 1784 0 \nQ 1141 0 747 490 \nQ 353 981 353 1791 \nQ 353 2603 747 3093 \nQ 1141 3584 1784 3584 \nQ 2172 3584 2450 3431 \nQ 2728 3278 2906 2969 \nL 2906 3500 \nL 3481 3500 \nL 3481 434 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(0 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(63.476562 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(124.755859 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(165.869141 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-6d\" transform=\"translate(227.148438 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(324.560547 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(386.083984 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(425.292969 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(486.816406 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(527.929688 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(580.029297 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-Oblique-4e\" transform=\"translate(611.816406 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(686.621094 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(718.408203 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(757.421875 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(820.800781 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(881.982422 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-2d\" transform=\"translate(945.361328 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(981.445312 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-6d\" transform=\"translate(1042.96875 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-62\" transform=\"translate(1140.380859 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(1203.857422 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-64\" transform=\"translate(1265.380859 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-64\" transform=\"translate(1328.857422 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(1392.333984 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(1420.117188 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-67\" transform=\"translate(1483.496094 0.015625)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(1546.972656 0.015625)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_20\">\n      <defs>\n       <path id=\"m664b51a0e9\" d=\"M 0 0 \nL -2 0 \n\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"144.289512\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- $\\mathdefault{1.025\\times10^{0}}$ -->\n      <g transform=\"translate(20.878125 148.088731) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-d7\" d=\"M 4488 3438 \nL 3059 2003 \nL 4488 575 \nL 4116 197 \nL 2681 1631 \nL 1247 197 \nL 878 575 \nL 2303 2003 \nL 878 3438 \nL 1247 3816 \nL 2681 2381 \nL 4116 3816 \nL 4488 3438 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(159.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(222.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(305.761719 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(409.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(472.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(537.236328 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_21\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"125.051372\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- $\\mathdefault{1.05\\times10^{0}}$ -->\n      <g transform=\"translate(27.278125 128.850591) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(159.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(242.138672 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(345.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(409.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(473.613281 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_22\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"106.265937\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- $\\mathdefault{1.075\\times10^{0}}$ -->\n      <g transform=\"translate(20.878125 110.065156) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-37\" transform=\"translate(159.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(222.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(305.761719 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(409.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(472.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(537.236328 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_23\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"87.912389\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- $\\mathdefault{1.1\\times10^{0}}$ -->\n      <g transform=\"translate(33.578125 91.711608) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(178.515625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(281.787109 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(345.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(409.990234 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_24\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"69.971315\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- $\\mathdefault{1.125\\times10^{0}}$ -->\n      <g transform=\"translate(20.878125 73.770534) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(159.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(222.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(305.761719 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(409.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(472.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(537.236328 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_6\">\n     <g id=\"line2d_25\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"52.424583\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- $\\mathdefault{1.15\\times10^{0}}$ -->\n      <g transform=\"translate(27.278125 56.223802) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(159.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(242.138672 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(345.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(409.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(473.613281 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_7\">\n     <g id=\"line2d_26\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"35.25523\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- $\\mathdefault{1.175\\times10^{0}}$ -->\n      <g transform=\"translate(20.878125 39.054448) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(95.410156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-37\" transform=\"translate(159.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(222.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(305.761719 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(409.033203 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(472.65625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(537.236328 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_8\">\n     <g id=\"line2d_27\">\n      <g>\n       <use xlink:href=\"#m664b51a0e9\" x=\"84.778125\" y=\"18.447363\" style=\"stroke: #000000; stroke-width: 0.6\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- $\\mathdefault{1.2\\times10^{0}}$ -->\n      <g transform=\"translate(34.178125 22.246582) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(0 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(89.910156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-d7\" transform=\"translate(173.015625 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(276.287109 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(339.910156 0.765625)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(404.490234 39.046875) scale(0.7)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_12\">\n     <!-- loss -->\n     <g transform=\"translate(14.798437 86.157813) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \nL 1178 4863 \nL 1178 0 \nL 603 0 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-6c\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(27.783203 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(88.964844 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(141.064453 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_28\">\n    <path d=\"M 93.655398 13.5 \nL 120.82811 37.846429 \nL 172.821813 80.982062 \nL 219.239217 114.833558 \nL 271.200852 139.5 \n\" clip-path=\"url(#p821a0a48c8)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"m7c5d4c2646\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #1f77b4\"/>\n    </defs>\n    <g clip-path=\"url(#p821a0a48c8)\">\n     <use xlink:href=\"#m7c5d4c2646\" x=\"93.655398\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c5d4c2646\" x=\"120.82811\" y=\"37.846429\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c5d4c2646\" x=\"172.821813\" y=\"80.982062\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c5d4c2646\" x=\"219.239217\" y=\"114.833558\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c5d4c2646\" x=\"271.200852\" y=\"139.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n    </g>\n   </g>\n   <g id=\"line2d_29\">\n    <path d=\"M 93.655398 16.078194 \nL 120.82811 36.221856 \nL 172.821813 73.864646 \nL 219.239217 97.328804 \nL 271.200852 112.864474 \n\" clip-path=\"url(#p821a0a48c8)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n    <defs>\n     <path id=\"mfd4d77cdc6\" d=\"M -3 3 \nL 3 3 \nL 3 -3 \nL -3 -3 \nz\n\" style=\"stroke: #ff7f0e; stroke-linejoin: miter\"/>\n    </defs>\n    <g clip-path=\"url(#p821a0a48c8)\">\n     <use xlink:href=\"#mfd4d77cdc6\" x=\"93.655398\" y=\"16.078194\" style=\"fill: #ff7f0e; stroke: #ff7f0e; stroke-linejoin: miter\"/>\n     <use xlink:href=\"#mfd4d77cdc6\" x=\"120.82811\" y=\"36.221856\" style=\"fill: #ff7f0e; stroke: #ff7f0e; stroke-linejoin: miter\"/>\n     <use xlink:href=\"#mfd4d77cdc6\" x=\"172.821813\" y=\"73.864646\" style=\"fill: #ff7f0e; stroke: #ff7f0e; stroke-linejoin: miter\"/>\n     <use xlink:href=\"#mfd4d77cdc6\" x=\"219.239217\" y=\"97.328804\" style=\"fill: #ff7f0e; stroke: #ff7f0e; stroke-linejoin: miter\"/>\n     <use xlink:href=\"#mfd4d77cdc6\" x=\"271.200852\" y=\"112.864474\" style=\"fill: #ff7f0e; stroke: #ff7f0e; stroke-linejoin: miter\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 84.778125 145.8 \nL 84.778125 7.2 \n\" 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 280.078125 145.8 \nL 280.078125 7.2 \n\" 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 84.778125 145.8 \nL 280.078125 145.8 \n\" 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 84.778125 7.2 \nL 280.078125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"legend_1\">\n    <g id=\"patch_7\">\n     <path d=\"M 191.84375 44.55625 \nL 273.078125 44.55625 \nQ 275.078125 44.55625 275.078125 42.55625 \nL 275.078125 14.2 \nQ 275.078125 12.2 273.078125 12.2 \nL 191.84375 12.2 \nQ 189.84375 12.2 189.84375 14.2 \nL 189.84375 42.55625 \nQ 189.84375 44.55625 191.84375 44.55625 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_30\">\n     <path d=\"M 193.84375 20.298437 \nL 203.84375 20.298437 \nL 213.84375 20.298437 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n     <g>\n      <use xlink:href=\"#m7c5d4c2646\" x=\"203.84375\" y=\"20.298437\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     </g>\n    </g>\n    <g id=\"text_13\">\n     <!-- train -->\n     <g transform=\"translate(221.84375 23.798437) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(80.322266 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(141.601562 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(169.384766 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_31\">\n     <path d=\"M 193.84375 34.976562 \nL 203.84375 34.976562 \nL 213.84375 34.976562 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n     <g>\n      <use xlink:href=\"#mfd4d77cdc6\" x=\"203.84375\" y=\"34.976562\" style=\"fill: #ff7f0e; stroke: #ff7f0e; stroke-linejoin: miter\"/>\n     </g>\n    </g>\n    <g id=\"text_14\">\n     <!-- validation -->\n     <g transform=\"translate(221.84375 38.476562) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-76\" d=\"M 191 3500 \nL 800 3500 \nL 1894 563 \nL 2988 3500 \nL 3597 3500 \nL 2284 0 \nL 1503 0 \nL 191 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-76\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(59.179688 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(120.458984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(148.242188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-64\" transform=\"translate(176.025391 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(239.501953 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(300.78125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(339.990234 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(367.773438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(428.955078 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p821a0a48c8\">\n   <rect x=\"84.778125\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-7 fw=all -->\n",
    "\n",
    "### Reading the Bend\n",
    "\n",
    "The plot has two curves and each tells half the story. The smaller sizes\n",
    "line up roughly on a straight line: on this diet, multiplying parameters\n",
    "by three buys a similar-looking improvement each time, which is the\n",
    "power-law regime that makes scaling predictable. The largest model\n",
    "departs from it. Its validation loss improves on the next-largest by\n",
    "visibly less than the trend predicts, while its *training* loss keeps\n",
    "falling right on schedule — the gap between the two curves grows from\n",
    "roughly nothing at the small end to several hundredths of a nat at the\n",
    "largest. Nothing is wrong with the model; something is wrong with its diet.\n",
    "Fourteen million parameters reading five million characters three times\n",
    "over have started spending capacity on the corpus itself rather than on\n",
    "English, the same failure mode that section produced on purpose,\n",
    "caught here at its onset.\n",
    "\n",
    "The Chinchilla ratio says this bend is exactly where it should be.\n",
    "Twenty tokens per parameter puts the largest model a corpus this size can\n",
    "feed at roughly $5.1\\textrm{M}/20 \\approx 0.26$M parameters — our\n",
    "*smallest* size. Everything to its right is data-starved by\n",
    "compute-optimal standards and survives on repetition, which is known to\n",
    "be a serviceable substitute at small multiplicities and a rapidly\n",
    "decaying one beyond a handful of passes\n",
    "[@Muennighoff.Rush.Barak.ea.2023]; three passes is mild, which is\n",
    "why our mid-sized models still track the line and only the largest has\n",
    "visibly hit the wall. That is the Chinchilla lesson in miniature: *data\n",
    "must scale with parameters*, and a budget spent on width and depth alone\n",
    "buys memorization, not language. We decline to fit an exponent to our\n",
    "five points: one seed and a forty-fold range would dress noise in\n",
    "decimals; the published fits span six orders of magnitude and entire\n",
    "model families [@kaplan2020scaling; @hoffmann2022training]. What our\n",
    "miniature shows is the *shape* those fits live on: the straight stretch\n",
    "where scaling laws are trustworthy, and the departure that marks the edge\n",
    "of their jurisdiction.\n",
    "\n",
    "Two footnotes before trusting the plot. First, a scaling study is only as\n",
    "good as the tuning of each point: had we frozen the learning rate across\n",
    "widths, part of our \"bend\" would have been a tuning artifact\n",
    "(that section; exercise 5 has you produce this artifact\n",
    "deliberately). Second, loss is the quantity that scales smoothly;\n",
    "downstream abilities can surface abruptly as loss creeps down, which is\n",
    "why small differences on this axis are worth more than they look\n",
    "[@wei2022emergent].\n",
    "\n",
    "### The Published Form of the Law\n",
    "\n",
    "Our miniature moved $N$ with $D$ pinned; the published fits treat both as\n",
    "free variables. Across more than four hundred training runs,\n",
    "@hoffmann2022training fit the loss surface\n",
    "\n",
    "$$\n",
    "L(N, D) = E + \\frac{A}{N^{\\alpha}} + \\frac{B}{D^{\\beta}},\n",
    "$$\n",
    "\n",
    "three terms with three different jobs. $E$ is the floor: the intrinsic\n",
    "entropy of text, the loss that would remain with unlimited parameters and\n",
    "unlimited data. Its presence is why raw loss cannot fall along a straight\n",
    "line forever — a log–log plot only looks straight far above the floor, or\n",
    "after a fitted $E$ has been subtracted; every raw-loss line must\n",
    "eventually flatten into it. The term $A/N^{\\alpha}$ is the capacity price of\n",
    "approximating the true distribution with only $N$ parameters; it is the\n",
    "term our five-point sweep traversed. The term $B/D^{\\beta}$ is the\n",
    "estimation price of seeing only $D$ tokens, and it is what bent our\n",
    "largest model away from the line: with $D$ fixed, $E + B/D^{\\beta}$ acts\n",
    "as an effective floor that no added capacity can pierce.\n",
    "\n",
    "Compute-optimal allocation drops out of the equation with\n",
    "one constraint. Fix a budget $C \\approx 6ND$, substitute $D = C/6N$, and\n",
    "set the derivative in $N$ to zero: the optimum satisfies\n",
    "\n",
    "$$\n",
    "\\alpha \\frac{A}{N^{\\alpha}} = \\beta \\frac{B}{D^{\\beta}},\n",
    "$$\n",
    "\n",
    "i.e., spend until the two shrinkable terms are shrinking at equal\n",
    "marginal rates. Solving gives $N^* \\propto C^{\\beta/(\\alpha+\\beta)}$ and\n",
    "$D^* \\propto C^{\\alpha/(\\alpha+\\beta)}$. The fitted exponents come out\n",
    "nearly equal ($\\alpha \\approx 0.34$, $\\beta \\approx 0.28$), so both\n",
    "optima scale close to $C^{1/2}$: parameters and tokens should grow in\n",
    "near-lockstep, and their ratio at the optimum is roughly constant — the\n",
    "twenty tokens per parameter quoted above is that constant, evaluated at\n",
    "the fit. We do not fit $E$, $\\alpha$, $\\beta$ to our own five points (the\n",
    "previous subsection said why); what the miniature contributes is the\n",
    "shape of both terms — the straight stretch is $A/N^{\\alpha}$ falling\n",
    "while the data term is negligible, and the bend is the crossover where\n",
    "the fixed corpus's $B/D^{\\beta}$ takes over.\n",
    "\n",
    "## The Modern Recipe\n",
    "\n",
    "If scale is what matters, what exactly do the trillion-token runs build?\n",
    "The reports read like a single answer arrived at independently.\n",
    "the table compiles the architecture sections of seven\n",
    "open-weights families — Mistral 7B\n",
    "[@Jiang.Sablayrolles.Mensch.ea.2023], Llama 3\n",
    "[@Grattafiori.Dubey.Jauhri.ea.2024], Qwen3\n",
    "[@Yang.Li.Yang.ea.2025], OLMo 2 and 3 [@OLMo.2025; @OLMo3.2025],\n",
    "DeepSeek-V3 [@Liu.Feng.Xue.ea.2024], Gemma 3\n",
    "[@Gemma.Team.2025], and GPT-OSS [@OpenAI.2025] — onto the axes\n",
    "this chapter built.\n",
    "\n",
    "### Convergent Evolution\n",
    "\n",
    "<!-- tbl-caption:The 2023–2025 open-weights recipe, one row per model family. Attention and cache column: that section. Normalization: that section. Positions: that section. Mixture of experts: that section. -->\n",
    "\n",
    "| model | attention and cache | normalization | positions | FFN | dense or MoE | dropout |\n",
    "|:--|:--|:--|:--|:--|:--|:--|\n",
    "| Mistral 7B (2023) | GQA $32{:}8$; sliding window 4096 | RMSNorm, pre | RoPE, $\\theta = 10^4$ | SwiGLU | dense | none |\n",
    "| Llama 3 (2024) | GQA $32{:}8$ | RMSNorm, pre | RoPE, $\\theta = 5 \\times 10^5$ | SwiGLU | dense | none |\n",
    "| Qwen3 (2025) | GQA: $64{:}8$ dense (32B), $64{:}4$ MoE (235B-A22B) | RMSNorm, pre; QK-norm | RoPE, $\\theta = 10^6$; YaRN for long context | SwiGLU | dense, and MoE: 128 experts, 8 active | none |\n",
    "| OLMo 2/3 (2024/25) | MHA (7B), GQA (32B); OLMo 3: window 4096 on 3 of 4 layers | RMSNorm, post but off-stream; QK-norm | RoPE | SwiGLU | dense | none |\n",
    "| DeepSeek-V3 (2024) | MLA: KV compressed to a 512-dim latent | RMSNorm, pre | RoPE on a decoupled 64-dim slice per head | SwiGLU | MoE: 256 experts plus 1 shared, 8 active | none |\n",
    "| Gemma 3 (2025) | GQA; local:global $5{:}1$, window 1024 | RMSNorm, pre and post; QK-norm | RoPE, $\\theta = 10^6$ global, $10^4$ local | GeGLU | dense | none |\n",
    "| GPT-OSS (2025) | GQA $64{:}8$; window 128 on alternate layers; learned sinks | RMSNorm, pre | RoPE; YaRN | SwiGLU, clamped | MoE: 128 or 32 experts, 4 active | none |\n",
    "\n",
    "Read down the columns and the convergence is hard to miss. Every row is\n",
    "the block of that section in the causal wiring of\n",
    "that section; nothing here is a new architecture in the sense that\n",
    "the transformer was new against the LSTM. The differences cluster on\n",
    "exactly three axes. *Stability*: where the norms sit and what they\n",
    "normalize, with pre-norm almost everywhere, RMSNorm everywhere, QK-norm\n",
    "spreading through the 2025 column (OLMo's post-but-off-stream placement\n",
    "is the one live dissent, and it concedes the residual stream's identity\n",
    "path, the actual lesson of our signal-propagation experiment). *The\n",
    "cache*: GQA as the default, with the window-plus-sink and latent\n",
    "compressions of that section where long contexts make the\n",
    "cache the binding cost. *Capacity per FLOP*: gated FFNs in every row, and\n",
    "mixture of experts (that section) where the budget wants more\n",
    "parameters than FLOPs. The dropout column is the quiet punchline of our\n",
    "scaling study: at trillion-token scale the corpus outweighs the\n",
    "parameters, overfitting is not the failure mode, and the regularizer we\n",
    "still needed in that section has simply left the recipe. Even the\n",
    "positions column is one idea at different dial settings: RoPE with an\n",
    "inflated base for longer contexts, stretched further by interpolation\n",
    "schemes (that section); the newest twist —\n",
    "dropping positions entirely on some layers, as Llama 4's NoPE-interleaved\n",
    "long-context layers do — is still a setting of the same dial.\n",
    "\n",
    "### Recipe Rows as Constructor Calls\n",
    "\n",
    "that section promised that these rows would come back as argument\n",
    "lists, and the debt is now due. Scaled to our size — width 256, six\n",
    "blocks — here are four rows of the table as configurations of `d2l.GPT`,\n",
    "with grouped-query attention dropped in through the same seam\n",
    "that section built:"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "scaling-laws-recipe-rows-as-constructor-calls"
   },
   "source": [
    "recipes = {\n",
    "    'GPT-2 (2019)': dict(pos='learned', norm='layer', act='gelu',\n",
    "                         pre_norm=True, bias=True, kv_heads=8),\n",
    "    'Mistral-7B':   dict(pos='rope', norm='rms', act='swiglu',\n",
    "                         pre_norm=True, bias=False, kv_heads=2),\n",
    "    'Llama-3':      dict(pos='rope', norm='rms', act='swiglu',\n",
    "                         pre_norm=True, bias=False, kv_heads=2),\n",
    "    'Qwen3':        dict(pos='rope', norm='rms', act='swiglu',\n",
    "                         pre_norm=True, bias=False, kv_heads=2),\n",
    "}\n",
    "for name, cfg in recipes.items():\n",
    "    kv_heads = cfg.pop('kv_heads')\n",
    "    model = d2l.GPT(vocab_size=1024, num_hiddens=256, num_heads=8,\n",
    "                    num_blks=6, **cfg)\n",
    "    if kv_heads < 8:            # grouped-query attention, as deployed\n",
    "        for blk in model.blks:\n",
    "            blk.attention = d2l.GQAAttention(\n",
    "                256, 8, kv_heads, rope=(cfg['pos'] == 'rope'))\n",
    "    d2l.check_shape(model(torch.zeros(2, 16, dtype=torch.long)),\n",
    "                    (2, 16, 1024))\n",
    "    print(f'{name:12s} {count(model) / 1e6:.2f}M  '\n",
    "          + ', '.join(f'{k}={v!r}' for k, v in cfg.items())\n",
    "          + f', kv_heads={kv_heads}')"
   ],
   "execution_count": 7,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "GPT-2 (2019) 5.26M  pos='learned', norm='layer', act='gelu', pre_norm=True, bias=True, kv_heads=8\nMistral-7B   4.40M  pos='rope', norm='rms', act='swiglu', pre_norm=True, bias=False, kv_heads=2\nLlama-3      4.40M  pos='rope', norm='rms', act='swiglu', pre_norm=True, bias=False, kv_heads=2\nQwen3        4.40M  pos='rope', norm='rms', act='swiglu', pre_norm=True, bias=False, kv_heads=2\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=scaling-laws-md-8 fw=all -->\n",
    "\n",
    "The printout is the point: the three modern rows are the *same argument\n",
    "list*. At the resolution of our constructor, the field has one recipe,\n",
    "and what distinguishes deployed families lives in the columns the flags\n",
    "do not reach: window widths, RoPE bases, expert counts, and the\n",
    "normalization refinements we left as exercises (QK-norm slots in through\n",
    "`attn_factory`, as in that section's exercises). The\n",
    "two rows we did not instantiate are the two seams working as designed:\n",
    "DeepSeek's MLA is the low-rank cache compression whose miniature\n",
    "that section trained, and every MoE cell in the table swaps the\n",
    "FFN through `ffn_factory` for the expert layer of that section.\n",
    "Convergent evolution is the biologist's name for this: independent\n",
    "lineages under the same selection pressure arriving at the same body\n",
    "plan. The selection pressures here are three bills — training stability,\n",
    "decode-time memory, capacity per FLOP — and every 2026 deployment is\n",
    "recognizably the 2017 transformer with engineering applied to exactly\n",
    "those three lines of the budget.\n",
    "\n",
    "## Where the Field Is Moving\n",
    "\n",
    "Three directions are worth pointers as this chapter closes. First, the\n",
    "attention layer's quadratic cost (that section) is\n",
    "increasingly rationed rather than paid: the sliding-window rows of\n",
    "the table are the mild form, and the stronger form\n",
    "replaces most attention layers outright with the linear-time recurrent\n",
    "mixers of that section, keeping full attention in only a\n",
    "fraction of layers. These hybrids bet that exact global lookup is worth\n",
    "its price only a few times per stack; where that bet pays, and where it\n",
    "fails, is that chapter's story. Second, long context has become an\n",
    "engineering discipline of its own: the number in a model card is a\n",
    "compound of RoPE base inflation and interpolation\n",
    "(that section), window-and-sink cache policies\n",
    "(that section), and the systems work of\n",
    "that section — none of it a new body plan; the\n",
    "architectural moves are settings of the attention layer this chapter\n",
    "already built, and the rest is positional bookkeeping and systems work.\n",
    "Third, everything this chapter held fixed — what to train *on*, and what\n",
    "happens after the loss stops falling — is where the gains have moved:\n",
    "data curation, instruction tuning, and learning from feedback are the\n",
    "subject of the Language Models part, beginning in\n",
    "that section.\n",
    "\n",
    "## Summary\n",
    "\n",
    "Transformer training cost is two multiplications: non-embedding\n",
    "parameters ($N \\approx 12Ld^2$; embeddings are tokenizer bookkeeping and\n",
    "are counted separately) times tokens, times six — two FLOPs per parameter\n",
    "per token forward, four backward, the equation — with corrections\n",
    "(attention scores, $n/6d$) that stay subleading until contexts reach\n",
    "thousands. A profiler and XLA's cost analysis both confirm the rule on\n",
    "our GPT to within a few percent. On a fixed diet of tokens, loss falls\n",
    "with model size along a rough power law until the corpus can no longer\n",
    "feed the model, then bends away: our five-size study on 5.1M characters\n",
    "shows the straight stretch, the departure of the largest model, and the\n",
    "widening train–validation gap that explains it. The published account of\n",
    "that shape is $L(N,D) = E + A N^{-\\alpha} + B D^{-\\beta}$ — an entropy\n",
    "floor, a capacity term, a data term — whose compute-optimal allocation\n",
    "under $C \\approx 6ND$ grows parameters and tokens together, at about\n",
    "twenty tokens per parameter (the Chinchilla ratio); its lesson is that\n",
    "data must scale with parameters.\n",
    "What the scaled-up runs build has converged: GQA or latent-compressed\n",
    "attention over a pre-norm RMSNorm block with a gated FFN, RoPE positions,\n",
    "no dropout, and mixture of experts where parameters should outnumber\n",
    "FLOPs; our recipe table's modern rows collapse to a single argument list\n",
    "of the `GPT` class, differing in dial settings rather than design. The\n",
    "2017 block, plus stability, cache, and capacity engineering, is the 2026\n",
    "frontier.\n",
    "\n",
    "## Exercises\n",
    "\n",
    "1. Derive the six in the equation for our default configuration\n",
    "   exactly. Write the per-block matmul parameter count for width 256\n",
    "   (fused QKV, output projection, and the three SwiGLU matrices), add the\n",
    "   tied head, and multiply out $6ND$ for one batch. Compare against the\n",
    "   profiler cell's analytic line. Then add the attention-score term: at\n",
    "   what context length $n$ would the score work equal the linear-layer\n",
    "   work for this width?\n",
    "2. Run the Chinchilla sanity check on our study. At twenty tokens per\n",
    "   parameter, how many tokens would each of our five sizes want, and how\n",
    "   many *unique* characters does our corpus provide? Which sizes exceed\n",
    "   the ratio, and how does that align with where the measured curve\n",
    "   bends? Our budget shows each character about three times; using the\n",
    "   findings of @Muennighoff.Rush.Barak.ea.2023, argue whether\n",
    "   doubling the number of passes would rescue the largest model.\n",
    "3. Add a row to the table. Pick an open-weights model\n",
    "   this section does not cover — Kimi K2 [@Kimi.Team.2025] is a good\n",
    "   subject — read the architecture section of its report, and fill in\n",
    "   every column. Which cells map onto `d2l.GPT` constructor flags, which\n",
    "   need the `attn_factory`/`ffn_factory` seams, and which would need\n",
    "   machinery this chapter has not built?\n",
    "4. The census showed GPT-2's embedding at roughly a third of its\n",
    "   parameters. Derive the condition on $V$, $d$, and $L$ under which the\n",
    "   embedding holds at least half of all parameters, and check it against\n",
    "   GPT-2's numbers. Why do scaling-law fits improve when embedding\n",
    "   parameters are excluded from $N$?\n",
    "5. Rerun the sweep with the learning rate frozen at $10^{-3}$ for every\n",
    "   size. Which points move, and in which direction? Explain each\n",
    "   movement using the width-dependence of the tuned optimum from\n",
    "   that section, and state what a naive reader of the resulting\n",
    "   plot would conclude that the properly tuned plot does not support.\n",
    "6. Extend the sweep one size upward: width 512, ten blocks, about 31M\n",
    "   non-embedding parameters. Before running it, predict its validation\n",
    "   loss twice — once by extending the straight line through the small\n",
    "   sizes, once by assuming the corpus is fully saturated (no improvement\n",
    "   over the largest measured size) — and estimate the run's cost in\n",
    "   FLOPs via the equation. Then run it. Which prediction was\n",
    "   closer, and what does the answer say about how much headroom three\n",
    "   passes over 5.1M characters leave?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-pytorch",
   "display_name": "d2l (PyTorch)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
