AttributeError: 'SingleAgentEnvRunner' object has no attribute 'get_policy'

I am gettng this error, its been on me from two days, and I am not able to make progress, somebody, kindly help me ‘AttributeError: ‘SingleAgentEnvRunner’ object has no attribute ‘get_policy’’

this is the whole code ’

Loading Checkpoint and running the gym environment

from ray import rllib
import gymnasium
from ray.rllib.algorithms.ppo import PPOConfig

env_name = “LunarLander-v3”
env = gymnasium.make(env_name,render_mode=“human”)
#algo = PPOConfig().environment(env_name).build()
checkpoint_path = “The Path”
my_ppo = (PPOConfig().environment(env_name)).build()
algo = my_ppo.from_checkpoint(checkpoint_path)

episode_reward = 0
terminated = truncated = False

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

#while not terminated and not truncated:
for _ in range(500):

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

env.close() ’

3 Likes

I got same problem here. Any updates on this?

Hey, which model are you running, I got the solution for this.

1 Like

I’m running on DQN algorithm, Could you please share the solution for this error?

same issue also with DQN, any help appreciated.

edit: replacing .get_policy().model with get_module() worked for my purposes. seems to be another issue with out of date documentation and examples…

Thanks for flagging this! I’ll try to get this updated in the docs / examples :slight_smile:

1 Like

Thanks! But while that solution worked for extracting the model architecture, it does not help when I want to actually get the learned policy and test it. I’m looking through the codebase and can’t quite figure it out; it seems like this line fails because type(self.env_runner) is <class 'ray.rllib.env.single_agent_env_runner.SingleAgentEnvRunner'>, which afaict does not define get_policy and neither do its parent classes.