|
| 1 | +# SAC Trainer Configuration for HalfCheetah-v4 |
| 2 | +# Run with `python sota-implementations/sac_trainer/train.py --config-name=config_async` |
| 3 | +# This configuration uses the new configurable trainer system and matches SOTA SAC implementation |
| 4 | + |
| 5 | +defaults: |
| 6 | + |
| 7 | + - transform@transform0: step_counter |
| 8 | + - transform@transform1: double_to_float |
| 9 | + - transform@transform2: reward_sum |
| 10 | + - transform@transform3: flatten_tensordict |
| 11 | + |
| 12 | + - env@training_env: batched_env |
| 13 | + - env@training_env.create_env_fn: transformed_env |
| 14 | + - env@training_env.create_env_fn.base_env: gym |
| 15 | + - transform@training_env.create_env_fn.transform: compose |
| 16 | + |
| 17 | + - model@models.policy_model: tanh_normal |
| 18 | + - model@models.value_model: value |
| 19 | + - model@models.qvalue_model: value |
| 20 | + |
| 21 | + - network@networks.policy_network: mlp |
| 22 | + - network@networks.value_network: mlp |
| 23 | + - network@networks.qvalue_network: mlp |
| 24 | + |
| 25 | + - collector@collector: multi_async |
| 26 | + |
| 27 | + - replay_buffer@replay_buffer: base |
| 28 | + - storage@replay_buffer.storage: lazy_tensor |
| 29 | + - writer@replay_buffer.writer: round_robin |
| 30 | + - sampler@replay_buffer.sampler: random |
| 31 | + - trainer@trainer: sac |
| 32 | + - optimizer@optimizer: adam |
| 33 | + - loss@loss: sac |
| 34 | + - target_net_updater@target_net_updater: soft |
| 35 | + - logger@logger: wandb |
| 36 | + - _self_ |
| 37 | + |
| 38 | +# Network configurations |
| 39 | +networks: |
| 40 | + policy_network: |
| 41 | + out_features: 12 # HalfCheetah action space is 6-dimensional (loc + scale) = 2 * 6 |
| 42 | + in_features: 17 # HalfCheetah observation space is 17-dimensional |
| 43 | + num_cells: [256, 256] |
| 44 | + |
| 45 | + value_network: |
| 46 | + out_features: 1 # Value output |
| 47 | + in_features: 17 # HalfCheetah observation space |
| 48 | + num_cells: [256, 256] |
| 49 | + |
| 50 | + qvalue_network: |
| 51 | + out_features: 1 # Q-value output |
| 52 | + in_features: 23 # HalfCheetah observation space (17) + action space (6) |
| 53 | + num_cells: [256, 256] |
| 54 | + |
| 55 | +# Model configurations |
| 56 | +models: |
| 57 | + policy_model: |
| 58 | + return_log_prob: true |
| 59 | + in_keys: ["observation"] |
| 60 | + param_keys: ["loc", "scale"] |
| 61 | + out_keys: ["action"] |
| 62 | + network: ${networks.policy_network} |
| 63 | + # Configure NormalParamExtractor for higher exploration |
| 64 | + scale_mapping: "biased_softplus_2.0" # Higher bias for more exploration (default: 1.0) |
| 65 | + scale_lb: 1e-2 # Minimum scale value (default: 1e-4) |
| 66 | + |
| 67 | + qvalue_model: |
| 68 | + in_keys: ["observation", "action"] |
| 69 | + out_keys: ["state_action_value"] |
| 70 | + network: ${networks.qvalue_network} |
| 71 | + |
| 72 | +transform0: |
| 73 | + max_steps: 1000 |
| 74 | + step_count_key: "step_count" |
| 75 | + |
| 76 | +transform1: |
| 77 | + # DoubleToFloatTransform - converts double precision to float to fix dtype mismatch |
| 78 | + in_keys: null |
| 79 | + out_keys: null |
| 80 | + |
| 81 | +transform2: |
| 82 | + # RewardSumTransform - sums up the rewards |
| 83 | + in_keys: ["reward"] |
| 84 | + out_keys: ["reward_sum"] |
| 85 | + |
| 86 | +training_env: |
| 87 | + num_workers: 4 |
| 88 | + create_env_fn: |
| 89 | + base_env: |
| 90 | + env_name: HalfCheetah-v4 |
| 91 | + transform: |
| 92 | + transforms: |
| 93 | + - ${transform0} |
| 94 | + - ${transform1} |
| 95 | + - ${transform2} |
| 96 | + _partial_: true |
| 97 | + |
| 98 | +# Loss configuration |
| 99 | +loss: |
| 100 | + actor_network: ${models.policy_model} |
| 101 | + qvalue_network: ${models.qvalue_model} |
| 102 | + target_entropy: "auto" |
| 103 | + loss_function: l2 |
| 104 | + alpha_init: 1.0 |
| 105 | + delay_qvalue: true |
| 106 | + num_qvalue_nets: 2 |
| 107 | + |
| 108 | +target_net_updater: |
| 109 | + tau: 0.001 |
| 110 | + |
| 111 | +# Optimizer configuration |
| 112 | +optimizer: |
| 113 | + lr: 3.0e-4 |
| 114 | + |
| 115 | +# Collector configuration |
| 116 | +collector: |
| 117 | + create_env_fn: ${training_env} |
| 118 | + policy: ${models.policy_model} |
| 119 | + total_frames: 5_000_000 |
| 120 | + frames_per_batch: 1000 |
| 121 | + num_workers: 8 |
| 122 | + # Incompatible with async collection |
| 123 | + init_random_frames: 0 |
| 124 | + track_policy_version: true |
| 125 | + extend_buffer: true |
| 126 | + _partial_: true |
| 127 | + |
| 128 | +# Replay buffer configuration |
| 129 | +replay_buffer: |
| 130 | + storage: |
| 131 | + max_size: 10_000 |
| 132 | + device: cpu |
| 133 | + ndim: 1 |
| 134 | + sampler: |
| 135 | + writer: |
| 136 | + compilable: false |
| 137 | + batch_size: 256 |
| 138 | + shared: true |
| 139 | + transform: ${transform3} |
| 140 | + |
| 141 | +logger: |
| 142 | + exp_name: sac_halfcheetah_v4 |
| 143 | + offline: false |
| 144 | + project: torchrl-sota-implementations |
| 145 | + |
| 146 | +# Trainer configuration |
| 147 | +trainer: |
| 148 | + collector: ${collector} |
| 149 | + optimizer: ${optimizer} |
| 150 | + replay_buffer: ${replay_buffer} |
| 151 | + target_net_updater: ${target_net_updater} |
| 152 | + loss_module: ${loss} |
| 153 | + logger: ${logger} |
| 154 | + total_frames: ${collector.total_frames} |
| 155 | + frame_skip: 1 |
| 156 | + clip_grad_norm: false # SAC typically doesn't use gradient clipping |
| 157 | + clip_norm: null |
| 158 | + progress_bar: true |
| 159 | + seed: 42 |
| 160 | + save_trainer_interval: 25000 # Match SOTA eval_iter |
| 161 | + log_interval: 25000 |
| 162 | + save_trainer_file: null |
| 163 | + optim_steps_per_batch: 16 # Match SOTA utd_ratio |
| 164 | + async_collection: true |
0 commit comments