1515from tensordict .prototype import is_tensorclass
1616from tensordict .tensordict import is_tensor_collection , TensorDict , TensorDictBase
1717
18- from torchrl ._utils import _CKPT_BACKEND
18+ from torchrl ._utils import _CKPT_BACKEND , VERBOSE
1919from torchrl .data .replay_buffers .utils import INT_CLASSES
2020
2121try :
@@ -224,7 +224,8 @@ def load_state_dict(self, state_dict):
224224 self ._len = state_dict ["_len" ]
225225
226226 def _init (self , data : Union [TensorDictBase , torch .Tensor ]) -> None :
227- print ("Creating a TensorStorage..." )
227+ if VERBOSE :
228+ print ("Creating a TensorStorage..." )
228229 if isinstance (data , torch .Tensor ):
229230 # if Tensor, we just create a MemmapTensor of the desired shape, device and dtype
230231 out = torch .empty (
@@ -353,16 +354,18 @@ def load_state_dict(self, state_dict):
353354 self ._len = state_dict ["_len" ]
354355
355356 def _init (self , data : Union [TensorDictBase , torch .Tensor ]) -> None :
356- print ("Creating a MemmapStorage..." )
357+ if VERBOSE :
358+ print ("Creating a MemmapStorage..." )
357359 if isinstance (data , torch .Tensor ):
358360 # if Tensor, we just create a MemmapTensor of the desired shape, device and dtype
359361 out = MemmapTensor (
360362 self .max_size , * data .shape , device = self .device , dtype = data .dtype
361363 )
362364 filesize = os .path .getsize (out .filename ) / 1024 / 1024
363- print (
364- f"The storage was created in { out .filename } and occupies { filesize } Mb of storage."
365- )
365+ if VERBOSE :
366+ print (
367+ f"The storage was created in { out .filename } and occupies { filesize } Mb of storage."
368+ )
366369 elif is_tensorclass (data ):
367370 out = (
368371 data .clone ()
@@ -374,12 +377,13 @@ def _init(self, data: Union[TensorDictBase, torch.Tensor]) -> None:
374377 out .items (include_nested = True , leaves_only = True ), key = str
375378 ):
376379 filesize = os .path .getsize (tensor .filename ) / 1024 / 1024
377- print (
378- f"\t { key } : { tensor .filename } , { filesize } Mb of storage (size: { tensor .shape } )."
379- )
380+ if VERBOSE :
381+ print (
382+ f"\t { key } : { tensor .filename } , { filesize } Mb of storage (size: { tensor .shape } )."
383+ )
380384 else :
381- # out = TensorDict({}, [self.max_size, *data.shape])
382- print ("The storage is being created: " )
385+ if VERBOSE :
386+ print ("The storage is being created: " )
383387 out = (
384388 data .clone ()
385389 .expand (self .max_size , * data .shape )
@@ -390,9 +394,10 @@ def _init(self, data: Union[TensorDictBase, torch.Tensor]) -> None:
390394 out .items (include_nested = True , leaves_only = True ), key = str
391395 ):
392396 filesize = os .path .getsize (tensor .filename ) / 1024 / 1024
393- print (
394- f"\t { key } : { tensor .filename } , { filesize } Mb of storage (size: { tensor .shape } )."
395- )
397+ if VERBOSE :
398+ print (
399+ f"\t { key } : { tensor .filename } , { filesize } Mb of storage (size: { tensor .shape } )."
400+ )
396401 self ._storage = out
397402 self .initialized = True
398403
0 commit comments