Algorithms¶
PPO¶
- class rsl_rl.algorithms.ppo.PPO[source]¶
Proximal Policy Optimization algorithm.
- Reference:
Schulman et al. “Proximal policy optimization algorithms.” arXiv preprint arXiv:1707.06347 (2017).
- __init__(actor, critic, storage, num_learning_epochs=5, num_mini_batches=4, clip_param=0.2, gamma=0.99, lam=0.95, value_loss_coef=1.0, entropy_coef=0.01, learning_rate=0.001, max_grad_norm=1.0, optimizer='adam', use_clipped_value_loss=True, schedule='adaptive', desired_kl=0.01, normalize_advantage_per_mini_batch=False, use_mixed_precision=False, device='cpu', rnd_cfg=None, symmetry_cfg=None, multi_gpu_cfg=None, grad_reduce_bucket_mb=25)[source]¶
Initialize the algorithm with models, storage, and optimization settings.
- Parameters:
actor (MLPModel)
critic (MLPModel)
storage (RolloutStorage)
num_learning_epochs (int)
num_mini_batches (int)
clip_param (float)
gamma (float)
lam (float)
value_loss_coef (float)
entropy_coef (float)
learning_rate (float)
max_grad_norm (float)
optimizer (str)
use_clipped_value_loss (bool)
schedule (str)
desired_kl (float)
normalize_advantage_per_mini_batch (bool)
use_mixed_precision (bool)
device (str)
rnd_cfg (dict | None)
symmetry_cfg (dict | None)
multi_gpu_cfg (dict | None)
grad_reduce_bucket_mb (float)
- Return type:
None
- act(obs)[source]¶
Sample actions and store transition data.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
torch.Tensor
- process_env_step(obs, rewards, dones, extras)[source]¶
Record one environment step and return per-environment values that the logger sums over each episode.
- Parameters:
obs (tensordict.TensorDict)
rewards (torch.Tensor)
dones (torch.Tensor)
extras (dict[str, torch.Tensor])
- Return type:
dict[str, torch.Tensor]
- compute_returns(obs)[source]¶
Compute return and advantage targets from stored transitions.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
None
- update()[source]¶
Run optimization epochs over stored batches and return mean losses and statistics.
- Return type:
tuple[dict[str, float], dict[str, float]]
- get_default_load_cfg()[source]¶
Return the default selection for resuming this algorithm’s own checkpoints.
- Return type:
dict
- load(loaded_dict, load_cfg, strict)[source]¶
Load specified models from a saved dict.
- Parameters:
loaded_dict (dict)
load_cfg (dict | None)
strict (bool)
- Return type:
bool
- compile(mode=None)[source]¶
Compile actor and critic with
torch.compile.See
compile_model()for the set of accepted modes.- Parameters:
mode (str | None) –
torch.compilemode. Defaults toNone, in which case compilation is disabled.- Return type:
None
SAC¶
- class rsl_rl.algorithms.sac.SAC[source]¶
Soft Actor-Critic algorithm.
Inspired by FlashSAC, this implementation supports categorical critics, reward normalization, temporally correlated exploration noise, and batch-normalized residual actor and critic networks. It also supports the library’s symmetry extension and CUDA graph updates.
References
Haarnoja et al. “Soft Actor-Critic Algorithms and Applications.” arXiv preprint arXiv:1812.05905 (2018).
Kim et al. “FlashSAC: Fast and Stable Off-Policy Reinforcement Learning for High-Dimensional Robot Control.” arXiv preprint arXiv:2604.04539 (2026).
- __init__(actor, critics, storage, num_updates=16, batch_size=2048, num_return_steps=3, gamma=0.98, tau=0.01, actor_update_interval=2, num_warmup_transitions=100000, actor_learning_rate=0.0003, critic_learning_rate=0.0003, alpha_learning_rate=0.0003, max_grad_norm=None, optimizer='adam', weight_decay=0.0, init_alpha=0.01, target_entropy=None, target_entropy_std=0.15, critic_loss_type='categorical', num_bins=101, value_range=(-5.0, 5.0), reward_normalization=True, reward_normalization_max_return=5.0, exploration_type='held', noise_repeat_exponent=2.0, max_noise_repeat_steps=16, learning_rate_schedule='constant', final_learning_rate_ratio=0.5, num_schedule_updates=None, use_mixed_precision=False, use_cuda_graph=False, device='cpu', symmetry_cfg=None, multi_gpu_cfg=None, grad_reduce_bucket_mb=25)[source]¶
Initialize the algorithm with models, storage, and optimization settings.
- Parameters:
actor (MLPModel)
storage (ReplayBuffer)
num_updates (int)
batch_size (int)
num_return_steps (int)
gamma (float)
tau (float)
actor_update_interval (int)
num_warmup_transitions (int)
actor_learning_rate (float)
critic_learning_rate (float)
alpha_learning_rate (float)
max_grad_norm (float | None)
optimizer (str)
weight_decay (float)
init_alpha (float)
target_entropy (float | None)
target_entropy_std (float | None)
critic_loss_type (str)
num_bins (int)
value_range (tuple[float, float])
reward_normalization (bool)
reward_normalization_max_return (float)
exploration_type (str)
noise_repeat_exponent (float)
max_noise_repeat_steps (int)
learning_rate_schedule (str)
final_learning_rate_ratio (float)
num_schedule_updates (int | None)
use_mixed_precision (bool)
use_cuda_graph (bool)
device (str)
symmetry_cfg (dict | None)
multi_gpu_cfg (dict | None)
grad_reduce_bucket_mb (float)
- Return type:
None
- critics: torch.nn.ModuleList¶
The ensemble of state-action critic models.
- target_critics: torch.nn.ModuleList¶
The ensemble of target critic models.
- act(obs)¶
Sample actions and store transition data.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
torch.Tensor
- process_env_step(obs, rewards, dones, extras)¶
Record one environment step and return per-environment values that the logger sums over each episode.
Final observations are used as next observations for environments that reset.
- Parameters:
obs (tensordict.TensorDict)
rewards (torch.Tensor)
dones (torch.Tensor)
extras (dict)
- Return type:
dict[str, torch.Tensor]
- compute_returns(obs)[source]¶
Defer return computation to replay sampling in
update()(no-op).- Parameters:
obs (tensordict.TensorDict)
- Return type:
None
- update()[source]¶
Update normalizers and models from replay samples and return mean losses and statistics.
- Return type:
tuple[dict[str, float], dict[str, float]]
- save()[source]¶
Return a dict of models, optimizers, temperature, and update counters for saving.
- Return type:
dict
- get_default_load_cfg()[source]¶
Return the default selection for resuming this algorithm’s own checkpoints.
- Return type:
dict
- load(loaded_dict, load_cfg, strict)[source]¶
Load specified models from a saved dict.
Note
Loading an actor disables uniform action sampling during warm-up.
- Parameters:
loaded_dict (dict)
load_cfg (dict | None)
strict (bool)
- Return type:
bool
- compile(mode=None)[source]¶
Compile actor and critics with
torch.compile.See
compile_model()for the set of accepted modes.- Parameters:
mode (str | None) –
torch.compilemode. Defaults toNone, in which case compilation is disabled.- Return type:
None
- broadcast_parameters()¶
Broadcast model parameters and training state to all GPUs.
- Return type:
None
Distillation¶
- class rsl_rl.algorithms.distillation.Distillation[source]¶
Distillation algorithm for training a student model to mimic a teacher model.
- Reference:
Ross et al. “A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning.” arXiv preprint arXiv:1011.0686 (2011).
- teacher_loaded: bool = False¶
Indicates whether the teacher model parameters have been loaded.
- __init__(student, teacher, storage, num_learning_epochs=1, gradient_length=15, learning_rate=0.001, max_grad_norm=None, loss_type='mse', optimizer='adam', use_mixed_precision=False, device='cpu', multi_gpu_cfg=None, grad_reduce_bucket_mb=25, **kwargs)[source]¶
Initialize the algorithm with models, storage, and optimization settings.
- Parameters:
student (MLPModel)
teacher (MLPModel)
storage (RolloutStorage)
num_learning_epochs (int)
gradient_length (int)
learning_rate (float)
max_grad_norm (float | None)
loss_type (str)
optimizer (str)
use_mixed_precision (bool)
device (str)
multi_gpu_cfg (dict | None)
grad_reduce_bucket_mb (float)
kwargs (dict)
- Return type:
None
- act(obs)[source]¶
Sample actions and store transition data.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
torch.Tensor
- process_env_step(obs, rewards, dones, extras)[source]¶
Record one environment step and return per-environment values that the logger sums over each episode.
- Parameters:
obs (tensordict.TensorDict)
rewards (torch.Tensor)
dones (torch.Tensor)
extras (dict[str, torch.Tensor])
- Return type:
dict[str, torch.Tensor]
- compute_returns(obs)[source]¶
No-op since distillation does not use return targets.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
None
- update()[source]¶
Run optimization epochs over stored batches and return mean losses and statistics.
- Return type:
tuple[dict[str, float], dict[str, float]]
- train_mode()[source]¶
Set train mode for the student and keep the teacher in eval mode.
- Return type:
None
- get_default_load_cfg()[source]¶
Return the default selection for resuming this algorithm’s own checkpoints.
- Return type:
dict
- load(loaded_dict, load_cfg, strict)[source]¶
Load specified models from a saved dict.
- Parameters:
loaded_dict (dict)
load_cfg (dict | None)
strict (bool)
- Return type:
bool
- compile(mode=None)[source]¶
Compile student and teacher with
torch.compile.See
compile_model()for the set of accepted modes.- Parameters:
mode (str | None) –
torch.compilemode. Defaults toNone, in which case compilation is disabled.- Return type:
None