|
| 1 | +(config)= |
| 2 | + |
| 3 | +# Configuration |
| 4 | + |
| 5 | +## Hyperparameter yaml syntax |
| 6 | + |
| 7 | +The syntax used in `hyperparameters/algo_name.yml` for setting |
| 8 | +hyperparameters (likewise the syntax to [overwrite |
| 9 | +hyperparameters](https://github.com/DLR-RM/rl-baselines3-zoo#overwrite-hyperparameters) |
| 10 | +on the cli) may be specialized if the argument is a function. See |
| 11 | +examples in the `hyperparameters/` directory. For example: |
| 12 | + |
| 13 | +- Specify a linear schedule for the learning rate: |
| 14 | + |
| 15 | +```yaml |
| 16 | +learning_rate: lin_0.012486195510232303 |
| 17 | +``` |
| 18 | +
|
| 19 | +Specify a different activation function for the network: |
| 20 | +
|
| 21 | +```yaml |
| 22 | +policy_kwargs: "dict(activation_fn=nn.ReLU)" |
| 23 | +``` |
| 24 | +
|
| 25 | +For a custom policy: |
| 26 | +
|
| 27 | +```yaml |
| 28 | +policy: my_package.MyCustomPolicy # for instance stable_baselines3.ppo.MlpPolicy |
| 29 | +``` |
| 30 | +
|
| 31 | +## Env Normalization |
| 32 | +
|
| 33 | +In the hyperparameter file, `normalize: True` means that the training |
| 34 | +environment will be wrapped in a |
| 35 | +[VecNormalize](https://github.com/DLR-RM/stable-baselines3/blob/master/stable_baselines3/common/vec_env/vec_normalize.py#L13) |
| 36 | +wrapper. |
| 37 | + |
| 38 | +[Normalization |
| 39 | +uses](https://github.com/DLR-RM/rl-baselines3-zoo/issues/64) the |
| 40 | +default parameters of `VecNormalize`, with the exception of `gamma` |
| 41 | +which is set to match that of the agent. This can be |
| 42 | +[overridden](https://github.com/DLR-RM/rl-baselines3-zoo/blob/v0.10.0/hyperparams/sac.yml#L239) |
| 43 | +using the appropriate `hyperparameters/algo_name.yml`, e.g. |
| 44 | + |
| 45 | +```yaml |
| 46 | +normalize: "{'norm_obs': True, 'norm_reward': False}" |
| 47 | +``` |
| 48 | + |
| 49 | +## Env Wrappers |
| 50 | + |
| 51 | +You can specify in the hyperparameter config one or more wrapper to use |
| 52 | +around the environment: |
| 53 | + |
| 54 | +for one wrapper: |
| 55 | + |
| 56 | +```yaml |
| 57 | +env_wrapper: gym_minigrid.wrappers.FlatObsWrapper |
| 58 | +``` |
| 59 | + |
| 60 | +for multiple, specify a list: |
| 61 | + |
| 62 | +```yaml |
| 63 | +env_wrapper: |
| 64 | + - rl_zoo3.wrappers.TruncatedOnSuccessWrapper: |
| 65 | + reward_offset: 1.0 |
| 66 | + - sb3_contrib.common.wrappers.TimeFeatureWrapper |
| 67 | +``` |
| 68 | + |
| 69 | +Note that you can easily specify parameters too. |
| 70 | + |
| 71 | +By default, the environment is wrapped with a `Monitor` wrapper to |
| 72 | +record episode statistics. You can specify arguments to it using |
| 73 | +`monitor_kwargs` parameter to log additional data. That data *must* be |
| 74 | +present in the info dictionary at the last step of each episode. |
| 75 | + |
| 76 | +For instance, for recording success with goal envs |
| 77 | +(e.g. `FetchReach-v1`): |
| 78 | + |
| 79 | +```yaml |
| 80 | +monitor_kwargs: dict(info_keywords=('is_success',)) |
| 81 | +``` |
| 82 | + |
| 83 | +or recording final x position with `Ant-v3`: |
| 84 | + |
| 85 | +```yaml |
| 86 | +monitor_kwargs: dict(info_keywords=('x_position',)) |
| 87 | +``` |
| 88 | + |
| 89 | +Note: for known `GoalEnv` like `FetchReach`, |
| 90 | +`info_keywords=('is_success',)` is actually the default. |
| 91 | + |
| 92 | +You can also specify environment keyword arguments with: |
| 93 | + |
| 94 | +```yaml |
| 95 | +env_kwargs: |
| 96 | + gravity: 0.0 |
| 97 | +``` |
| 98 | + |
| 99 | +## VecEnvWrapper |
| 100 | + |
| 101 | +You can specify which `VecEnvWrapper` to use in the config, the same |
| 102 | +way as for env wrappers (see above), using the `vec_env_wrapper` key: |
| 103 | + |
| 104 | +For instance: |
| 105 | + |
| 106 | +```yaml |
| 107 | +vec_env_wrapper: stable_baselines3.common.vec_env.VecMonitor |
| 108 | +``` |
| 109 | + |
| 110 | +Note: `VecNormalize` is supported separately using `normalize` |
| 111 | +keyword, and `VecFrameStack` has a dedicated keyword `frame_stack`. |
| 112 | + |
| 113 | +## Callbacks |
| 114 | + |
| 115 | +Following the same syntax as env wrappers, you can also add custom |
| 116 | +callbacks to use during training. |
| 117 | + |
| 118 | +```yaml |
| 119 | +callback: |
| 120 | + - rl_zoo3.callbacks.ParallelTrainCallback: |
| 121 | + gradient_steps: 256 |
| 122 | +``` |
0 commit comments