{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-1 fw=all -->\n",
    "\n",
    "# Hyperparameter Optimization API\n",
    "\n",
    "Before we dive into the methodology, we will first discuss a basic code\n",
    "structure that allows us to efficiently implement various HPO algorithms. In\n",
    "general, all HPO algorithms considered here need to implement two decision\n",
    "making primitives, *searching* and *scheduling*. First, they need to sample new\n",
    "hyperparameter configurations, which often involves some kind of search over the\n",
    "configuration space. Second, for each configuration, an HPO algorithm needs to\n",
    "schedule its evaluation and decide how many resources to allocate for it. Once\n",
    "we start to evaluate a configuration, we will refer to it as a *trial*. We map\n",
    "these decisions to two classes, `HPOSearcher` and `HPOScheduler`. On top of that,\n",
    "we also provide a `HPOTuner` class that executes the optimization process.\n",
    "\n",
    "This concept of scheduler and searcher is also implemented in popular HPO\n",
    "libraries, such as Syne Tune [@salinas-automl22], Ray Tune\n",
    "[@liaw-arxiv18] or Optuna [@akiba-sigkdd19]."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-hyperparameter-optimization-api"
   },
   "source": [
    "import time\n",
    "from d2l import jax as d2l\n",
    "import numpy as np\n",
    "from scipy import stats"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-2 fw=all -->\n",
    "\n",
    "## Searcher\n",
    "\n",
    "Below we define a base class for searchers, which provides a new candidate\n",
    "configuration through the `sample_configuration` function. A simple way to\n",
    "implement this function would be to sample configurations uniformly at random,\n",
    "as we did for random search in that section. More sophisticated\n",
    "algorithms, such as Bayesian optimization, will make these\n",
    "decisions based on the performance of previous trials. As a result, these\n",
    "algorithms are able to sample more promising candidates over time. We add the\n",
    "`update` function in order to update the history of previous trials, which can\n",
    "then be exploited to improve our sampling distribution."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-searcher-1"
   },
   "source": [
    "class HPOSearcher(d2l.HyperParameters):\n",
    "    def sample_configuration(self) -> dict:\n",
    "        raise NotImplementedError\n",
    "\n",
    "    def update(self, config: dict, error: float, additional_info=None):\n",
    "        pass"
   ],
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-3 fw=all -->\n",
    "\n",
    "The following code shows how to implement our random search optimizer from the\n",
    "previous section in this API. As a slight extension, we allow the user to\n",
    "prescribe the first configuration to be evaluated via `initial_config`, while\n",
    "subsequent ones are drawn at random."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-searcher-2"
   },
   "source": [
    "class RandomSearcher(HPOSearcher):\n",
    "    def __init__(self, config_space: dict, initial_config=None):\n",
    "        self.save_hyperparameters()\n",
    "\n",
    "    def sample_configuration(self) -> dict:\n",
    "        if self.initial_config is not None:\n",
    "            result = self.initial_config\n",
    "            self.initial_config = None\n",
    "        else:\n",
    "            result = {\n",
    "                name: domain.rvs()\n",
    "                for name, domain in self.config_space.items()\n",
    "            }\n",
    "        return result"
   ],
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-4 fw=all -->\n",
    "\n",
    "## Scheduler\n",
    "\n",
    "Beyond sampling configurations for new trials, we also need to decide when and\n",
    "for how long to run a trial. In practice, all these decisions are done by the\n",
    "`HPOScheduler`, which delegates the choice of new configurations to a\n",
    "`HPOSearcher`. The `suggest` method is called whenever some resource for training\n",
    "becomes available. Apart from invoking `sample_configuration` of a searcher, it\n",
    "may also decide upon parameters like `max_epochs` (i.e., how long to train the\n",
    "model for). The `update` method is called whenever a trial returns a new\n",
    "observation."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-scheduler-1"
   },
   "source": [
    "class HPOScheduler(d2l.HyperParameters):\n",
    "    def suggest(self) -> dict:\n",
    "        raise NotImplementedError\n",
    "    \n",
    "    def update(self, config: dict, error: float, info=None):\n",
    "        raise NotImplementedError"
   ],
   "execution_count": 4,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-5 fw=all -->\n",
    "\n",
    "To implement random search, but also other HPO algorithms, we only need a basic\n",
    "scheduler that schedules a new configuration every time new resources become\n",
    "available."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-scheduler-2"
   },
   "source": [
    "class BasicScheduler(HPOScheduler):\n",
    "    def __init__(self, searcher: HPOSearcher):\n",
    "        self.save_hyperparameters()\n",
    "\n",
    "    def suggest(self) -> dict:\n",
    "        return self.searcher.sample_configuration()\n",
    "\n",
    "    def update(self, config: dict, error: float, info=None):\n",
    "        self.searcher.update(config, error, additional_info=info)"
   ],
   "execution_count": 5,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-6 fw=all -->\n",
    "\n",
    "## Tuner\n",
    "\n",
    "Finally, we need a component that runs the scheduler/searcher and does some\n",
    "book-keeping of the results. The following code implements a sequential\n",
    "execution of the HPO trials that evaluates one training job after the next and\n",
    "will serve as a basic example. We will later use *Syne Tune* for more scalable\n",
    "distributed HPO cases."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-tuner"
   },
   "source": [
    "class HPOTuner(d2l.HyperParameters):\n",
    "    def __init__(self, scheduler: HPOScheduler, objective: callable):\n",
    "        self.save_hyperparameters()\n",
    "        # Bookkeeping results for plotting\n",
    "        self.incumbent = None\n",
    "        self.incumbent_error = None\n",
    "        self.incumbent_trajectory = []\n",
    "        self.cumulative_runtime = []\n",
    "        self.current_runtime = 0\n",
    "        self.records = []\n",
    "\n",
    "    def run(self, number_of_trials):\n",
    "        for i in range(number_of_trials):\n",
    "            start_time = time.time()\n",
    "            config = self.scheduler.suggest()\n",
    "            print(f\"Trial {i}: config = {config}\")\n",
    "            error = self.objective(**config)\n",
    "            # Each objective creates a training figure. HPO can evaluate many\n",
    "            # configurations, so release completed figures between trials.\n",
    "            d2l.plt.close('all')\n",
    "            error = float(error)\n",
    "            self.scheduler.update(config, error)\n",
    "            runtime = time.time() - start_time\n",
    "            self.bookkeeping(config, error, runtime)\n",
    "            print(f\"    error = {error}, runtime = {runtime}\")"
   ],
   "execution_count": 6,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-7 fw=all -->\n",
    "\n",
    "## Bookkeeping the Performance of HPO Algorithms\n",
    "\n",
    "With any HPO algorithm, we are mostly interested in the best performing\n",
    "configuration (called *incumbent*) and its validation error after a given \n",
    "wall-clock time. This is why we track `runtime` per iteration, which includes\n",
    "both the time to run an evaluation (call of `objective`) and the time to\n",
    "make a decision (call of `scheduler.suggest`). In the sequel, we will plot\n",
    "`cumulative_runtime` against `incumbent_trajectory` in  order to visualize the\n",
    "*any-time performance* of the HPO algorithm defined in  terms of `scheduler`\n",
    "(and `searcher`). This allows us to quantify not only how well the configuration\n",
    "found by an optimizer works, but also how quickly an optimizer is able to find it."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-bookkeeping-the-performance-of-hpo-algorithms"
   },
   "source": [
    "@d2l.add_to_class(HPOTuner)\n",
    "def bookkeeping(self, config: dict, error: float, runtime: float):\n",
    "    self.records.append({\"config\": config, \"error\": error, \"runtime\": runtime})\n",
    "    # Check if the last hyperparameter configuration performs better \n",
    "    # than the incumbent\n",
    "    if self.incumbent is None or self.incumbent_error > error:\n",
    "        self.incumbent = config\n",
    "        self.incumbent_error = error\n",
    "    # Add current best observed performance to the optimization trajectory\n",
    "    self.incumbent_trajectory.append(self.incumbent_error)\n",
    "    # Update runtime\n",
    "    self.current_runtime += runtime\n",
    "    self.cumulative_runtime.append(self.current_runtime)"
   ],
   "execution_count": 7,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-8 fw=all -->\n",
    "\n",
    "## Example: Optimizing the Hyperparameters of a Convolutional Neural Network\n",
    "\n",
    "We now use our new implementation of random search to optimize the\n",
    "*batch size* and *learning rate* of the `LeNet` convolutional neural network\n",
    "from that section. We begin by defining the objective function, which\n",
    "will once more be validation error."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-example-optimizing-the-hyperparameters-of-a-convolutional-neural-network-1"
   },
   "source": [
    "def hpo_objective_lenet(learning_rate, batch_size, max_epochs=10):\n",
    "    model = d2l.LeNet(lr=learning_rate, num_classes=10)\n",
    "    trainer = d2l.HPOTrainer(max_epochs=max_epochs, num_gpus=1)\n",
    "    data = d2l.FashionMNIST(batch_size=batch_size)\n",
    "    trainer.fit(model=model, data=data)\n",
    "    validation_error = trainer.validation_error()\n",
    "    return validation_error"
   ],
   "execution_count": 8,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-9 fw=all -->\n",
    "\n",
    "We also need to define the configuration space. Moreover, the first configuration\n",
    "to be evaluated is the default setting used in that section."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-example-optimizing-the-hyperparameters-of-a-convolutional-neural-network-2"
   },
   "source": [
    "config_space = {\n",
    "    \"learning_rate\": stats.loguniform(1e-2, 1),\n",
    "    \"batch_size\": stats.randint(32, 256),\n",
    "}\n",
    "initial_config = {\n",
    "    \"learning_rate\": 0.1,\n",
    "    \"batch_size\": 128,\n",
    "}"
   ],
   "execution_count": 9,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-10 fw=all -->\n",
    "\n",
    "Now we can start our random search:"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-example-optimizing-the-hyperparameters-of-a-convolutional-neural-network-3"
   },
   "source": [
    "searcher = RandomSearcher(config_space, initial_config=initial_config)\n",
    "scheduler = BasicScheduler(searcher=searcher)\n",
    "tuner = HPOTuner(scheduler=scheduler, objective=hpo_objective_lenet)\n",
    "tuner.run(number_of_trials=5)"
   ],
   "execution_count": 10,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "    error = 0.3433000445365906, runtime = 13.18621277809143\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-11 fw=all -->\n",
    "\n",
    "Below we plot the optimization trajectory of the incumbent to get the any-time\n",
    "performance of random search:"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "hyperopt-api-example-optimizing-the-hyperparameters-of-a-convolutional-neural-network-4"
   },
   "source": [
    "board = d2l.ProgressBoard(xlabel=\"time\", ylabel=\"error\")\n",
    "for time_stamp, error in zip(\n",
    "    tuner.cumulative_runtime, tuner.incumbent_trajectory\n",
    "):\n",
    "    board.draw(time_stamp, error, \"random search\", every_n=1)\n",
    "board.flush()  # drawing is asynchronous; render the final trajectory"
   ],
   "execution_count": 11,
   "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=\"258.607932pt\" height=\"183.35625pt\" viewBox=\"0 0 258.607932 183.35625\" 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:33:20.864517</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.35625 \nL 258.607932 183.35625 \nL 258.607932 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 50.14375 145.8 \nL 245.44375 145.8 \nL 245.44375 7.2 \nL 50.14375 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      <defs>\n       <path id=\"m8323955dce\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m8323955dce\" x=\"50.562753\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 20 -->\n      <g transform=\"translate(44.200253 160.398438) scale(0.1 -0.1)\">\n       <defs>\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-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       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_2\">\n      <g>\n       <use xlink:href=\"#m8323955dce\" x=\"98.38811\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 40 -->\n      <g transform=\"translate(92.02561 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_3\">\n      <g>\n       <use xlink:href=\"#m8323955dce\" x=\"146.213467\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 60 -->\n      <g transform=\"translate(139.850967 160.398438) scale(0.1 -0.1)\">\n       <defs>\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-36\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m8323955dce\" x=\"194.038824\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 80 -->\n      <g transform=\"translate(187.676324 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-38\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_5\">\n      <g>\n       <use xlink:href=\"#m8323955dce\" x=\"241.864182\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 100 -->\n      <g transform=\"translate(232.320432 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       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- time -->\n     <g transform=\"translate(136.497656 174.076563) scale(0.1 -0.1)\">\n      <defs>\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-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-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      </defs>\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6d\" transform=\"translate(66.992188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(164.404297 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_6\">\n      <defs>\n       <path id=\"m96e2ee9f71\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m96e2ee9f71\" x=\"50.14375\" y=\"129.233309\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0.18 -->\n      <g transform=\"translate(20.878125 133.032527) 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       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(95.410156 0)\"/>\n       <use xlink:href=\"#DejaVuSans-38\" transform=\"translate(159.033203 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_7\">\n      <g>\n       <use xlink:href=\"#m96e2ee9f71\" x=\"50.14375\" y=\"102.566644\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0.20 -->\n      <g transform=\"translate(20.878125 106.365862) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(159.033203 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m96e2ee9f71\" x=\"50.14375\" y=\"75.899978\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 0.22 -->\n      <g transform=\"translate(20.878125 79.699197) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(159.033203 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_9\">\n      <g>\n       <use xlink:href=\"#m96e2ee9f71\" x=\"50.14375\" y=\"49.233313\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 0.24 -->\n      <g transform=\"translate(20.878125 53.032532) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n       <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(159.033203 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m96e2ee9f71\" x=\"50.14375\" y=\"22.566648\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 0.26 -->\n      <g transform=\"translate(20.878125 26.365867) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n       <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(159.033203 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_12\">\n     <!-- error -->\n     <g transform=\"translate(14.798437 88.602344) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\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-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      </defs>\n      <use xlink:href=\"#DejaVuSans-65\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(61.523438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(100.886719 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(139.75 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(200.931641 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_11\">\n    <path d=\"M 59.021023 13.5 \nL 99.806348 139.5 \nL 167.000465 139.5 \nL 205.03471 139.5 \nL 236.566477 139.5 \n\" clip-path=\"url(#p1a0b655961)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 50.14375 145.8 \nL 50.14375 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 245.44375 145.8 \nL 245.44375 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 50.14375 145.8 \nL 245.44375 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 50.14375 7.2 \nL 245.44375 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 131.26875 29.878125 \nL 238.44375 29.878125 \nQ 240.44375 29.878125 240.44375 27.878125 \nL 240.44375 14.2 \nQ 240.44375 12.2 238.44375 12.2 \nL 131.26875 12.2 \nQ 129.26875 12.2 129.26875 14.2 \nL 129.26875 27.878125 \nQ 129.26875 29.878125 131.26875 29.878125 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_12\">\n     <path d=\"M 133.26875 20.298438 \nL 143.26875 20.298438 \nL 153.26875 20.298438 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_13\">\n     <!-- random search -->\n     <g transform=\"translate(161.26875 23.798438) scale(0.1 -0.1)\">\n      <defs>\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-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-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-20\" 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-63\" d=\"M 3122 3366 \nL 3122 2828 \nQ 2878 2963 2633 3030 \nQ 2388 3097 2138 3097 \nQ 1578 3097 1268 2742 \nQ 959 2388 959 1747 \nQ 959 1106 1268 751 \nQ 1578 397 2138 397 \nQ 2388 397 2633 464 \nQ 2878 531 3122 666 \nL 3122 134 \nQ 2881 22 2623 -34 \nQ 2366 -91 2075 -91 \nQ 1284 -91 818 406 \nQ 353 903 353 1747 \nQ 353 2603 823 3093 \nQ 1294 3584 2113 3584 \nQ 2378 3584 2631 3529 \nQ 2884 3475 3122 3366 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-68\" 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 4863 \nL 1159 4863 \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      </defs>\n      <use xlink:href=\"#DejaVuSans-72\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(41.113281 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(102.392578 0)\"/>\n      <use xlink:href=\"#DejaVuSans-64\" transform=\"translate(165.771484 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(229.248047 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6d\" transform=\"translate(290.429688 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(387.841797 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(419.628906 0)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(471.728516 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(533.251953 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(594.53125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(633.394531 0)\"/>\n      <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(688.375 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p1a0b655961\">\n   <rect x=\"50.14375\" 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=hyperopt-api-md-12 fw=all -->\n",
    "\n",
    "## Comparing HPO Algorithms\n",
    "\n",
    "Just as with training algorithms or model architectures, it is important to\n",
    "understand how to best compare different HPO algorithms. Each HPO run depends\n",
    "on two major sources of randomness: the random effects of the training process,\n",
    "such as random weight initialization or mini-batch ordering, and the intrinsic\n",
    "randomness of the HPO algorithm itself, such as the random sampling of random\n",
    "search. Hence, when comparing different algorithms, it is crucial to run each\n",
    "experiment several times and report statistics, such as mean or median, across\n",
    "a population of multiple repetitions of an algorithm based on different seeds\n",
    "of the random number generator.\n",
    "\n",
    "To illustrate this, we compare random search (see that section) and Bayesian\n",
    "optimization [@snoek-nips12] on tuning the hyperparameters of a feed-forward\n",
    "neural network. Each algorithm was evaluated\n",
    "$50$ times with a different random seed. The solid line indicates the average\n",
    "performance of the incumbent across these $50$ repetitions and the dashed line\n",
    "the standard deviation. We can see that random search and Bayesian optimization\n",
    "perform roughly the same up to ~1000 seconds, but Bayesian optimization can\n",
    "make use of the past observation to identify better configurations and thus\n",
    "quickly outperforms random search afterwards.\n",
    "\n",
    "\n",
    "![Example any-time performance plot to compare two algorithms A and B.](../img/example_anytime_performance.svg){#example-anytime-performance}\n",
    "\n",
    "## Summary\n",
    "\n",
    "This section laid out a simple, yet flexible interface to implement various HPO\n",
    "algorithms that we will look at in this chapter. Similar interfaces can be found\n",
    "in popular open-source HPO frameworks. We also looked at how we can compare HPO\n",
    "algorithms, and potential pitfalls one needs to be aware of. \n",
    "\n",
    "## Exercises\n",
    "\n",
    "1. The goal of this exercise is to implement the objective function for a slightly more challenging HPO problem, and to run more realistic experiments. We will use the two hidden layer MLP `DropoutMLP` implemented in that section.\n",
    "    1. Code up the objective function, which should depend on all hyperparameters of the model and `batch_size`. Use `max_epochs=50`. GPUs do not help here, so `num_gpus=0`. Hint: Modify `hpo_objective_lenet`.\n",
    "    2. Choose a sensible search space, where `num_hiddens_1`, `num_hiddens_2` are integers in $[8, 1024]$, and dropout values lie in $[0, 0.95]$, while `batch_size` lies in $[16, 384]$. Provide code for `config_space`, using sensible distributions from `scipy.stats`.\n",
    "    3. Run random search on this example with `number_of_trials=20` and plot the results. Make sure to first evaluate the default configuration of that section, which is `initial_config = {'num_hiddens_1': 256, 'num_hiddens_2': 256, 'dropout_1': 0.5, 'dropout_2': 0.5, 'lr': 0.1, 'batch_size': 256}`.\n",
    "2. In this exercise, you will implement a new searcher (subclass of `HPOSearcher`) which makes decisions based on past data. It depends on parameters `probab_local`, `num_init_random`. Its `sample_configuration` method works as follows. For the first `num_init_random` calls, do the same as `RandomSearcher.sample_configuration`. Otherwise, with probability `1 - probab_local`, do the same as `RandomSearcher.sample_configuration`. Otherwise, pick the configuration which attained the smallest validation error so far, select one of its hyperparameters at random, and sample its value randomly like in `RandomSearcher.sample_configuration`, but leave all other values the same. Return this configuration, which is identical to the best configuration so far, except in this one hyperparameter.\n",
    "    1. Code up this new `LocalSearcher`. Hint: Your searcher requires `config_space` as argument at construction. Feel free to use a member of type `RandomSearcher`. You will also have to implement the `update` method.\n",
    "    2. Re-run the experiment from the previous exercise, but using your new searcher instead of `RandomSearcher`. Experiment with different values for `probab_local`, `num_init_random`. However, note that a proper comparison between different HPO methods requires repeating experiments several times, and ideally considering a number of benchmark tasks."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=hyperopt-api-md-13 fw=jax -->\n",
    "\n",
    "[Discussions](https://d2l.discourse.group/t/12092)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-jax",
   "display_name": "d2l (JAX)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
