trunk/8e58f3020c32896456ee7be3dd44aa07884c3199: [BE] Remove pyobj_interpreter_ from PyObjectSlot (#179631)
Core PyTorch commit eliminates interpreter pointer field, reducing memory overhead across tensors.
A significant internal optimization has landed in the PyTorch codebase. Maintainer colesbury authored commit 8e58f3020c32896456ee7be3dd44aa07884c3199, which removes the `pyobj_interpreter_` field from the `PyObjectSlot` class. This field was used to store a pointer to the Python interpreter object alongside a PyObject reference. However, analysis revealed this pointer was always pointing to the global Python interpreter when set, making the field redundant. The commit replaces direct field access with calls to `getGlobalPyInterpreter()`, streamlining the data structure.
This change represents a second attempt at this optimization, as a previous version was reverted. The commit message suggests the earlier failure may have been due to a subtle bug involving stray writes to `TensorImpl` that made it sensitive to changes in object size—a bug that was subsequently fixed in pull request #167564. With that fix in place, the team is more confident this optimization will stick. The commit also removes the associated `HermeticPyObjectTLS` (Thread-Local Storage) mechanism, further simplifying the code. Authored with assistance from Claude AI, this is a low-level but impactful change for the popular deep learning framework used by millions of developers.
- Removes redundant `pyobj_interpreter_` pointer field from `PyObjectSlot`, always pointed to global interpreter.
- Eliminates `HermeticPyObjectTLS` mechanism, simplifying PyTorch's internal object representation.
- Second attempt after a previous revert; relies on a prior bug fix (#167564) for `TensorImpl` stability.
Why It Matters
Reduces memory overhead for PyTorch tensors, leading to potential performance gains in large-scale AI training workloads.