@@ -923,6 +923,8 @@ class LazyMemmapStorage(LazyTensorStorage):
923
923
Args:
924
924
max_size (int): size of the storage, i.e. maximum number of elements stored
925
925
in the buffer.
926
+
927
+ Keyword Args:
926
928
scratch_dir (str or path): directory where memmap-tensors will be written.
927
929
device (torch.device, optional): device where the sampled tensors will be
928
930
stored and sent. Default is :obj:`torch.device("cpu")`.
@@ -933,6 +935,9 @@ class LazyMemmapStorage(LazyTensorStorage):
933
935
measuring the storage size. For instance, a storage of shape ``[3, 4]``
934
936
has capacity ``3`` if ``ndim=1`` and ``12`` if ``ndim=2``.
935
937
Defaults to ``1``.
938
+ existsok (bool, optional): whether an error should be raised if any of the
939
+ tensors already exists on disk. Defaults to ``True``. If ``False``, the
940
+ tensor will be opened as is, not overewritten.
936
941
937
942
.. note:: When checkpointing a ``LazyMemmapStorage``, one can provide a path identical to where the storage is
938
943
already stored to avoid executing long copies of data that is already stored on disk.
@@ -1009,10 +1014,12 @@ def __init__(
1009
1014
scratch_dir = None ,
1010
1015
device : torch .device = "cpu" ,
1011
1016
ndim : int = 1 ,
1017
+ existsok : bool = False ,
1012
1018
):
1013
1019
super ().__init__ (max_size , ndim = ndim )
1014
1020
self .initialized = False
1015
1021
self .scratch_dir = None
1022
+ self .existsok = existsok
1016
1023
if scratch_dir is not None :
1017
1024
self .scratch_dir = str (scratch_dir )
1018
1025
if self .scratch_dir [- 1 ] != "/" :
@@ -1108,7 +1115,7 @@ def max_size_along_dim0(data_shape):
1108
1115
if is_tensor_collection (data ):
1109
1116
out = data .clone ().to (self .device )
1110
1117
out = out .expand (max_size_along_dim0 (data .shape ))
1111
- out = out .memmap_like (prefix = self .scratch_dir )
1118
+ out = out .memmap_like (prefix = self .scratch_dir , existsok = self . existsok )
1112
1119
for key , tensor in sorted (
1113
1120
out .items (include_nested = True , leaves_only = True ), key = str
1114
1121
):
0 commit comments