PyTorch's FakeTensor adds hinted storage size metadata for tracing
New serialization preserves symbolic expressions and optimization hints for policy tooling.
The PyTorch team has enhanced FakeTensor's trace tooling serialization by storing symbolic storage size metadata alongside explicit optimization hints. Previously, when a storage size was a symbolic SymInt, trace tooling only stored the symbolic expression. This limited diagnostic and policy tools from accessing concrete expected extents provided by optimization hints. The new behavior separates concerns: the existing `size` field remains symbolic, preserving provenance for downstream trace consumers, while a new `size_hint` field is added only when every free symbol in the storage-size expression has an explicit hint override.
This design avoids specializing tensor shapes or changing runtime semantics, keeping the symbolic trace contract intact. The pull request (PR #183839, approved by ezyang and laithsakka) fixes issue #183835 and passes tests in `test_fake_tensor.py`. The change is critical for tools that rely on both the abstract symbolic representation and concrete guarantees for policy decisions, enabling more accurate resource planning and debugging in PyTorch's meta-tensor framework.
- New `size_hint` field exported when all free symbols in storage size expression have explicit optimization hints.
- Preserves symbolic `size` field for provenance while adding concrete metadata for policy tooling.
- Fixes issue #183835 and passes existing FakeTensor tests without changing runtime semantics.
Why It Matters
Enables precise resource planning and debugging in PyTorch traces without sacrificing symbolic flexibility.