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
SHAC¶
Short-horizon actor-critic training with differentiable dynamics.
- rsl_rl.algorithms.shac.compute_lambda_returns(rewards, dones, values, gamma, lam)[source]¶
Compute TD(lambda) targets, retaining terminal rewards and the final bootstrap state.
- Parameters:
rewards (torch.Tensor)
dones (torch.Tensor)
values (torch.Tensor)
gamma (float)
lam (float)
- Return type:
torch.Tensor
- class rsl_rl.algorithms.shac.SHAC[source]¶
Optimize short-horizon differentiable returns with a learned value bootstrap.
- Reference:
Xu et al. “Accelerated Policy Learning with Parallel Differentiable Simulation.” ICLR (2022).
- __init__(actor, critic, task, obs_groups, action_history, learned_dynamics=None, updates_per_step=0.4, update_schedule='after_warmup', num_policy_updates=1, horizon=32, policy_batch_size=4096, gamma=0.99, max_step_reward=None, action_noise=0.1, normalize_before_action=True, use_reference_action=False, actor_ema_halflife=None, lam=0.95, num_critic_epochs=5, num_critic_mini_batches=4, critic_survival_weighting=True, critic_bootstrap_clipping=True, critic_shuffle_each_epoch=True, learning_rate=0.0002, actor_learning_rate=None, actor_learning_rate_multiplier=1.0, actor_learning_rate_decay_iterations=300, actor_learning_rate_decay_return=None, actor_learning_rate_decay_start=None, max_episode_length=None, muon_models=(), max_grad_norm=1.0, num_schedule_updates=250000, final_learning_rate_ratio=0.03, learning_rate_schedule_unit='learner_updates', use_mixed_precision=False, use_cuda_graph=False, device='cpu', multi_gpu_cfg=None)[source]¶
Initialize short-horizon policy and value updates with the selected dynamics.
- Parameters:
actor (MLPModel | SuperMimicActor)
critic (MLPModel)
task (DifferentiableTask)
obs_groups (dict[str, list[str]])
action_history (torch.Tensor)
learned_dynamics (LearnedDynamics | None)
updates_per_step (float)
update_schedule (str)
num_policy_updates (int)
horizon (int)
policy_batch_size (int)
gamma (float)
max_step_reward (float | None)
action_noise (float)
normalize_before_action (bool)
use_reference_action (bool)
actor_ema_halflife (int | None)
lam (float)
num_critic_epochs (int)
num_critic_mini_batches (int)
critic_survival_weighting (bool)
critic_bootstrap_clipping (bool)
critic_shuffle_each_epoch (bool)
learning_rate (float)
actor_learning_rate (float | None)
actor_learning_rate_multiplier (float)
actor_learning_rate_decay_iterations (int)
actor_learning_rate_decay_return (float | None)
actor_learning_rate_decay_start (int | None)
max_episode_length (int | torch.Tensor | None)
muon_models (tuple[str, ...])
max_grad_norm (float)
num_schedule_updates (int)
final_learning_rate_ratio (float)
learning_rate_schedule_unit (str)
use_mixed_precision (bool)
use_cuda_graph (bool)
device (str)
multi_gpu_cfg (dict | None)
- Return type:
None
- act(obs)¶
Record the physical start and sample an action from the collection policy.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
torch.Tensor
- process_env_step(obs, rewards, dones, extras)¶
Record the transition and, with learned dynamics, its physical successor.
- Parameters:
obs (tensordict.TensorDict)
rewards (torch.Tensor)
dones (torch.Tensor)
extras (dict)
- Return type:
dict[str, torch.Tensor]
- compute_returns(obs)[source]¶
Replay and imagination construct their own return targets during update.
- Parameters:
obs (tensordict.TensorDict)
- Return type:
None
- update()[source]¶
Run accumulated learner updates and return mean losses and statistics.
- Return type:
tuple[dict[str, float], dict[str, float]]
- eval_mode()[source]¶
Select deterministic deployment inference without updating actor moments.
- Return type:
None
- get_default_load_cfg()[source]¶
Return the default selection for resuming this algorithm’s own checkpoints, including the world model.
- Return type:
dict
- load(loaded_dict, load_cfg, strict)[source]¶
Restore a deployment actor or resume all configured models.
- Parameters:
loaded_dict (dict)
load_cfg (dict | None)
strict (bool)
- Return type:
bool
- get_policy()[source]¶
Return the actor with its live normalization and optional averaged weights.
- Return type:
- compile(mode=None)[source]¶
Compile differentiable dynamics and stateless actor forwards using the standard mode restrictions.
- Parameters:
mode (str | None)
- Return type:
None
- static construct_algorithm(obs, env, cfg, device)¶
Resolve the task and explicit network configs, inferring synthetic feature widths once.
- broadcast_parameters()¶
Synchronize learned model state while preserving each rank’s local collection histories.
- Return type:
None
- class rsl_rl.algorithms.shac.ActorLearningRateMultiplier[source]¶
Raise the actor learning rate early in training and decay it to its base value.
- __init__(multiplier, decay_iterations, decay_return, decay_start, max_episode_length, num_envs, device)[source]¶
Validate the triggers and allocate device accumulators for episode returns.
- Parameters:
multiplier (float)
decay_iterations (int)
decay_return (float | None)
decay_start (int | None)
max_episode_length (int | torch.Tensor | None)
num_envs (int)
device (str)
- Return type:
None
- record_rewards(rewards, dones)[source]¶
Accumulate the normalized returns of completed episodes using only device operations.
- Parameters:
rewards (torch.Tensor)
dones (torch.Tensor)
- Return type:
None
- update_decay_from_returns(num_learner_updates, is_multi_gpu)[source]¶
Start the decay once the mean completed episode return reaches its threshold.
- Parameters:
num_learner_updates (int)
is_multi_gpu (bool)
- Return type:
None
- reset_episode_returns()[source]¶
Discard the accumulated returns of completed and in-progress episodes.
- Return type:
None
- class rsl_rl.algorithms.shac.ActorEMA[source]¶
Maintain a deployment actor with exponentially averaged parameters.
- __init__(actor, halflife)[source]¶
Start the average at the current actor parameters.
- Parameters:
actor (MLPModel | SuperMimicActor)
halflife (int)
- Return type:
None
- update_parameters(finite)¶
Average the actor after a successful step using the half-life and warm-start decay.
- Parameters:
finite (torch.Tensor)
- Return type:
None
- get_policy()¶
Return the averaged parameters with the live actor’s normalization buffers.
- Return type:
- state_dict()[source]¶
Return the deployment actor state and the number of averaged steps under their checkpoint keys.
- Return type:
dict
- load_state_dict(loaded_dict, strict)[source]¶
Restore the average, or restart it from the loaded live actor when the checkpoint has none.
- Parameters:
loaded_dict (dict)
strict (bool)
- Return type:
None
- broadcast_parameters()¶
Synchronize the average and its step count from rank 0.
- Return type:
None