Stochastic Stateful Policy Gradients (S2PG) is a novel framework designed to train recurrent (stateful) policies without relying on Backpropagation Through Time (BPTT). By treating an agent's internal memory as a stochastic variable, S2PG enables faster, highly parallelizable training that circumvents the notorious "vanishing gradient" problem while remaining theoretically unbiased.
The Challenge of Memory in RL
In many real-world Reinforcement Learning (RL) scenarios, agents operate under Partially Observable Markov Decision Processes (POMDPs)—meaning they don't have a perfect, complete view of their environment. To succeed, these agents require "memory," typically implemented via stateful policies like Recurrent Neural Networks (RNNs).
The industry standard for training these stateful policies is Backpropagation Through Time (BPTT). However, BPTT introduces three major bottlenecks:
- Sequential Bottlenecks: Gradients must be propagated backward through the entire history of the episode. This sequential requirement is slow and notoriously difficult to parallelize.
- Numerical Instability: Processing long histories frequently leads to "vanishing" or "exploding" gradients, where the learning signal either fades to zero or blows up to infinity.
- Systematic Bias: To maintain computational efficiency, researchers often truncate the history (Truncated BPTT). While faster, this introduces a systematic bias into the policy updates, limiting the agent's ability to learn long-term dependencies.
Enter Stochastic Stateful Policy Gradients (S2PG)
To address these limitations, the authors introduce S2PG. Instead of treating the internal state (memory) as a deterministic hidden layer, S2PG decomposes the policy into two distinct components:
- A Stochastic Internal State Kernel: This module determines how the agent's memory updates based on new observations.
- A Stateless Policy: This module decides the immediate action based on the current observation and the current memory state.
By framing the memory transition as a stochastic process, the authors derive a new version of the Policy Gradient Theorem. Crucially, this formulation allows gradients to be computed using only local information from the current timestep. The gradient is "shielded" from having to flow backward through time by utilizing a learned Q-function that accounts for the future value of internal state transitions.
This theoretical breakthrough allows the creation of "Recurrent Stochastic" (RS) versions of popular RL algorithms, including SAC-RS, TD3-RS, PPO-RS, and imitation learning variants like GAIL-RS.
Experimental Setup and Tasks
The S2PG approach was rigorously evaluated across a variety of continuous control benchmarks:
- MuJoCo Gym Tasks: Standard continuous control tasks like Ant, Humanoid, Hopper, Walker2d, and HalfCheetah.
- Robust RL/POMDPs: Modified versions of the MuJoCo tasks where velocities are hidden and link masses are randomized to test the agent's robustness.
- Memory Tasks: Point-mass navigation challenges where the goal is only visible at the start of the episode, forcing the agent to rely on its memory to navigate.
- Imitation Learning: Learning complex humanoid walking and running gaits by imitating motion capture data.
- Inductive Bias Tasks: Training a "blind" agent using a Central Pattern Generator (CPG)—essentially an oscillator—to learn locomotion without visual input.
Key Insights and Results
The shift from deterministic BPTT to stochastic S2PG yields several compelling advantages:
- Trading Variance for Speed: While S2PG introduces some variance because the internal state is stochastic, this variance is often preferable to the exploding variance and instability of BPTT in long-sequence tasks.
- Massive Speedups: Because S2PG doesn't require sequential backpropagation, it fully leverages modern GPU architectures. For algorithms like SAC and TD3, S2PG was roughly 2x to 4x faster in wall-clock time compared to BPTT with a history length of 32.
- Scaling to Complexity: In high-dimensional tasks, S2PG consistently outperformed BPTT. BPTT often struggles with the complex gradient landscapes of these environments, whereas S2PG’s local updates remain stable.
- Superior Imitation Learning: In Humanoid-Walk and Run tasks, GAIL-RS (powered by S2PG) significantly outperformed BPTT-based versions, achieving higher rewards with fewer samples.
- Beyond Neural Networks: S2PG's utility extends beyond standard RNNs. The authors demonstrated it can directly optimize the parameters of physical models, such as Ordinary Differential Equations (ODEs) used in robotics, directly within the RL loop.
Limitations and Future Directions
Despite its successes, S2PG faces a "Causality Dilemma" in pure POMDPs where no privileged information (like true velocity) is available to the critic. Learning both the internal state and the value function simultaneously from scratch is highly challenging; the best results often required a "privileged critic" during training. Additionally, in simpler, low-dimensional tasks (like Hopper), BPTT sometimes edged out S2PG because the added variance of S2PG’s stochastic state outweighed its parallelization benefits.
Future work will investigate how S2PG scales in massively parallel environments (like NVIDIA's Isaac Gym) and explore solutions to the causality dilemma to enable stronger performance in completely "blind" POMDPs.
Summary updated