File size: 4,638 Bytes
91263c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# coding=utf-8
# Copyright 2024 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Default SAC config values."""

import ml_collections


def get_config():
    """Returns default config."""
    config = ml_collections.ConfigDict()

    # ================================================= #
    # Placeholders.
    # ================================================= #
    # These values will be filled at runtime once the gym.Env is loaded.
    obs_dim = ml_collections.FieldReference(None, field_type=int)
    action_dim = ml_collections.FieldReference(None, field_type=int)
    action_range = ml_collections.FieldReference(None, field_type=tuple)
    chunk_len = ml_collections.FieldReference(None, field_type=int)

    # ================================================= #
    # Main parameters.
    # ================================================= #
    config.save_dir = "./rl_runs/"

    # Set this to True to allow CUDA to find the best convolutional algorithm to
    # use for the given parameters. When False, cuDNN will deterministically
    # select the same algorithm at a possible cost in performance.
    config.cudnn_benchmark = True
    # Enforce CUDA convolution determinism. The algorithm itself might not be
    # deterministic so setting this to True ensures we make it repeatable.
    config.cudnn_deterministic = True #False

    # ================================================= #
    # Wrappers.
    # ================================================= #
    config.action_repeat = 1
    config.frame_stack = 1

    config.reward_wrapper = ml_collections.ConfigDict()
    config.reward_wrapper.pretrained_path = ""
    # Can be one of ['distance_to_goal', 'goal_classifier'].
    config.reward_wrapper.type = "distance_to_goal"

    # ================================================= #
    # Training parameters.
    # ================================================= #
    config.num_train_steps = 75_000
    config.replay_buffer_capacity = 1_000_000
    config.num_seed_steps = 20_000
    config.num_eval_episodes = 10
    config.eval_frequency = 20_000 #5_000
    config.checkpoint_frequency = 50_000
    config.log_frequency = 10_000
    config.save_video = True

    # ================================================= #
    # SAC parameters.
    # ================================================= #
    config.sac = ml_collections.ConfigDict()

    config.sac.obs_dim = obs_dim
    config.sac.action_dim = action_dim
    config.sac.action_range = action_range
    config.sac.chunk_len = chunk_len
    config.sac.discount = 0.99
    config.sac.init_temperature = 0.1
    config.sac.alpha_lr = 5e-5
    config.sac.alpha_betas = [0.9, 0.999]
    config.sac.actor_lr = 5e-5
    config.sac.actor_betas = [0.9, 0.999]
    config.sac.actor_update_frequency = 1
    config.sac.critic_lr = 5e-5
    config.sac.critic_betas = [0.9, 0.999]
    config.sac.critic_tau = 0.005
    config.sac.critic_target_update_frequency = 1
    config.sac.batch_size = 256
    config.sac.learnable_temperature = True

    # ================================================= #
    # Critic parameters.
    # ================================================= #
    config.sac.critic = ml_collections.ConfigDict()

    config.sac.critic.obs_dim = obs_dim
    config.sac.critic.action_dim = action_dim  * chunk_len
    config.sac.critic.hidden_dim = 1024
    config.sac.critic.hidden_depth = 2

    # ================================================= #
    # Actor parameters.
    # ================================================= #
    config.sac.actor = ml_collections.ConfigDict()

    config.sac.actor.obs_dim = obs_dim
    config.sac.actor.action_dim = action_dim * chunk_len
    config.sac.actor.hidden_dim = 1024
    config.sac.actor.hidden_depth = 2
    config.sac.actor.log_std_bounds = [-5, 1]

    # ================================================= #
    # Additional parameters.
    # ================================================= #
    config.epsilon = 0.21
    config.threshold_for_vgen = 0.8
    config.threshold_for_random_seq = 0.8
    config.sample_per_seq = 8

    return config