PyTorch Developer Podcast
PyTorch Developer Podcast
Edward Yang, Team PyTorch
Jul 20, 2021 · 15 min

Reference counting

MP3

Reference counting is a common memory management technique in C++ but PyTorch does its reference counting in a slightly idiosyncratic way using intrusive_ptr. We'll talk about why intrusive_ptr exists, the reason why refcount bumps are slow in C++ (but not in Python), what's up with const Tensor& everywhere, why the const is a lie and how TensorRef lets you create a const Tensor& from a TensorImpl* without needing to bump your reference count.

Further reading.

This podcast uses Simplecast for stats and dynamic audio. What this means Episodes play from the podcast's own servers, unmodified. Not affiliated with Podbay.