TensorDictBase.pin_memory#
- TensorDictBase.pin_memory(num_threads: int | None = None, inplace: bool = False) Self#
Calls
pin_memory()on the stored tensors.- Parameters:
num_threads (int, optional) – if provided, the number of threads to use to call
pin_memoryon the leaves, in aThreadPoolExecutor. Defaults toNone, which, like0, callspin_memory()on the calling thread.inplace (bool, optional) – if
True, the tensordict is modified in-place. When every node is an unlockedTensorDictorLazyStackedTensorDict(or a tensorclass over one) and no leaf is aMemoryMappedTensor, in shared memory, sparse, jagged or anUnbatchedTensor, each leaf is replaced by its pinned copy, and the tensordict and every nested node stay the same objects; keys that hold the same tensor share its pinned copy, and a leaf that is a view of another leaf gets its own. Any other tree, such as a locked one or one that holds a memory-mapped tensordict, has the pinned copies written back into its leaves, as before, so they stay in pageable memory. Defaults toFalse.
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.