본문으로 건너뛰기
Skillpedia
에이전트51k · #3575

stable-baselines3

하는 일

Stable-Baselines3는 시뮬레이션 환경에서 AI 에이전트가 결정하는 법을 배우도록 돕는 도구입니다. 강화학습 알고리즘을 사용해, 경험이 쌓일수록 에이전트가 나아지도록 합니다.

사용하는 경우

  • ✓가상 로봇에게 걷는 법을 가르치고 싶을 때.
  • ✓캐릭터가 스스로 게임하는 법을 배우는 게임을 만들 때.
  • ✓복잡한 시뮬레이션에서 전략을 테스트하는 경우.

스킬 링크

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/stable-baselines3/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/stable-baselines3/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“PPO 알고리즘을 사용해 에이전트가 팩맨을 하도록 훈련해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 학습할 환경을 정의하고 알고리즘을 고릅니다. 그러면 도구가 훈련을 실행하고, 에이전트는 보상을 얻기 위해 행동을 조정합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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.

Current upstream: SB3 2.9.0 (June 15, 2026). Docs: stable-baselines3.readthedocs.io.

Installation

Tested against stable-baselines3 2.9.0. Requires Python 3.10+ (3.9 dropped in 2.8.0) and PyTorch >= 2.8.

# Basic installation
uv pip install "stable-baselines3==2.9.0"

# With extra dependencies (TensorBoard, ale-py for Atari, etc.)
uv pip install "stable-baselines3[extra]==2.9.0"

The 2.9.0 release supports Gymnasium >=0.29.1,<2.0; this review exercised Gymnasium 1.3.0, PyTorch 2.14.1 and Python 3.13 on CPU. pandas/matplotlib are now optional extras. Installation requires network unless packages are cached; local RL training needs no credentials or service endpoints.

On zsh, quote brackets: uv pip install 'stable-baselines3[extra]==2.9.0'.

For MuJoCo continuous-control benchmarks:

uv pip install "gymnasium[mujoco]"

Check your version:

import stable_baselines3
print(stable_baselines3.__version__)

Related Projects

  • SB3-Contrib: experimental algorithms (MaskablePPO, CrossQ, QR-DQN, RecurrentPPO) — separate sb3-contrib package
  • RL Baselines3 Zoo: pre-trained agents, hyperparameters, training scripts
  • SBX: SB3 + JAX implementations for users who prefer JAX over PyTorch

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 (device="cpu" is often faster for MlpPolicy on small envs)
model = PPO("MlpPolicy", env, verbose=1, device="cpu", seed=0)

# 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, device="cpu")
env.close()

Important Notes:

  • total_timesteps is a lower bound; actual training may exceed this due to batch collection
  • Call the class method PPO.load(...) and keep the returned new model
  • 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 Box, Discrete, flat MultiDiscrete and MultiBinary actions, good for multiprocessing
  • SAC/TD3: Continuous control, off-policy, sample-efficient
  • DQN: Discrete actions, off-policy
  • HER: Replay-buffer strategy for goal-conditioned off-policy 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_space
  • reset(seed, options): Return initial observation and info dict
  • step(action): Return observation, reward, terminated, truncated, info
  • render(): Visualization (optional)
  • close(): Cleanup resources

Key Constraints:

  • Default CNN image preprocessing expects np.uint8 in range [0, 255]
  • Use channel-first format when possible (channels, height, width)
  • SB3 normalizes images automatically by dividing by 255
  • For pre-normalized float images, use channel-first layout and policy_kwargs={"normalize_images": False}
  • SB3 does NOT support Discrete or MultiDiscrete spaces with start!=0

Validation:

from stable_baselines3.common.env_checker import check_env

check_env(env, warn=True)

See the template and environment guide. The template now observes both agent and random goal coordinates, shape (4,); old shape (2,) checkpoints require retraining. gym.make("CustomEnv-v0") adds the 100-step time limit; direct CustomEnv() does not. check_env checks API consistency, not Markov sufficiency, reward correctness or learnability.

…

자주 묻는 질문

'강화학습'이란 무엇인가요?

에이전트가 행동에 대한 보상이나 벌을 받으면서 결정하는 법을 배우는 머신러닝의 한 종류입니다.

'커스텀 환경'이란 무엇인가요?

기본으로 제공되지 않는 특정 상황에서 에이전트를 훈련하려고 직접 만드는 시뮬레이션입니다.

'벡터화 환경'은 왜 사용하나요?

여러 시뮬레이션을 동시에 실행할 수 있게 해 주어, 에이전트 훈련 속도를 크게 높여 줍니다.

상세 정보

작성자의 원본 설명

Trains and evaluates single-agent reinforcement learning with Stable Baselines3 (PPO, SAC, DQN, TD3, DDPG, A2C), Gymnasium custom environments, vectorized rollouts, callbacks, and checkpoint normalization. Applies to reproducible RL experiments, continuous control, discrete actions, and SB3-Contrib recurrent or masked policies.

repo: K-Dense-AI/scientific-agent-skills

인기도

GitHub 스타
51k
순위
#3575
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬