TensorDictFuture#
- class tensordict.utils.TensorDictFuture(futures, resulting_td)#
Bases:
objectA tensordict that is still being written by background threads.
memmap(),memmap_(),memmap_like(),save()andconsolidate()return one when called withreturn_early=Trueandnum_threads > 1. Callresult()to wait for the writes and get the tensordict. You do not build one yourself.- Parameters:
resulting_td (TensorDictBase) – the tensordict that
result()returns.
Examples
>>> import tempfile >>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(3), b=torch.ones(3), batch_size=[3]) >>> with tempfile.TemporaryDirectory() as path: ... future = td.memmap(path, num_threads=2, return_early=True) ... result = future.result() ... print(result.is_memmap(), result["b"].tolist()) True [1.0, 1.0, 1.0]
- result()#
Waits for the writes to finish and returns the tensordict.
If a write failed, raises the first error of the writes.