stable-baselines3
Skill3 starsChanged 8 months agoMITView on GitHub
Production-ready reinforcement learning algorithms (PPO, SAC, DQN, TD3, DDPG, A2C) with scikit-learn-like API. Use for standard RL experiments, quick prototyping, and well-documented algorithm implementations. Best for single-agent RL with Gymnasium environments. For high-performance parallel training, multi-agent systems, or custom vectorized environments, use pufferlib instead.
- Installs packages
9 other projects use a version of this, 6 of them edited.
Adopted by
Most recently taken up by
- BrightGold70/skillsedited, first seen Nov 8, 2026
- MarieLynneBlock/arcanum-artifexedited, first seen Nov 1, 2026
- davidanthonyn/claude-skillsedited, first seen Oct 20, 2026
- patoangolano/bio-stackedited, first seen Oct 15, 2026
- Luooops/skillsedited, first seen Oct 13, 2026
- uppifyagency/boilerplate-saas-2026word for word, first seen Jun 2, 2026
Other versions9 projects use a version of this.
Word for word · 3
- LeonChaoX/qinyan-academic-skills★ 910100% same
- qinyan-ai/qinyan-academic-skills★ 80100% same
- uppifyagency/boilerplate-saas-2026★ 1100% same
Edited · 6
- MarieLynneBlock/arcanum-artifex★ 497% same
- BrightGold70/skills★ 190% same
- Luooops/skills★ 176% same
- yf8578/claude-skills-collection★ 190% same
- davidanthonyn/claude-skills★ 094% same
- patoangolano/bio-stack★ 044% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository43 other files it gives its agents.
- agent-codingSkill
- benchmark-designSkill
- citation-managementSkill
- code-reproductionSkill
- code-to-paperSkill
- daskSkill
- experiment-trackingSkill
- exploratory-data-analysisSkill
- get-available-resourcesSkill
- github-release-prepSkill
- latex-postersSkill
- literature-reviewSkill
- markdown-mermaid-writingSkill
- markitdownSkill
- matplotlibSkill
- modalSkill
- networkxSkill
- paper-to-codeSkill
- peer-reviewSkill
- plotlySkill
- polarsSkill
- pytorch-lightningSkill
- pyzoteroSkill
- repo-cleanupSkill
- research-planningSkill
- reviewer-responseSkill
- scholar-evaluationSkill
- scientific-critical-thinkingSkill
- scientific-schematicsSkill
- scientific-slidesSkill
- scientific-visualizationSkill
- scientific-writingSkill
- scikit-learnSkill
- seabornSkill
- shapSkill
- statistical-analysisSkill
- statsmodelsSkill
- sympySkill
- torch-geometricSkill
- transformersSkill
- umap-learnSkill
- vaexSkill
- venue-templatesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. 5 are common, 0 are distinctive, and 9 are very specific to this project.
5
Common
Most of the 6 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 43
Use model.load() as a static method, not on an existing instance
- Very specific: line 47
Use references/algorithms.md for detailed algorithm characteristics and selection guidance.
- Common: line 67
Use channel-first format when possible (channels, height, width)
- Very specific: line 102
When using multiple environments with off-policy algorithms (SAC, TD3, DQN), set gradient_steps=-1 to perform one gradient update per …
- Common: line 120
StopTrainingOnRewardThreshold: Stop when target reward reached
- Common: line 232
Use when observations are dictionaries (e.g., combining images with sensor data).
- Very specific: line 260
Choose algorithm: Use references/algorithms.md for selection guidance
- Very specific: line 261
Create/adapt environment: Use scripts/custom_env_template.py if needed
- Very specific: line 262
Validate environment: Always run check_env() before training
- Very specific: line 263
Set up training: Use scripts/train_rl_agent.py as starting template
- Common: line 265
Optimize performance: Consider vectorized environments for speed
- Very specific: line 266
Evaluate and iterate: Use scripts/evaluate_agent.py for assessment
- Common: line 271
Slow training: Consider SubprocVecEnv for parallel environments
- Very specific: line 273
Import errors: Ensure stable_baselines3 is installed: uv pip install stable-baselines3[extra]
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stable Baselines3
Overview
Stable Baselines3 (SB3) is a PyTorch-based library providing reliable implementations of reinforcement learning algorithms. This skill provides comprehensive guidance for training RL agents, creating custom environments, implementing callbacks, and optimizing training workflows using SB3's unified API.
Core Capabilities
1. Training RL Agents
Basic Training Pattern:
import gymnasium as gym
from stable_baselines3 import PPO
# Create environment
env = gym.make("CartPole-v1")
# Initialize agent
model = PPO("MlpPolicy", env, verbose=1)
# Train the agent
model.learn(total_timesteps=10000)
# Save the model
model.save("ppo_cartpole")
# Load the model (without prior instantiation)
model = PPO.load("ppo_cartpole", env=env)Important Notes:
total_timestepsis a lower bound; actual training may exceed this due to batch collection- Use
model.load()as a static method, not on an existing instance - The replay buffer is NOT saved with the model to save space
Algorithm Selection:
Use references/algorithms.md for detailed algorithm characteristics and selection guidance. Quick reference:
- PPO/A2C: General-purpose, supports all action space types, good for multiprocessing
- SAC/TD3: Continuous control, off-policy, sample-efficient
- DQN: Discrete actions, off-policy
- HER: Goal-conditioned tasks
See scripts/train_rl_agent.py for a complete training template with best practices.
2. Custom Environments
Requirements:
Custom environments must inherit from gymnasium.Env and implement:
__init__(): Define action_space and observation_spacereset(seed, options): Return initial observation and info dictstep(action): Return observation, reward, terminated, truncated, inforender(): Visualization (optional)close(): Cleanup resources
Key Constraints:
- Image observations must be
np.uint8in range [0, 255] - Use channel-first format when possible (channels, height, width)
- SB3 normalizes images automatically by dividing by 255
- Set
normalize_images=Falsein policy_kwargs if pre-normalized - SB3 does NOT support
DiscreteorMultiDiscretespaces withstart!=0
Validation:
from stable_baselines3.common.env_checker import check_env
check_env(env, warn=True)See scripts/custom_env_template.py for a complete custom environment template and references/custom_environments.md for comprehensive guidance.
3. Vectorized Environments
Purpose: Vectorized environments run multiple environment instances in parallel, accelerating training and enabling certain wrappers (frame-stacking, normalization).
Types:
- DummyVecEnv: Sequential execution on current process (for lightweight environments)
- SubprocVecEnv: Parallel execution across processes (for compute-heavy environments)
Quick Setup:
from stable_baselines3.common.env_util import make_vec_env
# Create 4 parallel environments
env = make_vec_env("CartPole-v1", n_envs=4, vec_env_cls=SubprocVecEnv)
model = PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=25000)Off-Policy Optimization:
When using multiple environments with off-policy algorithms (SAC, TD3, DQN), set gradient_steps=-1 to perform one gradient update per environment step, balancing wall-clock time and sample efficiency.
API Differences:
reset()returns only observations (info available invec_env.reset_infos)step()returns 4-tuple:(obs, rewards, dones, infos)not 5-tuple- Environments auto-reset after episodes
- Terminal observations available via
infos[env_idx]["terminal_observation"]
See references/vectorized_envs.md for detailed information on wrappers and advanced usage.
4. Callbacks for Monitoring and Control
Purpose: Callbacks enable monitoring metrics, saving checkpoints, implementing early stopping, and custom training logic without modifying core algorithms.
Common Callbacks:
- EvalCallback: Evaluate periodically and save best model
- CheckpointCallback: Save model checkpoints at intervals
- StopTrainingOnRewardThreshold: Stop when target reward reached
- ProgressBarCallback: Display training progress with timing
Custom Callback Structure:
from stable_baselines3.common.callbacks import BaseCallback
class CustomCallback(BaseCallback):
def _on_training_start(self):
# Called before first rollout
pass
def _on_step(self):
# Called after each environment step
# Return False to stop training
return True
def _on_rollout_end(self):
# Called at end of rollout
passAvailable Attributes:
self.model: The RL algorithm instanceself.num_timesteps: Total environment stepsself.training_env: The training environment
Chaining Callbacks:
from stable_baselines3.common.callbacks import CallbackList
callback = CallbackList([eval_callback, checkpoint_callback, custom_callback])
model.learn(total_timesteps=10000, callback=callback)See references/callbacks.md for comprehensive callback documentation.
5. Model Persistence and Inspection
Saving and Loading:
# Save model
model.save("model_name")
# Save normalization statistics (if using VecNormalize)
vec_env.save("vec_normalize.pkl")
# Load model
model = PPO.load("model_name", env=env)
# Load normalization statistics
vec_env = VecNormalize.load("vec_normalize.pkl", vec_env)Parameter Access:
# Get parameters
params = model.get_parameters()
# Set parameters
model.set_parameters(params)
# Access PyTorch state dict
state_dict = model.policy.state_dict()6. Evaluation and Recording
Evaluation:
from stable_baselines3.common.evaluation import evaluate_policy
mean_reward, std_reward = evaluate_policy(
model,
env,
n_eval_episodes=10,
deterministic=True
)Video Recording:
from stable_baselines3.common.vec_env import VecVideoRecorder
# Wrap environment with video recorder
env = VecVideoRecorder(
env,
"videos/",
record_video_trigger=lambda x: x % 2000 == 0,
video_length=200
)See scripts/evaluate_agent.py for a complete evaluation and recording template.
7. Advanced Features
Learning Rate Schedules:
def linear_schedule(initial_value):
def func(progress_remaining):
# progress_remaining goes from 1 to 0
return progress_remaining * initial_value
return func
model = PPO("MlpPolicy", env, learning_rate=linear_schedule(0.001))Multi-Input Policies (Dict Observations):
model = PPO("MultiInputPolicy", env, verbose=1)Use when observations are dictionaries (e.g., combining images with sensor data).
Hindsight Experience Replay:
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",
),
)TensorBoard Integration:
model = PPO("MlpPolicy", env, tensorboard_log="./tensorboard/")
model.learn(total_timesteps=10000)Workflow Guidance
Starting a New RL Project:
- Define the problem: Identify observation space, action space, and reward structure
- Choose algorithm: Use
references/algorithms.mdfor selection guidance - Create/adapt environment: Use
scripts/custom_env_template.pyif needed - Validate environment: Always run
check_env()before training - Set up training: Use
scripts/train_rl_agent.pyas starting template - Add monitoring: Implement callbacks for evaluation and checkpointing
- Optimize performance: Consider vectorized environments for speed
- Evaluate and iterate: Use
scripts/evaluate_agent.pyfor assessment
Common Issues:
- Memory errors: Reduce
buffer_sizefor off-policy algorithms or use fewer parallel environments - Slow training: Consider SubprocVecEnv for parallel environments
- Unstable training: Try different algorithms, tune hyperparameters, or check reward scaling
- Import errors: Ensure
stable_baselines3is installed:uv pip install stable-baselines3[extra]
Resources
scripts/
train_rl_agent.py: Complete training script template with best practicesevaluate_agent.py: Agent evaluation and video recording templatecustom_env_template.py: Custom Gym environment template
references/
algorithms.md: Detailed algorithm comparison and selection guidecustom_environments.md: Comprehensive custom environment creation guidecallbacks.md: Complete callback system referencevectorized_envs.md: Vectorized environment usage and wrappers
Installation
# Basic installation
uv pip install stable-baselines3
# With extra dependencies (Tensorboard, etc.)
uv pip install stable-baselines3[extra]Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

