Zum Inhalt

Trainers API

The unified Trainer is the recommended entry point for all training. The legacy per-algorithm trainers below are deprecated wrappers kept for backward compatibility.

Unified Trainer

rlox.trainer.Trainer

Unified trainer wrapping any registered algorithm.

Parameters

algorithm : str | type Algorithm name (e.g. "ppo") or the algorithm class itself. env : str Gymnasium environment ID. config : dict, optional Algorithm-specific hyperparameters forwarded to the constructor. callbacks : list[Callback], optional Training callbacks. logger : object, optional Logger instance (WandbLogger, TensorBoardLogger, etc.). seed : int Random seed (default 42). compile : bool Whether to torch.compile the policy (default False).

train(total_timesteps: int) -> dict[str, float]

Run training and return metrics dict.

save(path: str) -> None

Save training checkpoint.

predict(obs: Any, deterministic: bool = True) -> Any

Get action from the trained policy.

evaluate(n_episodes: int = 10, seed: int = 0, render: bool = False) -> dict[str, float]

Run deterministic evaluation and return episode statistics.

Parameters

n_episodes : int Number of evaluation episodes (default 10). seed : int Base seed for environment resets (default 0). render : bool Whether to render the environment (default False).

Returns

dict with keys: mean_reward, std_reward, min_reward, max_reward, mean_length, n_episodes.

enjoy(n_episodes: int = 1, seed: int = 0) -> None

Render the trained policy for visual inspection.

Parameters

n_episodes : int Number of episodes to render (default 1). seed : int Base seed for environment resets (default 0).

from_checkpoint(path: str, algorithm: str | type, env: str | None = None) -> Trainer classmethod

Restore a Trainer from a saved checkpoint.

Parameters

path : str Path to the checkpoint file. algorithm : str | type Algorithm name or class. env : str, optional Environment ID (uses checkpoint's env_id if None).

Legacy Trainers (Deprecated)

Warning

These classes are deprecated. Use Trainer('ppo', ...) etc. instead. See the Python User Guide for the migration path.

rlox.trainers.PPOTrainer = _make_legacy_trainer('ppo', 'PPOTrainer') module-attribute

rlox.trainers.SACTrainer = _make_legacy_trainer('sac', 'SACTrainer') module-attribute

rlox.trainers.DQNTrainer = _make_legacy_trainer('dqn', 'DQNTrainer') module-attribute

rlox.trainers.A2CTrainer = _make_legacy_trainer('a2c', 'A2CTrainer') module-attribute

rlox.trainers.TD3Trainer = _make_legacy_trainer('td3', 'TD3Trainer') module-attribute

rlox.trainers.MAPPOTrainer = _make_legacy_trainer('mappo', 'MAPPOTrainer') module-attribute

rlox.trainers.DreamerV3Trainer = _make_legacy_trainer('dreamer', 'DreamerV3Trainer') module-attribute

rlox.trainers.IMPALATrainer = _make_legacy_trainer('impala', 'IMPALATrainer') module-attribute