1515
1616
1717class DreamerEnv (ModelBasedEnvBase ):
18- """Dreamer simulation environment."""
18+ """Dreamer simulation environment.
19+
20+ This environment is used for imagination rollouts in Dreamer training.
21+ It never terminates (done is always False) since imagination runs for a
22+ fixed horizon. The done-checking methods are overridden to avoid CUDA
23+ synchronization overhead from Python control flow on CUDA tensors.
24+ """
1925
2026 def __init__ (
2127 self ,
@@ -26,11 +32,31 @@ def __init__(
2632 device : DEVICE_TYPING = "cpu" ,
2733 batch_size : torch .Size | None = None ,
2834 ):
29- super ().__init__ (world_model , device = device , batch_size = batch_size )
35+ super ().__init__ (
36+ world_model ,
37+ device = device ,
38+ batch_size = batch_size ,
39+ # Skip done validation in reset() — imagination never terminates.
40+ allow_done_after_reset = True ,
41+ )
3042 self .obs_decoder = obs_decoder
3143 self .prior_shape = prior_shape
3244 self .belief_shape = belief_shape
3345
46+ def any_done (self , tensordict ) -> bool :
47+ """Returns False — imagination rollouts never terminate.
48+
49+ Overridden to avoid CUDA sync from `done.any()` in parent class.
50+ """
51+ return False
52+
53+ def maybe_reset (self , tensordict ):
54+ """No-op — imagination rollouts don't need partial resets.
55+
56+ Overridden to avoid CUDA sync from done checks in parent class.
57+ """
58+ return tensordict
59+
3460 def set_specs_from_env (self , env : EnvBase ):
3561 """Sets the specs of the environment from the specs of the given environment."""
3662 super ().set_specs_from_env (env )
0 commit comments