I am running DreamerV3 and facing some issues apparently due to the MetricsLogger, the raised error is similar to TypeError: Scalar tensor has no len()
, and seems to be thrown when executing the _reduced_values()
function on a 2D EagerTensor, in particular on these 2 lines of ray/rllib/utils/metrics/stats.py
(e.g. when reduce_meth
is tf.reduce_mean
):
reduce_meth = getattr(tf, "reduce_" + self._reduce_method)
reduced = reduce_meth(values)
The error can be reproduced through the following code (I am using Ray 2.43.0 and tensorflow 2.19.0):
# See https://discuss.ray.io/t/dreamer-v3-rllib-tensorflow-error/15127
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"
import ray
from ray.rllib.algorithms.dreamerv3.dreamerv3 import DreamerV3Config
if __name__ == "__main__":
ray.init(local_mode=True) # debugging
config = (
DreamerV3Config()
.environment(env='CartPole-v1')
.env_runners(
num_env_runners=0,
num_envs_per_env_runner=1
)
.reporting(
metrics_num_episodes_for_smoothing=1,
report_images_and_videos=False,
report_dream_data=False,
report_individual_batch_item_stats=False,
)
# See Appendix A.
.training(model_size="XS")
.framework(
"tf2",
eager_tracing=False # debugging
)
)
agent = config.build_algo()
agent.train()
Naively replacing reduce_meth(values)
with reduce_meth(values[0])
seems to run but I do not think this is the ultimate solution. Is the above code the correct way to run DreamerV3?
Thank you