# Quick Reference

The Quick Reference collects the PyTorch patterns, tensor conventions, formulas, and workflow rules that recur throughout the course. Use this section when you know roughly what you need to do but do not remember the exact syntax, tensor shape, formula, or workflow pattern. For conceptual explanations and complete examples, return to the lessons or the tutorials.

:::{important}
The Quick Reference is not a tutorial. It is a concise summary of key concepts for experienced users. If you are new to deep learning with PyTorch, start with the lessons or the tutorials.
:::

## Find What You Need

| I need to... | Go to |
| ------------ | ----- |
| inspect, reshape, or move a tensor                               | [Tensors & Devices](quickref-tensors.md) |
| create a dataset or mini-batches                                 | [Data Management](quickref-data.md) |
| define a model or inspect its parameters                         | [Models](quickref-models.md) |
| calculate a loss or update parameters                            | [Training](quickref-training.md) |
| evaluate a model or restore the best checkpoint                  | [Evaluation](quickref-evaluation.md) |
| diagnose poor learning or design a controlled comparison         | [Diagnostics](quickref-diagnosis.md) |
| calculate CNN shapes or convolution parameters                   | [Convolutional Networks](quickref-convnet.md) |
| use batch normalization, residual connections, or global pooling | [Residual Networks](quickref-resnet.md) |
| use or fine-tune a pretrained model                              | [Transfer Learning](quickref-transfer.md) |

---

## Common Tensor Shapes

| Object | Typical shape |
| --- | --- |
| Tabular example | `(D,)` |
| Tabular batch | `(N, D)` |
| Grayscale image | `(1, H, W)` |
| RGB image | `(3, H, W)` |
| Image batch | `(N, C, H, W)` |
| Multiclass logits | `(N, K)` |
| Multiclass targets | `(N,)` |
| Binary logits | `(N,)` or `(N, 1)` |
| Binary targets | `(N,)` |
| Regression predictions | `(N,)` or `(N, T)` |

Notation:

- `N` = batch size;
- `D` = feature dimension;
- `K` = number of classes;
- `T` = number of regression targets;
- `C` = number of channels;
- `H` = height;
- `W` = width;


## Training, Validation, Test

Data is typically split into three partitions, each with a different role in the development workflow.

| Partition | May influence |
| --- | --- |
| Training | Model parameters and fitted preprocessing |
| Validation | Model selection and development decisions |
| Test | Final reported evaluation only |

## Training and Evaluation

Training updates the model parameters. Evaluation measures a fixed model without parameter updates.

| Training                               | Evaluation                                                |
| -------------------------------------- | --------------------------------------------------------- |
| `model.train()`                        | `model.eval()`                                            |
| gradients recorded for backpropagation | gradient recording disabled with `torch.inference_mode()` |
| backward pass computes gradients       | no backward pass                                          |
| optimizer updates parameters           | parameters remain fixed                                   |

## PyTorch Imports

```python
import torch
from torch import nn
import torch.nn.functional as F
from torch.utils.data import DataLoader, Dataset, Subset, random_split

from torchvision import datasets
import torchvision.transforms.v2 as v2 
```