ACADEMY · PYTORCH FUNDAMENTALS · 02

Silent broadcasting: why a falling loss can break your model

Verified on live PyTorch 2.15.0+cpu: why one extra set of brackets stretches four numbers into 16 cross-pairs, drops reported loss while destroying accuracy, and how one assertion stops it on step zero.

Key Takeaways (Evidence-Backed)

  • Silent broadcasting combines preds shape (4,) and targets shape (4, 1) into a 4×4 matrix of 16 pairs (12 wrong).
  • Live PyTorch 2.15.0+cpu run: matched MSE is 0.0000, silent broadcast MSE jumps to 2.5000.
  • Over 200 SGD steps, reported loss falls to 1.2526 while true MSE rises to 1.1466.
  • Practitioner Habit: Always place assert preds.shape == targets.shape right before computing loss.

Key Terms · Plain-Language Glossary

tensorA numbered grid paired with metadata: its shape, number type, memory strides, and device.
broadcastingAutomatic stretching of size-1 axes so mismatched tensor shapes combine without raising an error.