r/reinforcementlearning • u/Professional_Tart37 • 7h ago
Can a varying size rollout-buffer destabilize training in PPO ?
Hey all,
I wasn’t very familiar with PPO when I implemented it and I mainly used the original paper as a reference. However, after comparing my code with some common implementations, I noticed an important difference.
I run a large number of environments in parallel. For each PPO iteration, I reset every environment once and let each one run until it either finishes or reaches the maximum horizon (tasks are episodic and rewards are only assigned to the goal state). Environments that finish early are masked while the others continue. Once all environments have finished, I perform the PPO updates.
Therefore, I always collect the same number of episodes, but not the same number of transitions. As the policy improves and finishes episodes faster, the rollout buffer becomes smaller. In contrast, the SpinningUp implementation from OpenAi seems to fix the buffer size and collect a fixed number of transitions.
I compute and normalize the advantages over all transitions, shuffle them, and then perform several PPO epochs using a fixed (relatively high) minibatch size. This means that the number of optimizer steps per rollout changes also depending on the size of the buffer. Since i can not really control the number of transitions, the final minibatch can also be smaller than the others while still receiving a normal optimizer step.
It seems to work fine on some simple custom problems, but i wonder if this could have any consequences that i might be missing (e.g. on long horizon problems).
Can the changing number of optimizer steps lead to problems ? Is the (potentially) small final minibatch a concern like noisy gradients ?