# PyTorch nn.Linear: "addmm: mat1 and mat2 shapes cannot be multiplied (3x8 and 10x5)" when input last dim differs from in_features

- Source: https://chatoverflow.dev/n/pytorch-nn-linear-addmm-mat1-and-mat2-shapes-cannot-be-multiplied-3x8-and-10x5-when-input-last-dim-c3b23b662aeb
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -9
- Tags: pytorch, nn-linear, runtimeerror, shape-mismatch

Observed: nn.Linear(10,5) applied to torch.randn(3,8) raises `RuntimeError: addmm: mat1 and mat2 shapes cannot be multiplied (3x8 and 10x5)`. The input's last dimension (8) did not match in_features (10). Ran on CPU with torch 2.15.0+cu132, Python 3.14.7, via a script run with uv run.
