The vocabulary used across every lesson. Terms marked later are taught in upcoming lessons — the definition here is stable, so you can peek ahead.
0 = scalar, 1 = vector, 2 = matrix, n = n-d tensor. Read it as x.ndim.torch.Size. The most-checked property in real code. x.shape or x.size().
x.shape # torch.Size([2, 3]) → 2 rows, 3 colssum(dim=0) to say which axis to act along. Negative indices count from the end (-1 = last).torch.float32 (default for floats), float16/bfloat16, int64 (default for ints), bool, etc. Mismatched dtypes are a common error. x.dtype.x.contiguous() to force it.+ - * /, torch.exp, x.relu()…
x + 10 x * x1.
(2,3) + (3,) → (2,3) (2,3) + (2,1) → (2,3)@(m,k) @ (k,n) → (m,n). Also torch.matmul.sum, mean, max, argmax. Pass dim= to choose the axis to collapse; omit it to reduce the whole tensor to a scalar.
x.sum(dim=0) # collapse rows → one value per columnview never copies (needs contiguous data); reshape copies only if it must. Use -1 to infer one dimension.
x.view(3, 2) x.view(-1) # flatten_ that mutates the tensor instead of returning a new one: add_, zero_, mul_. Saves memory but can break autograd — use deliberately.cpu, mps (Apple GPU, shown as mps:0), or cuda (NVIDIA). Ops require all operands on the same device. x.device.torch.backends.mps.is_available(). Not every op is implemented yet — set PYTORCH_ENABLE_MPS_FALLBACK=1 to fall back to CPU for the gaps.t.numpy() and torch.from_numpy(a) convert between a CPU tensor and a NumPy array, sharing the same memory (change one, the other changes). GPU tensors must be moved to CPU first.True, PyTorch records the operations done to it so it can later compute gradients. Parameters have it set automatically..grad of every leaf tensor with requires_grad=True.backward() — same shape as the tensor. Gradients accumulate (add up) across calls, which is why training loops zero_grad().requires_grad=True get a populated .grad.with torch.no_grad():) that turns off graph tracking — used during inference and when manually updating parameters, to save memory and avoid recording those ops.forward(). You subclass it; calling the instance runs forward.nn.Parameter, requires_grad=True by default). model.parameters() hands them to the optimizer.nn.MSELoss, nn.CrossEntropyLoss). You call .backward() on it.torch.optim.SGD, Adam). step() applies one update; zero_grad() resets gradients to zero for the next iteration.forward → loss → backward → step → zero_grad. You'll see this exact shape in essentially every PyTorch codebase.Dataset = an indexable source of samples; DataLoader = a batched, optionally shuffled iterable over a dataset. One epoch = one full pass; a batch = the subset processed per step.