ML Has No Type System for Tensor Shapes — and Most Bugs Pass Silently
In machine learning engineering, tensor shapes like [B, T, d] function as the closest equivalent to type signatures, but unlike traditional software, no runtime enforces their correctness. A deliberate experiment with four shape bugs in PyTorch found that only one was caught by the runtime, with the rest failing silently. PyTorch's broadcasting rule resolves shape mismatches by aligning dimensions from the right and stretching size-1 dimensions, but it operates purely on sizes, not semantic meaning. This means two axes of identical size — such as sequence length and hidden dimension — can be silently swapped without triggering any error. The post argues that manually annotating shape signatures next to operations is the only reliable discipline available to ML engineers working with tensors.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in