Fixed the problem of the reset function of Memory corresponding to actor_critic_recurrent #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Original code in
class Memory(torch.nn.Module)
: atrsl_rl/modules/actor_critic_recurrent.py
When I train PPO policy with
num_envs=1
using ActorCriticRecurrent, I find a bug:I modify the code and find that
dones.max() >= hidden_state.size(-2)
The logs(
num_envs=1
) are below:The logs(
num_envs=4
) are below, it will not result in error, but the index ofhidden_state
is not correct.It can be found that the meaning of the elements in
dones
is whether each environment has ended. But what we need to reset are the ids of those ended environments.Therefore, the correct code is to find the envs whose
dones
areTrue
.I don't know what the corresponding behavior is when
done==True
, so by default, all the memory of all environments will be set to 0.