minimal_mjx.learning¶
Training policies and loading them back. See Training a policy for how these fit together.
minimal_mjx.learning.training
¶
Classes:
| Name | Description |
|---|---|
Resume |
What a continued run inherits from the checkpoints already in its directory. |
Functions:
| Name | Description |
|---|---|
setup_ppo |
Default handler: brax PPO. Returns |
find_checkpoints |
The run's checkpoint directories, named by step and ordered by it. |
find_resume |
Where training left off in |
apply_resume |
A copy of |
create_training_directory |
Create the run output directory, refusing to clobber an earlier run. |
train |
Train a policy on the given environment. |
Resume
dataclass
¶
What a continued run inherits from the checkpoints already in its directory.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
|
step |
int
|
|
epoch |
int
|
|
Source code in src/minimal_mjx/learning/training.py
setup_ppo
¶
setup_ppo(
ppo_params: dict,
network_params: dict,
resumed: Resume | None = None,
)
Default handler: brax PPO. Returns (train_fn, network_factory).
train_fn is a :func:functools.partial of the brax PPO trainer with all
algorithm params pre-bound; network_factory builds the PPO networks.
Source code in src/minimal_mjx/learning/training.py
find_checkpoints
¶
The run's checkpoint directories, named by step and ordered by it.
Source code in src/minimal_mjx/learning/training.py
find_resume
¶
find_resume(output_dir) -> Resume | None
Where training left off in output_dir, or None if it never checkpointed.
The epoch count is the number of checkpoints past the one written at step 0, which is what a run writes per epoch; taking it from the directory keeps it right across several continuations, and across a schedule whose epochs changed size.
Source code in src/minimal_mjx/learning/training.py
apply_resume
¶
apply_resume(ppo_params: dict, resumed: Resume) -> dict
A copy of ppo_params asking the algorithm for only the steps the run still owes.
num_timesteps is the run's whole budget, so continuing a run is a matter of
raising it: the algorithm is handed the difference.
Source code in src/minimal_mjx/learning/training.py
create_training_directory
¶
Create the run output directory, refusing to clobber an earlier run.
If the directory already exists but holds nothing a run produced -- only a stale
config, or the run id of a job that died before its first epoch -- it is reused.
overwrite reuses it whatever it holds (e.g. for scratch runs), and so does
resume, for a run that continues the checkpoints already there.
Source code in src/minimal_mjx/learning/training.py
train
¶
train(
env,
eval_env,
run_dir,
train_fn_params,
network_factory_params,
handle_params,
run=None,
progress_cls=None,
resume=False,
overwrite=False,
)
Train a policy on the given environment.
Creates run_dir, resolves the training algorithm via handle_params
then wraps the resulting train_fn with progress/checkpoint callbacks and runs
it. Saving the run's config is up to the caller (see
:meth:minimal_mjx.utils.config.Config.save).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Training environment. |
required | |
eval_env
|
Evaluation environment used for periodic rollouts. |
required | |
run_dir
|
Directory for checkpoints and progress output. |
required | |
train_fn_params
|
Algorithmic parameters for your specific training algo. |
required | |
network_factory_params
|
Keyword arguments for the network factory. |
required | |
run
|
(optional) Experiment-tracking handle (e.g. a wandb run). |
None
|
|
handle_params
|
Callable
|
required | |
progress_cls
|
(optional) Progress callback class, built as
|
None
|
|
resume
|
(optional) If True, continue the checkpoints already in |
False
|
|
overwrite
|
(optional) If True, train into |
False
|
Returns:
| Type | Description |
|---|---|
|
Tuple |
Source code in src/minimal_mjx/learning/training.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
minimal_mjx.learning.inference
¶
Inference utilities for loading and interacting with trained RL models.
Functions:
| Name | Description |
|---|---|
get_step_reset |
Return (step, reset) functions, jitted if using JAX backend. |
get_all_models |
Return all checkpoint directories in |
get_last_model |
Return the most recent checkpoint directory in |
load_policy |
Load and return a policy from |
get_params |
Load and return model parameters from |
get_step_reset
¶
Return (step, reset) functions, jitted if using JAX backend.
Source code in src/minimal_mjx/learning/inference.py
get_all_models
¶
Return all checkpoint directories in run_dir, sorted by step if requested.
Source code in src/minimal_mjx/learning/inference.py
get_last_model
¶
Return the most recent checkpoint directory in run_dir.
Source code in src/minimal_mjx/learning/inference.py
load_policy
¶
load_policy(
run_dir: Path | str,
deterministic: bool = True,
checkpoint_path: Optional[Path] = None,
) -> Callable
Load and return a policy from checkpoint_path, or the last checkpoint in
run_dir.
Source code in src/minimal_mjx/learning/inference.py
get_params
¶
Load and return model parameters from path, or the last checkpoint in
run_dir.