AttributeError: 'numpy.ndarray' object has no attribute 'float'

Hi, I’m using dqn for my custom multi-agent env. I can test my evn with trainer and tune, both work without any error. After just a few training iterations, I would like to see the agent’s performance with compute_action. But I get the following error:
AttributeError: 'numpy.ndarray' object has no attribute 'float'

I ran my code in debugger mode, and I found that the problem comes from torch_policy.py line 276.
return self._compute_action_helper(input_dict, state_batches, seq_lens, explore, timestep)

I’m using torch vision as the policy. in this line 276, input_dict contains the obs and PyTorch expects to receive it as a Tensor. But, for some reason RLlib/Ray stores the obs tensor in a nparray. As a result, this error rises.

I wonder anyone knows what is happening in the background?

Thanks!

Hi @deepgravity

This should not happen. RLlib converts the complete content of the input_dict to torch tensors before computing actions.

Can you breakpoint into this function? … or maybe to this line and see what happens there?

Cheers!

Hi @arturn
Many thanks for your reply.

I fixed the error. Actually, it was my fault to send observation as a dictionary to the conpute_action method. But, the right datatype is a nparray.

For those who got into the same problem, here is the solution:

policy_id = self.config['multiagent']['policy_mapping_fn'](current_agent_name, _)
obs_arr = observation[current_agent_name]
action = self.agent.compute_single_action(obs_arr, policy_id=policy_id)

Cheers!

1 Like