The config file¶
Every run is described by one YAML file. The example scripts read it through
Config, which turns its sections into the plain
arguments the library functions take. Here is example/cheetah.yaml:
name: test
save_dir: example/results/cheetah
description: ""
algorithm: ppo
env: Cheetah
backend: np # jnp or np. Always uses jnp for training
env_config:
ctrl_dt: 0.01
sim_dt: 0.01
action_scale: 1.0
history_length: 5
ideal_base_height: 0.5
ideal_base_vel: 0.5
min_base_height: 0.3
add_random_joint_state: False
add_random_pitch: False
reward:
weights:
run: 1.0
height: 10.0
energy: 1.0
alive: 1.0
done: 0
termination:
enabled: true # Enable or disable early termination
base_height: 0.2
learning_params:
ppo_params:
action_repeat: 1
batch_size: 64
clipping_epsilon: 0.1
deterministic_eval: true
discounting: 0.98
entropy_cost: 0.01
episode_length: 500
learning_rate: 0.0005
max_grad_norm: 1.0
normalize_observations: true
num_envs: 128
num_evals: 15
num_minibatches: 2
num_timesteps: 50000000
num_updates_per_batch: 4
reward_scaling: 1.0
unroll_length: 20
network_params:
policy_hidden_layer_sizes: [64, 64]
value_hidden_layer_sizes: [64, 64]
Top-level keys¶
| Key | Read as | Meaning |
|---|---|---|
name |
cfg.name |
Run name. The run directory is save_dir/name. A run named test may be overwritten and does not record a git hash. |
save_dir |
cfg.save_dir |
Parent directory for all runs made from this config |
description |
Free text for your own notes | |
algorithm |
cfg.algorithm |
Training algorithm; defaults to ppo |
env |
cfg.env_name |
Environment class name, which create_environment maps to a class |
backend |
cfg.backend |
np or jnp for rollouts. Training always uses jnp. |
git_hash |
Not in your config: Config.save adds it to the copy saved in the run directory |
cfg.run_dir combines save_dir and name, so example/cheetah.yaml trains into
example/results/cheetah/test/.
env_config¶
The env_config section is available as
cfg.env_params. Environments do not
receive it directly: example/create_environment.py reads the values out of it and
passes them to the environment's constructor as arguments. Every environment takes
these:
| Key | Constructor argument | Meaning |
|---|---|---|
ctrl_dt |
ctrl_dt |
Control period in seconds: how often the policy acts. This is env.dt. |
sim_dt |
sim_dt |
Physics timestep. Each step runs ctrl_dt / sim_dt physics substeps. |
reward.weights |
reward_weights |
One weight per reward term. The keys must match the names your reward_function returns. |
Any other key is yours to define. To use it, add a constructor argument to your
environment and pass the value in create_environment. Cheetah takes
action_scale this way and uses it in step; the remaining keys in the example (history_length,
ideal_base_height, termination, ...) show the kind of settings an environment might
take, but Cheetah does not use them.
Missing keys raise an error
Reading a key from cfg.env_params that is missing from the YAML raises an error,
so add every key that create_environment reads to the config.
learning_params¶
| Section | Read as | Meaning |
|---|---|---|
ppo_params |
cfg.ppo_params |
Passed as keyword arguments to Brax's PPO train function. See the Brax PPO docs for every option. |
network_params |
cfg.network_params |
Passed to Brax's make_ppo_networks, for example the hidden layer sizes |
A few PPO settings worth knowing:
num_timesteps: total environment steps for the run. When resuming, this is the total budget, not the steps still to go.num_envs: environments simulated in parallel.num_evals: how many times training pauses to evaluate the policy. Each evaluation also writes a checkpoint and a row ofprogress.csv.episode_length: steps per episode before the environment is reset.normalize_observations: keep a running mean and variance of observations. The normalizer is saved inside each checkpoint.
Using your own layout¶
Library functions never read the YAML directly. To use a different layout, subclass
Config and override the properties that differ:
class MyConfig(mm.Config):
@property
def ppo_params(self) -> dict:
return self.cfg.training.ppo.to_dict()
Or skip Config and pass run_dir, ppo_params and network_params to
train yourself.