Skill Tracer
Skills › Scientific Agent Skills › stable-baselines3 › algorithms.md

algorithms.md

368 lines · skills/stable-baselines3/references/algorithms.md at 5f2bc03

Open on GitHub
1# Stable Baselines3 Algorithm Reference
2
3Targets SB3/SB3-Contrib 2.9.0. Algorithm performance and tuning suggestions below
4are task-dependent starting points, not guarantees or benchmark results.
5Sources: [action support](https://stable-baselines3.readthedocs.io/en/v2.9.0/guide/algos.html),
6[algorithm APIs](https://stable-baselines3.readthedocs.io/en/v2.9.0/modules/ppo.html),
7[RL experiment guidance](https://stable-baselines3.readthedocs.io/en/v2.9.0/guide/rl_tips.html).
8

Stable Baselines3 Algorithm Reference

Targets SB3/SB3-Contrib 2.9.0. Algorithm performance and tuning suggestions below are task-dependent starting points, not guarantees or benchmark results. Sources: action support, algorithm APIs, RL experiment guidance.

Raw lines 1 to 8
9## Algorithm Comparison Table
11| Algorithm | Type | Action Space | Sample Efficiency | Training Speed | Use Case |
12|-----------|------|--------------|-------------------|----------------|----------|
13| **PPO** | On-Policy | Box/Discrete/MultiDiscrete/MultiBinary | Medium | Fast | General-purpose, stable |
14| **A2C** | On-Policy | Box/Discrete/MultiDiscrete/MultiBinary | Low | Very Fast | Quick prototyping, multiprocessing |
15| **SAC** | Off-Policy | Continuous | High | Medium | Continuous control, sample-efficient |
16| **TD3** | Off-Policy | Continuous | High | Medium | Continuous control, deterministic |
17| **DDPG** | Off-Policy | Continuous | High | Medium | Continuous control (use TD3 instead) |
18| **DQN** | Off-Policy | Discrete | Medium | Medium | Discrete actions, Atari games |
19| **HER** | Replay buffer | Box or Discrete, per underlying algorithm | Task-dependent | Task-dependent | Goal-conditioned tasks |
20| **RecurrentPPO** | On-Policy | Box/Discrete/MultiDiscrete/MultiBinary | Medium | Slow | Partial observability (POMDP) |

Algorithm Comparison Table

AlgorithmTypeAction SpaceSample EfficiencyTraining SpeedUse Case
PPOOn-PolicyBox/Discrete/MultiDiscrete/MultiBinaryMediumFastGeneral-purpose, stable
A2COn-PolicyBox/Discrete/MultiDiscrete/MultiBinaryLowVery FastQuick prototyping, multiprocessing
SACOff-PolicyContinuousHighMediumContinuous control, sample-efficient
TD3Off-PolicyContinuousHighMediumContinuous control, deterministic
DDPGOff-PolicyContinuousHighMediumContinuous control (use TD3 instead)
DQNOff-PolicyDiscreteMediumMediumDiscrete actions, Atari games
HERReplay bufferBox or Discrete, per underlying algorithmTask-dependentTask-dependentGoal-conditioned tasks
RecurrentPPOOn-PolicyBox/Discrete/MultiDiscrete/MultiBinaryMediumSlowPartial observability (POMDP)
Raw lines 9 to 21
22## Detailed Algorithm Characteristics

Detailed Algorithm Characteristics

Raw lines 22 to 23
24### PPO (Proximal Policy Optimization)
26**Overview:** General-purpose on-policy algorithm with good performance across many tasks.
28**Strengths:**
29- Stable and reliable training
30- Works with supported action space types (Discrete, Box, MultiDiscrete, MultiBinary)
31- Good balance between sample efficiency and training speed
32- Excellent for multiprocessing with vectorized environments
33- Easy to tune
35**Weaknesses:**
36- Less sample-efficient than off-policy methods
37- Requires many environment interactions
39**Best For:**
40- General-purpose RL tasks
41- When stability is important
42- When you have cheap environment simulations
43- Tasks with continuous or discrete actions
45**Hyperparameter Guidance:**
46- `n_steps`: 2048-4096 for continuous, 128-256 for Atari
47- `learning_rate`: 3e-4 is a good default
48- `n_epochs`: 10 for continuous, 4 for Atari
49- `batch_size`: 64
50- `gamma`: 0.99 (0.995-0.999 for long episodes)

PPO (Proximal Policy Optimization)

Overview: General-purpose on-policy algorithm with good performance across many tasks.

Strengths:

  • Stable and reliable training
  • Works with supported action space types (Discrete, Box, MultiDiscrete, MultiBinary)
  • Good balance between sample efficiency and training speed
  • Excellent for multiprocessing with vectorized environments
  • Easy to tune

Weaknesses:

  • Less sample-efficient than off-policy methods
  • Requires many environment interactions

Best For:

  • General-purpose RL tasks
  • When stability is important
  • When you have cheap environment simulations
  • Tasks with continuous or discrete actions

Hyperparameter Guidance:

  • n_steps: 2048-4096 for continuous, 128-256 for Atari
  • learning_rate: 3e-4 is a good default
  • n_epochs: 10 for continuous, 4 for Atari
  • batch_size: 64
  • gamma: 0.99 (0.995-0.999 for long episodes)
Raw lines 24 to 51
52### A2C (Advantage Actor-Critic)
54**Overview:** Synchronous variant of A3C, simpler than PPO but less stable.
56**Strengths:**
57- Very fast training (simpler than PPO)
58- Works with supported action space types
59- Good for quick prototyping
60- Memory efficient
62**Weaknesses:**
63- Less stable than PPO
64- Requires careful hyperparameter tuning
65- Lower sample efficiency
67**Best For:**
68- Quick experimentation
69- When training speed is critical
70- Simple environments
72**Hyperparameter Guidance:**
73- `n_steps`: 5-256 depending on task
74- `learning_rate`: 7e-4
75- `gamma`: 0.99

A2C (Advantage Actor-Critic)

Overview: Synchronous variant of A3C, simpler than PPO but less stable.

Strengths:

  • Very fast training (simpler than PPO)
  • Works with supported action space types
  • Good for quick prototyping
  • Memory efficient

Weaknesses:

  • Less stable than PPO
  • Requires careful hyperparameter tuning
  • Lower sample efficiency

Best For:

  • Quick experimentation
  • When training speed is critical
  • Simple environments

Hyperparameter Guidance:

  • n_steps: 5-256 depending on task
  • learning_rate: 7e-4
  • gamma: 0.99
Raw lines 52 to 76
77### SAC (Soft Actor-Critic)
79**Overview:** Off-policy algorithm with entropy regularization, widely used for continuous control.
81**Strengths:**
82- Excellent sample efficiency
83- Very stable training
84- Automatic entropy tuning
85- Good exploration through stochastic policy
86- Suitable baseline for robotics
88**Weaknesses:**
89- Only supports continuous action spaces (Box)
90- Slower wall-clock time than on-policy methods
91- More complex hyperparameters
93**Best For:**
94- Continuous control (robotics, physics simulations)
95- When sample efficiency is critical
96- Expensive environment simulations
97- Tasks requiring good exploration
99**Hyperparameter Guidance:**
100- `learning_rate`: 3e-4
101- `buffer_size`: 1M for most tasks
102- `learning_starts`: 10000
103- `batch_size`: 256
104- `tau`: 0.005 (target network update rate)
105- `train_freq`: 1 with `gradient_steps=-1` as one update-to-data ratio to evaluate

SAC (Soft Actor-Critic)

Overview: Off-policy algorithm with entropy regularization, widely used for continuous control.

Strengths:

  • Excellent sample efficiency
  • Very stable training
  • Automatic entropy tuning
  • Good exploration through stochastic policy
  • Suitable baseline for robotics

Weaknesses:

  • Only supports continuous action spaces (Box)
  • Slower wall-clock time than on-policy methods
  • More complex hyperparameters

Best For:

  • Continuous control (robotics, physics simulations)
  • When sample efficiency is critical
  • Expensive environment simulations
  • Tasks requiring good exploration

Hyperparameter Guidance:

  • learning_rate: 3e-4
  • buffer_size: 1M for most tasks
  • learning_starts: 10000
  • batch_size: 256
  • tau: 0.005 (target network update rate)
  • train_freq: 1 with gradient_steps=-1 as one update-to-data ratio to evaluate
Raw lines 77 to 106
107### TD3 (Twin Delayed DDPG)
109**Overview:** Improved DDPG with double Q-learning and delayed policy updates.
111**Strengths:**
112- High sample efficiency
113- Deterministic policy (good for deployment)
114- More stable than DDPG
115- Good for continuous control
117**Weaknesses:**
118- Only supports continuous action spaces (Box)
119- Less exploration than SAC
120- Requires careful tuning
122**Best For:**
123- Continuous control tasks
124- When deterministic policies are preferred
125- Sample-efficient learning
127**Hyperparameter Guidance:**
128- `learning_rate`: 1e-3
129- `buffer_size`: 1M
130- `learning_starts`: 10000
131- `batch_size`: 256 (current TD3 default)
132- `policy_delay`: 2 (update policy every 2 critic updates)

TD3 (Twin Delayed DDPG)

Overview: Improved DDPG with double Q-learning and delayed policy updates.

Strengths:

  • High sample efficiency
  • Deterministic policy (good for deployment)
  • More stable than DDPG
  • Good for continuous control

Weaknesses:

  • Only supports continuous action spaces (Box)
  • Less exploration than SAC
  • Requires careful tuning

Best For:

  • Continuous control tasks
  • When deterministic policies are preferred
  • Sample-efficient learning

Hyperparameter Guidance:

  • learning_rate: 1e-3
  • buffer_size: 1M
  • learning_starts: 10000
  • batch_size: 256 (current TD3 default)
  • policy_delay: 2 (update policy every 2 critic updates)
Raw lines 107 to 133
134### DDPG (Deep Deterministic Policy Gradient)
136**Overview:** Early off-policy continuous control algorithm.
138**Strengths:**
139- Continuous action space support
140- Off-policy learning
142**Weaknesses:**
143- Less stable than TD3 or SAC
144- Sensitive to hyperparameters
145- Generally outperformed by TD3
147**Best For:**
148- Legacy compatibility
149- **Recommendation:** Use TD3 instead for new projects

DDPG (Deep Deterministic Policy Gradient)

Overview: Early off-policy continuous control algorithm.

Strengths:

  • Continuous action space support
  • Off-policy learning

Weaknesses:

  • Less stable than TD3 or SAC
  • Sensitive to hyperparameters
  • Generally outperformed by TD3

Best For:

  • Legacy compatibility
  • Recommendation: Use TD3 instead for new projects
Raw lines 134 to 150
151### DQN (Deep Q-Network)
153**Overview:** Classic off-policy algorithm for discrete action spaces.
155**Strengths:**
156- Sample-efficient for discrete actions
157- Experience replay enables reuse of past data
158- Proven success on Atari games
160**Weaknesses:**
161- Only supports discrete action spaces
162- Can be unstable without proper tuning
163- Overestimation bias
165**Best For:**
166- Discrete action tasks
167- Atari games and similar environments
168- When sample efficiency matters
170**Hyperparameter Guidance:**
171- `learning_rate`: 1e-4
172- `buffer_size`: 100K-1M depending on task
173- `learning_starts`: 50000 for Atari
174- `batch_size`: 32
175- `exploration_fraction`: 0.1
176- `exploration_final_eps`: 0.05
178**Variants:**
179- **QR-DQN**: Distributional RL version for better value estimates (SB3-Contrib)
180- **MaskablePPO**: Contrib supports invalid action masking with PPO; there is no released `MaskableDQN` in contrib 2.9.0.

DQN (Deep Q-Network)

Overview: Classic off-policy algorithm for discrete action spaces.

Strengths:

  • Sample-efficient for discrete actions
  • Experience replay enables reuse of past data
  • Proven success on Atari games

Weaknesses:

  • Only supports discrete action spaces
  • Can be unstable without proper tuning
  • Overestimation bias

Best For:

  • Discrete action tasks
  • Atari games and similar environments
  • When sample efficiency matters

Hyperparameter Guidance:

  • learning_rate: 1e-4
  • buffer_size: 100K-1M depending on task
  • learning_starts: 50000 for Atari
  • batch_size: 32
  • exploration_fraction: 0.1
  • exploration_final_eps: 0.05

Variants:

  • QR-DQN: Distributional RL version for better value estimates (SB3-Contrib)
  • MaskablePPO: Contrib supports invalid action masking with PPO; there is no released MaskableDQN in contrib 2.9.0.
Raw lines 151 to 181
182### HER (Hindsight Experience Replay)
184**Overview:** Not a standalone algorithm but a replay buffer strategy for goal-conditioned tasks.
186**Strengths:**
187- Dramatically improves learning in sparse reward settings
188- Learns from failures by relabeling goals
189- Supports SB3 off-policy algorithms using compatible Dict replay buffers (SAC, TD3, DDPG, DQN)
191**Weaknesses:**
192- Only for goal-conditioned environments
193- Requires specific observation structure (Dict with "observation", "achieved_goal", "desired_goal")
195**Best For:**
196- Goal-conditioned tasks (robotics manipulation, navigation)
197- Sparse reward environments
198- Tasks where goal is clear but reward is binary
200**Usage (illustrative, supply the task environment):**
202The environment must return Dict observations containing `observation`,
203`achieved_goal`, and `desired_goal`, and expose vectorized `compute_reward`.
204Set `learning_starts` beyond the first full episode so HER can sample completed
205episodes. Pass an environment when loading a HER model, including for inference.
207```python
208from stable_baselines3 import SAC, HerReplayBuffer
210model = SAC(
211 "MultiInputPolicy",
212 env,
213 replay_buffer_class=HerReplayBuffer,
214 replay_buffer_kwargs=dict(
215 n_sampled_goal=4,
216 goal_selection_strategy="future", # or "episode", "final"
217 ),
219```

HER (Hindsight Experience Replay)

Overview: Not a standalone algorithm but a replay buffer strategy for goal-conditioned tasks.

Strengths:

  • Dramatically improves learning in sparse reward settings
  • Learns from failures by relabeling goals
  • Supports SB3 off-policy algorithms using compatible Dict replay buffers (SAC, TD3, DDPG, DQN)

Weaknesses:

  • Only for goal-conditioned environments
  • Requires specific observation structure (Dict with "observation", "achieved_goal", "desired_goal")

Best For:

  • Goal-conditioned tasks (robotics manipulation, navigation)
  • Sparse reward environments
  • Tasks where goal is clear but reward is binary

Usage (illustrative, supply the task environment):

The environment must return Dict observations containing observation, achieved_goal, and desired_goal, and expose vectorized compute_reward. Set learning_starts beyond the first full episode so HER can sample completed episodes. Pass an environment when loading a HER model, including for inference.

from stable_baselines3 import SAC, HerReplayBuffer

model = SAC(
    "MultiInputPolicy",
    env,
    replay_buffer_class=HerReplayBuffer,
    replay_buffer_kwargs=dict(
        n_sampled_goal=4,
        goal_selection_strategy="future",  # or "episode", "final"
    ),
)
Raw lines 182 to 220
221### RecurrentPPO
223Use `from sb3_contrib import RecurrentPPO` and `"MlpLstmPolicy"`
224(or `"CnnLstmPolicy"` / `"MultiInputLstmPolicy"`). During manual prediction
225pass and retain `state`, and pass `episode_start=dones` from the preceding
226VecEnv step; initialize it to all True after reset. Core `evaluate_policy`
227handles those recurrent states. See the [official recurrent example](https://sb3-contrib.readthedocs.io/en/master/modules/ppo_recurrent.html).
229**Overview:** PPO with LSTM policy for handling partial observability.
231**Strengths:**
232- Handles partial observability (POMDP)
233- Can learn temporal dependencies
234- Good for memory-required tasks
236**Weaknesses:**
237- Slower training than standard PPO
238- More complex to tune
239- Requires sequential data
241**Best For:**
242- Partially observable environments
243- Tasks requiring memory (e.g., navigation without full map)
244- Time-series problems

RecurrentPPO

Use from sb3_contrib import RecurrentPPO and "MlpLstmPolicy" (or "CnnLstmPolicy" / "MultiInputLstmPolicy"). During manual prediction pass and retain state, and pass episode_start=dones from the preceding VecEnv step; initialize it to all True after reset. Core evaluate_policy handles those recurrent states. See the official recurrent example.

Overview: PPO with LSTM policy for handling partial observability.

Strengths:

  • Handles partial observability (POMDP)
  • Can learn temporal dependencies
  • Good for memory-required tasks

Weaknesses:

  • Slower training than standard PPO
  • More complex to tune
  • Requires sequential data

Best For:

  • Partially observable environments
  • Tasks requiring memory (e.g., navigation without full map)
  • Time-series problems
Raw lines 221 to 245
246## Algorithm Selection Guide

Algorithm Selection Guide

Raw lines 246 to 247
248### Decision Tree
2501. **What is your action space?**
251 - **Continuous (Box)** → Consider PPO, SAC, or TD3
252 - **Discrete** → Consider PPO, A2C, or DQN
253 - **MultiDiscrete/MultiBinary** → Use PPO or A2C
2552. **Is sample efficiency critical?**
256 - **Yes (expensive simulations)** → Use off-policy: SAC, TD3, DQN, or HER
257 - **No (cheap simulations)** → Use on-policy: PPO, A2C
2593. **Do you need fast wall-clock training?**
260 - **Yes** → Use PPO or A2C with vectorized environments
261 - **No** → Any algorithm works
2634. **Is the task goal-conditioned with sparse rewards?**
264 - **Yes** → Use HER with SAC or TD3
265 - **No** → Continue with standard algorithms
2675. **Is the environment partially observable?**
268 - **Yes** → Use RecurrentPPO
269 - **No** → Use standard algorithms

Decision Tree

  1. What is your action space?
  2. Continuous (Box) → Consider PPO, SAC, or TD3
  3. Discrete → Consider PPO, A2C, or DQN
  4. MultiDiscrete/MultiBinary → Use PPO or A2C
  1. Is sample efficiency critical?
  2. Yes (expensive simulations) → Use off-policy: SAC, TD3, DQN, or HER
  3. No (cheap simulations) → Use on-policy: PPO, A2C
  1. Do you need fast wall-clock training?
  2. Yes → Use PPO or A2C with vectorized environments
  3. No → Any algorithm works
  1. Is the task goal-conditioned with sparse rewards?
  2. Yes → Use HER with SAC or TD3
  3. No → Continue with standard algorithms
  1. Is the environment partially observable?
  2. Yes → Use RecurrentPPO
  3. No → Use standard algorithms
Raw lines 248 to 270
271### Quick Recommendations
273- **Starting out / General tasks:** PPO
274- **Continuous control / Robotics:** SAC
275- **Discrete actions / Atari:** DQN or PPO
276- **Goal-conditioned / Sparse rewards:** SAC + HER
277- **Fast prototyping:** A2C
278- **Sample efficiency critical:** SAC, TD3, or DQN
279- **Partial observability:** RecurrentPPO

Quick Recommendations

  • Starting out / General tasks: PPO
  • Continuous control / Robotics: SAC
  • Discrete actions / Atari: DQN or PPO
  • Goal-conditioned / Sparse rewards: SAC + HER
  • Fast prototyping: A2C
  • Sample efficiency critical: SAC, TD3, or DQN
  • Partial observability: RecurrentPPO
Raw lines 271 to 280
281## Training Configuration Tips

Training Configuration Tips

Raw lines 281 to 282
283### For On-Policy Algorithms (PPO, A2C)
285```python
286# Illustrative configuration; env_id and imports are supplied by the caller.
287# Use DummyVecEnv first; SubprocVecEnv calls require a guarded Python entry point.
288env = make_vec_env(env_id, n_envs=8)
290model = PPO(
291 "MlpPolicy",
292 env,
293 n_steps=2048, # Collect this many steps per environment before update
294 batch_size=64,
295 n_epochs=10,
296 learning_rate=3e-4,
297 gamma=0.99,
298 device="cpu", # Often faster than GPU for small MLP tasks
300```

For On-Policy Algorithms (PPO, A2C)

# Illustrative configuration; env_id and imports are supplied by the caller.
# Use DummyVecEnv first; SubprocVecEnv calls require a guarded Python entry point.
env = make_vec_env(env_id, n_envs=8)

model = PPO(
    "MlpPolicy",
    env,
    n_steps=2048,  # Collect this many steps per environment before update
    batch_size=64,
    n_epochs=10,
    learning_rate=3e-4,
    gamma=0.99,
    device="cpu",  # Often faster than GPU for small MLP tasks
)
Raw lines 283 to 301
302### For Off-Policy Algorithms (SAC, TD3, DQN)
304```python
305# Use step-based collection with multiple environments.
306env = make_vec_env(env_id, n_envs=4)
308model = SAC(
309 "MlpPolicy",
310 env,
311 buffer_size=1_000_000,
312 learning_starts=10000,
313 batch_size=256,
314 train_freq=1,
315 gradient_steps=-1, # Do 1 gradient step per env step (4 with 4 envs)
316 learning_rate=3e-4,
318```

For Off-Policy Algorithms (SAC, TD3, DQN)

# Use step-based collection with multiple environments.
env = make_vec_env(env_id, n_envs=4)

model = SAC(
    "MlpPolicy",
    env,
    buffer_size=1_000_000,
    learning_starts=10000,
    batch_size=256,
    train_freq=1,
    gradient_steps=-1,  # Do 1 gradient step per env step (4 with 4 envs)
    learning_rate=3e-4,
)
Raw lines 302 to 319
320## Common Pitfalls
3221. **Using DQN with continuous actions** - DQN only works with discrete actions
3232. **Assuming parallelism always helps** - benchmark environment cost against IPC overhead
3243. **Changing n_envs without checking rollout size** - PPO uses n_envs * n_steps; choose batch_size dividing that product
3254. **Using too large replay buffer** - Can cause memory issues
3265. **Not tuning learning rate** - Critical for stable training
3276. **Mixing reward units** - if normalizing training rewards, report original rewards during evaluation
3287. **Wrong policy type** - Use "CnnPolicy" for images, "MultiInputPolicy" for dict observations

Common Pitfalls

  1. Using DQN with continuous actions - DQN only works with discrete actions
  2. Assuming parallelism always helps - benchmark environment cost against IPC overhead
  3. Changing n_envs without checking rollout size - PPO uses n_envs * n_steps; choose batch_size dividing that product
  4. Using too large replay buffer - Can cause memory issues
  5. Not tuning learning rate - Critical for stable training
  6. Mixing reward units - if normalizing training rewards, report original rewards during evaluation
  7. Wrong policy type - Use "CnnPolicy" for images, "MultiInputPolicy" for dict observations
Raw lines 320 to 329
330## Reporting benchmark results
332Use the exact environment version, wrapper stack, action repeat, reward clipping,
333training budget and independent training seeds. Current Gymnasium MuJoCo IDs use
334v5 (for example `HalfCheetah-v5`); scores from v4 or different wrappers are not a
335reference target. Use the Zoo's versioned configurations and actual evaluation
336artifacts instead of unsourced expected reward numbers. The tiny tests for this
337skill do not measure comparative algorithm quality.

Reporting benchmark results

Use the exact environment version, wrapper stack, action repeat, reward clipping, training budget and independent training seeds. Current Gymnasium MuJoCo IDs use v5 (for example HalfCheetah-v5); scores from v4 or different wrappers are not a reference target. Use the Zoo's versioned configurations and actual evaluation artifacts instead of unsourced expected reward numbers. The tiny tests for this skill do not measure comparative algorithm quality.

Raw lines 330 to 338
339## SB3-Contrib (Experimental Algorithms)
341These algorithms live in the separate **[sb3-contrib](https://github.com/Stable-Baselines-Team/stable-baselines3-contrib)** package, not core SB3:
343| Algorithm | Use Case |
344|-----------|----------|
345| **MaskablePPO** | Discrete actions with action masking (invalid moves masked out) |
346| **CrossQ** | Continuous control; sample-efficient off-policy (added SB3-Contrib 2.4+) |
347| **QR-DQN** | Distributional DQN for better value estimates |
348| **RecurrentPPO** | Partial observability (POMDP) with LSTM policy |
349| **TQC** | Continuous control with distributional critics |
351Install with `uv pip install "sb3-contrib==2.9.0"`.

SB3-Contrib (Experimental Algorithms)

These algorithms live in the separate sb3-contrib package, not core SB3:

AlgorithmUse Case
MaskablePPODiscrete actions with action masking (invalid moves masked out)
CrossQContinuous control; sample-efficient off-policy (added SB3-Contrib 2.4+)
QR-DQNDistributional DQN for better value estimates
RecurrentPPOPartial observability (POMDP) with LSTM policy
TQCContinuous control with distributional critics

Install with uv pip install "sb3-contrib==2.9.0".

Raw lines 339 to 352
353## Additional Resources
355- **RL Baselines3 Zoo**: Collection of pre-trained agents and hyperparameters: https://github.com/DLR-RM/rl-baselines3-zoo
356- **Hyperparameter Tuning**: Use Optuna for systematic tuning
357- **Custom Policies**: Extend base policies for custom network architectures
358- **PPO + MlpPolicy on CPU**: For small MLP tasks (CartPole, Pendulum), `device="cpu"` often trains faster than GPU

Additional Resources

  • RL Baselines3 Zoo: Collection of pre-trained agents and hyperparameters: https://github.com/DLR-RM/rl-baselines3-zoo
  • Hyperparameter Tuning: Use Optuna for systematic tuning
  • Custom Policies: Extend base policies for custom network architectures
  • PPO + MlpPolicy on CPU: For small MLP tasks (CartPole, Pendulum), device="cpu" often trains faster than GPU
Raw lines 353 to 359
360### Masked evaluation
362For MaskablePPO, `True` marks a valid action. Use
363`sb3_contrib.common.maskable.callbacks.MaskableEvalCallback` and
364`sb3_contrib.common.maskable.evaluation.evaluate_policy`; core evaluators do not
365supply masks. In SubprocVecEnv, implement `action_masks()` inside the environment;
366`ActionMasker` is not the supported multiprocessing route. `check_env` samples
367actions without consulting masks, so validation needs a defined response to those
368actions. [Official masking contract](https://sb3-contrib.readthedocs.io/en/master/modules/ppo_mask.html).

Masked evaluation

For MaskablePPO, True marks a valid action. Use sb3_contrib.common.maskable.callbacks.MaskableEvalCallback and sb3_contrib.common.maskable.evaluation.evaluate_policy; core evaluators do not supply masks. In SubprocVecEnv, implement action_masks() inside the environment; ActionMasker is not the supported multiprocessing route. check_env samples actions without consulting masks, so validation needs a defined response to those actions. Official masking contract.

Raw lines 360 to 368