{ "cells": [ { "cell_type": "markdown", "id": "3333804c", "metadata": { "origin_pos": 1 }, "source": [ "# Implementation of Multilayer Perceptrons\n", ":label:`sec_mlp-implementation`\n", "\n", "Multilayer perceptrons (MLPs) are not much more complex to implement than simple linear models. The key conceptual\n", "difference is that we now concatenate multiple layers.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "87926c3b", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:41:22.340655Z", "iopub.status.busy": "2023-08-18T19:41:22.340381Z", "iopub.status.idle": "2023-08-18T19:41:25.449640Z", "shell.execute_reply": "2023-08-18T19:41:25.448607Z" }, "origin_pos": 3, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "import torch\n", "from torch import nn\n", "from d2l import torch as d2l" ] }, { "cell_type": "markdown", "id": "1f2763e5", "metadata": { "origin_pos": 6 }, "source": [ "## Implementation from Scratch\n", "\n", "Let's begin again by implementing such a network from scratch.\n", "\n", "### Initializing Model Parameters\n", "\n", "Recall that Fashion-MNIST contains 10 classes,\n", "and that each image consists of a $28 \\times 28 = 784$\n", "grid of grayscale pixel values.\n", "As before we will disregard the spatial structure\n", "among the pixels for now,\n", "so we can think of this as a classification dataset\n", "with 784 input features and 10 classes.\n", "To begin, we will [**implement an MLP\n", "with one hidden layer and 256 hidden units.**]\n", "Both the number of layers and their width are adjustable\n", "(they are considered hyperparameters).\n", "Typically, we choose the layer widths to be divisible by larger powers of 2.\n", "This is computationally efficient due to the way\n", "memory is allocated and addressed in hardware.\n", "\n", "Again, we will represent our parameters with several tensors.\n", "Note that *for every layer*, we must keep track of\n", "one weight matrix and one bias vector.\n", "As always, we allocate memory\n", "for the gradients of the loss with respect to these parameters.\n" ] }, { "cell_type": "markdown", "id": "08aa4fb7", "metadata": { "origin_pos": 8, "tab": [ "pytorch" ] }, "source": [ "In the code below we use `nn.Parameter`\n", "to automatically register\n", "a class attribute as a parameter to be tracked by `autograd` (:numref:`sec_autograd`).\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "bcccd30d", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:41:25.459844Z", "iopub.status.busy": "2023-08-18T19:41:25.459149Z", "iopub.status.idle": "2023-08-18T19:41:25.472859Z", "shell.execute_reply": "2023-08-18T19:41:25.471738Z" }, "origin_pos": 12, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "class MLPScratch(d2l.Classifier):\n", " def __init__(self, num_inputs, num_outputs, num_hiddens, lr, sigma=0.01):\n", " super().__init__()\n", " self.save_hyperparameters()\n", " self.W1 = nn.Parameter(torch.randn(num_inputs, num_hiddens) * sigma)\n", " self.b1 = nn.Parameter(torch.zeros(num_hiddens))\n", " self.W2 = nn.Parameter(torch.randn(num_hiddens, num_outputs) * sigma)\n", " self.b2 = nn.Parameter(torch.zeros(num_outputs))" ] }, { "cell_type": "markdown", "id": "49aeeb41", "metadata": { "origin_pos": 15 }, "source": [ "### Model\n", "\n", "To make sure we know how everything works,\n", "we will [**implement the ReLU activation**] ourselves\n", "rather than invoking the built-in `relu` function directly.\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "2af157bb", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:41:25.477923Z", "iopub.status.busy": "2023-08-18T19:41:25.477044Z", "iopub.status.idle": "2023-08-18T19:41:25.482976Z", "shell.execute_reply": "2023-08-18T19:41:25.481963Z" }, "origin_pos": 17, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "def relu(X):\n", " a = torch.zeros_like(X)\n", " return torch.max(X, a)" ] }, { "cell_type": "markdown", "id": "3f8bd74c", "metadata": { "origin_pos": 20 }, "source": [ "Since we are disregarding spatial structure,\n", "we `reshape` each two-dimensional image into\n", "a flat vector of length `num_inputs`.\n", "Finally, we (**implement our model**)\n", "with just a few lines of code. Since we use the framework built-in autograd this is all that it takes.\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "7438b40c", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:41:25.492513Z", "iopub.status.busy": "2023-08-18T19:41:25.491685Z", "iopub.status.idle": "2023-08-18T19:41:25.498375Z", "shell.execute_reply": "2023-08-18T19:41:25.497344Z" }, "origin_pos": 21, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "@d2l.add_to_class(MLPScratch)\n", "def forward(self, X):\n", " X = X.reshape((-1, self.num_inputs))\n", " H = relu(torch.matmul(X, self.W1) + self.b1)\n", " return torch.matmul(H, self.W2) + self.b2" ] }, { "cell_type": "markdown", "id": "f07056fc", "metadata": { "origin_pos": 22 }, "source": [ "### Training\n", "\n", "Fortunately, [**the training loop for MLPs\n", "is exactly the same as for softmax regression.**] We define the model, data, and trainer, then finally invoke the `fit` method on model and data.\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "82d57362", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:41:25.502740Z", "iopub.status.busy": "2023-08-18T19:41:25.502096Z", "iopub.status.idle": "2023-08-18T19:42:19.146140Z", "shell.execute_reply": "2023-08-18T19:42:19.144962Z" }, "origin_pos": 23, "tab": [ "pytorch" ] }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", " \n", " 2023-08-18T19:42:19.045062\n", " image/svg+xml\n", " \n", " \n", " Matplotlib v3.7.2, https://matplotlib.org/\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "model = MLPScratch(num_inputs=784, num_outputs=10, num_hiddens=256, lr=0.1)\n", "data = d2l.FashionMNIST(batch_size=256)\n", "trainer = d2l.Trainer(max_epochs=10)\n", "trainer.fit(model, data)" ] }, { "cell_type": "markdown", "id": "0c068a33", "metadata": { "origin_pos": 24 }, "source": [ "## Concise Implementation\n", "\n", "As you might expect, by relying on the high-level APIs, we can implement MLPs even more concisely.\n", "\n", "### Model\n", "\n", "Compared with our concise implementation\n", "of softmax regression implementation\n", "(:numref:`sec_softmax_concise`),\n", "the only difference is that we add\n", "*two* fully connected layers where we previously added only *one*.\n", "The first is [**the hidden layer**],\n", "the second is the output layer.\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "a5087507", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:42:19.152096Z", "iopub.status.busy": "2023-08-18T19:42:19.151778Z", "iopub.status.idle": "2023-08-18T19:42:19.157644Z", "shell.execute_reply": "2023-08-18T19:42:19.156631Z" }, "origin_pos": 26, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "class MLP(d2l.Classifier):\n", " def __init__(self, num_outputs, num_hiddens, lr):\n", " super().__init__()\n", " self.save_hyperparameters()\n", " self.net = nn.Sequential(nn.Flatten(), nn.LazyLinear(num_hiddens),\n", " nn.ReLU(), nn.LazyLinear(num_outputs))" ] }, { "cell_type": "markdown", "id": "c5fb2be8", "metadata": { "origin_pos": 29 }, "source": [ "Previously, we defined `forward` methods for models to transform input using the model parameters.\n", "These operations are essentially a pipeline:\n", "you take an input and\n", "apply a transformation (e.g.,\n", "matrix multiplication with weights followed by bias addition),\n", "then repetitively use the output of the current transformation as\n", "input to the next transformation.\n", "However, you may have noticed that \n", "no `forward` method is defined here.\n", "In fact, `MLP` inherits the `forward` method from the `Module` class (:numref:`subsec_oo-design-models`) to \n", "simply invoke `self.net(X)` (`X` is input),\n", "which is now defined as a sequence of transformations\n", "via the `Sequential` class.\n", "The `Sequential` class abstracts the forward process\n", "enabling us to focus on the transformations.\n", "We will further discuss how the `Sequential` class works in :numref:`subsec_model-construction-sequential`.\n", "\n", "\n", "### Training\n", "\n", "[**The training loop**] is exactly the same\n", "as when we implemented softmax regression.\n", "This modularity enables us to separate\n", "matters concerning the model architecture\n", "from orthogonal considerations.\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "baf391c1", "metadata": { "execution": { "iopub.execute_input": "2023-08-18T19:42:19.162133Z", "iopub.status.busy": "2023-08-18T19:42:19.161837Z", "iopub.status.idle": "2023-08-18T19:43:16.475813Z", "shell.execute_reply": "2023-08-18T19:43:16.474574Z" }, "origin_pos": 30, "tab": [ "pytorch" ] }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", " \n", " 2023-08-18T19:43:16.297049\n", " image/svg+xml\n", " \n", " \n", " Matplotlib v3.7.2, https://matplotlib.org/\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "model = MLP(num_outputs=10, num_hiddens=256, lr=0.1)\n", "trainer.fit(model, data)" ] }, { "cell_type": "markdown", "id": "8b353853", "metadata": { "origin_pos": 31 }, "source": [ "## Summary\n", "\n", "Now that we have more practice in designing deep networks, the step from a single to multiple layers of deep networks does not pose such a significant challenge any longer. In particular, we can reuse the training algorithm and data loader. Note, though, that implementing MLPs from scratch is nonetheless messy: naming and keeping track of the model parameters makes it difficult to extend models. For instance, imagine wanting to insert another layer between layers 42 and 43. This might now be layer 42b, unless we are willing to perform sequential renaming. Moreover, if we implement the network from scratch, it is much more difficult for the framework to perform meaningful performance optimizations.\n", "\n", "Nonetheless, you have now reached the state of the art of the late 1980s when fully connected deep networks were the method of choice for neural network modeling. Our next conceptual step will be to consider images. Before we do so, we need to review a number of statistical basics and details on how to compute models efficiently.\n", "\n", "\n", "## Exercises\n", "\n", "1. Change the number of hidden units `num_hiddens` and plot how its number affects the accuracy of the model. What is the best value of this hyperparameter?\n", "1. Try adding a hidden layer to see how it affects the results.\n", "1. Why is it a bad idea to insert a hidden layer with a single neuron? What could go wrong?\n", "1. How does changing the learning rate alter your results? With all other parameters fixed, which learning rate gives you the best results? How does this relate to the number of epochs?\n", "1. Let's optimize over all hyperparameters jointly, i.e., learning rate, number of epochs, number of hidden layers, and number of hidden units per layer.\n", " 1. What is the best result you can get by optimizing over all of them?\n", " 1. Why it is much more challenging to deal with multiple hyperparameters?\n", " 1. Describe an efficient strategy for optimizing over multiple parameters jointly.\n", "1. Compare the speed of the framework and the from-scratch implementation for a challenging problem. How does it change with the complexity of the network?\n", "1. Measure the speed of tensor--matrix multiplications for well-aligned and misaligned matrices. For instance, test for matrices with dimension 1024, 1025, 1026, 1028, and 1032.\n", " 1. How does this change between GPUs and CPUs?\n", " 1. Determine the memory bus width of your CPU and GPU.\n", "1. Try out different activation functions. Which one works best?\n", "1. Is there a difference between weight initializations of the network? Does it matter?\n" ] }, { "cell_type": "markdown", "id": "60c1e284", "metadata": { "origin_pos": 33, "tab": [ "pytorch" ] }, "source": [ "[Discussions](https://discuss.d2l.ai/t/93)\n" ] } ], "metadata": { "language_info": { "name": "python" }, "required_libs": [] }, "nbformat": 4, "nbformat_minor": 5 }