@@ -2699,6 +2699,7 @@ def specs(self) -> Composite:
2699
2699
2700
2700
@property
2701
2701
def _has_dynamic_specs (self ) -> bool :
2702
+ # TODO: cache this value
2702
2703
return _has_dynamic_specs (self .specs )
2703
2704
2704
2705
def rollout (
@@ -2711,7 +2712,7 @@ def rollout(
2711
2712
auto_cast_to_device : bool = False ,
2712
2713
break_when_any_done : bool | None = None ,
2713
2714
break_when_all_done : bool | None = None ,
2714
- return_contiguous : bool = True ,
2715
+ return_contiguous : bool | None = False ,
2715
2716
tensordict : Optional [TensorDictBase ] = None ,
2716
2717
set_truncated : bool = False ,
2717
2718
out = None ,
@@ -2746,7 +2747,8 @@ def rollout(
2746
2747
break_when_all_done (bool, optional): if ``True``, break if all of the contained environments reach any
2747
2748
of the done states. If ``False``, break if at least one environment reaches any of the done states.
2748
2749
Default is ``False``.
2749
- return_contiguous (bool): if False, a LazyStackedTensorDict will be returned. Default is True.
2750
+ return_contiguous (bool): if False, a LazyStackedTensorDict will be returned. Default is `True` if
2751
+ the env does not have dynamic specs, otherwise `False`.
2750
2752
tensordict (TensorDict, optional): if ``auto_reset`` is False, an initial
2751
2753
tensordict must be provided. Rollout will check if this tensordict has done flags and reset the
2752
2754
environment in those dimensions (if needed).
@@ -2957,7 +2959,8 @@ def rollout(
2957
2959
raise TypeError (
2958
2960
"Cannot have both break_when_all_done and break_when_any_done True at the same time."
2959
2961
)
2960
-
2962
+ if return_contiguous is None :
2963
+ return_contiguous = not self ._has_dynamic_specs
2961
2964
if policy is not None :
2962
2965
policy = _make_compatible_policy (
2963
2966
policy ,
0 commit comments