# Attribute error when trying to compute actions after training DreamerV3 on Cartpole

**URL:** <https://discuss.ray.io/t/attribute-error-when-trying-to-compute-actions-after-training-dreamerv3-on-cartpole/12361>\
**Category:** RLlib\
**Created:** [October 7, 2023, 1:27pm UTC](https://discuss.ray.io/t/attribute-error-when-trying-to-compute-actions-after-training-dreamerv3-on-cartpole/12361 "2023-10-07T13:27:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alian3785](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/alian3785/32/5160_2.png) [@Alian3785](https://discuss.ray.io/u/Alian3785)\
**Post date:** [October 7, 2023, 1:27pm UTC](https://discuss.ray.io/t/attribute-error-when-trying-to-compute-actions-after-training-dreamerv3-on-cartpole/12361/1 "2023-10-07T13:27:50Z")

</div>

- High: It blocks me to complete my task.

So I train cartpole-v1 with DreamerV3 using tune in Colab with free GPU

```auto
from ray import tune
from ray.tune import Tuner
from ray.rllib.algorithms.dreamerv3 import DreamerV3Config
from ray.air import RunConfig, CheckpointConfig

# Define the configuration for PPO training
config = (DreamerV3Config().environment("CartPole-v1").training(model_size="XS",training_ratio=1024,).resources(num_gpus=1, num_gpus_per_learner_worker=1, num_learner_workers=0))

# Define the tuner
tuner = Tuner(
    "DreamerV3",
    run_config=RunConfig(
        stop={"training_iteration": 4000},
        checkpoint_config=CheckpointConfig(checkpoint_at_end=True)
    ),
    param_space=config,
)

# Run the tuner
result = tuner.fit()

```

It trains in an hour. Then I take a checkpoint

```auto
from ray.rllib.algorithms.algorithm import Algorithm
algo = Algorithm.from_checkpoint("/root/ray_results/DreamerV3_2023-10-04_14-17-04/DreamerV3_CartPole-v1_b623a_00000_0_2023-10-04_14-17-12/checkpoint_000000")

```

And try to compute actions almost exactly as documentation example - [Getting Started with RLlib — Ray 2.7.0](https://docs.ray.io/en/latest/rllib/rllib-training.html)

```auto
# Note: `gymnasium` (not `gym`) will be **the** API supported by RLlib from Ray 2.3 on.
try:
    import gymnasium as gym

    gymnasium = True
except Exception:
    import gym

    gymnasium = False

from ray.rllib.algorithms.dreamerv3.dreamerv3 import DreamerV3Config

env_name = "CartPole-v1"
env = gym.make(env_name)
#algo = PPOConfig().environment(env_name).build()

episode_reward = 0
terminated = truncated = False

if gymnasium:
    obs, info = env.reset()
else:
    obs = env.reset()

while not terminated and not truncated:
    action = algo.compute_single_action(obs)
    if gymnasium:
        obs, reward, terminated, truncated, info = env.step(action)
    else:
        obs, reward, terminated, info = env.step(action)
    episode_reward += reward

```

But I get an error: AttributeError: ‘DreamerV3EnvRunner’ object has no attribute ‘get\_policy’  
Is something still not ready with Dreamerv3 or am I doing something wrong? With other algorithms everything works fine.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/f/fd35e3af6dc184976da763c658622740040b3281.jpeg)

---

<div class="post-metadata">

**Author:** ![chus1818](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/chus1818/32/5230_2.png) [@chus1818](https://discuss.ray.io/u/chus1818)\
**Post date:** [October 22, 2023, 3:06pm UTC](https://discuss.ray.io/t/attribute-error-when-trying-to-compute-actions-after-training-dreamerv3-on-cartpole/12361/2 "2023-10-22T15:06:37Z")

</div>

I am having the same problem - See [this PR](https://github.com/ray-project/ray/pull/40448) for updated documentation about how to do it and [the issue](https://github.com/ray-project/ray/issues/40312) where this is discussed.

---

<div class="post-metadata">

**Author:** ![Alex-Golod](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/alex-golod/32/5439_2.png) [@Alex-Golod](https://discuss.ray.io/u/Alex-Golod)\
**Post date:** [December 4, 2023, 12:34pm UTC](https://discuss.ray.io/t/attribute-error-when-trying-to-compute-actions-after-training-dreamerv3-on-cartpole/12361/3 "2023-12-04T12:34:41Z")

</div>

Hello,  
Now it’s written at the end of Readme.

## Running Action Inference after Training

To run action inference on a DreamerV3 Algorithm object, you can use [this simple environment loop script](https://github.com/ray-project/ray/tree/master/doc/source/rllib/doc_code/dreamerv3_inference.py).

Note the slight complexity caused by the fact that DreamerV3 a) uses a recurrent model, b) uses the new RLModule-based API stack (no Policy class), and c) outputs actions in a one-hot fashion for discrete action spaces.
