rlmodule 0.1.0__tar.gz → 0.1.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rlmodule-0.1.5.1/LICENSE +30 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/PKG-INFO +1 -1
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/pyproject.toml +1 -1
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/__init__.py +1 -1
- rlmodule-0.1.5.1/rlmodule/skrl/torch/__init__.py +9 -0
- {rlmodule-0.1.0/rlmodule/skrl → rlmodule-0.1.5.1/rlmodule/skrl/torch}/examples/gymnasium/skrl_gymnasium_pendulum.py +55 -94
- rlmodule-0.1.5.1/rlmodule/skrl/torch/network/__init__.py +8 -0
- rlmodule-0.1.5.1/rlmodule/skrl/torch/output_layer/__init__.py +5 -0
- rlmodule-0.1.0/rlmodule/source/model_builder.py → rlmodule-0.1.5.1/rlmodule/source/build.py +1 -1
- rlmodule-0.1.0/rlmodule/source/modules.py → rlmodule-0.1.5.1/rlmodule/source/network.py +9 -9
- rlmodule-0.1.0/rlmodule/source/modules_cfg.py → rlmodule-0.1.5.1/rlmodule/source/network_cfg.py +4 -4
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/output_layer.py +2 -2
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/output_layer_cfg.py +6 -6
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/rlmodel.py +9 -19
- rlmodule-0.1.0/rlmodule/source/model_cfg.py → rlmodule-0.1.5.1/rlmodule/source/rlmodel_cfg.py +8 -1
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/utils.py +3 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule.egg-info/PKG-INFO +1 -1
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule.egg-info/SOURCES.txt +9 -6
- rlmodule-0.1.0/LICENSE +0 -21
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/README.md +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/skrl/__init__.py +0 -0
- {rlmodule-0.1.0/rlmodule/skrl → rlmodule-0.1.5.1/rlmodule/skrl/torch}/examples/gymnasium/skrl_gymnasium_pendulum_no_module.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/__init__.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/deprecated.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/model.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/nvidia_utils/__init__.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/nvidia_utils/configclass.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/nvidia_utils/dict.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule/source/nvidia_utils/string.py +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule.egg-info/dependency_links.txt +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule.egg-info/requires.txt +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/rlmodule.egg-info/top_level.txt +0 -0
- {rlmodule-0.1.0 → rlmodule-0.1.5.1}/setup.cfg +0 -0
rlmodule-0.1.5.1/LICENSE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Copyright (c) 2024 by Fabrica AI Corp.
|
|
2
|
+
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
8
|
+
are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
18
|
+
may be used to endorse or promote products derived from this software without
|
|
19
|
+
specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
22
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
23
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
25
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
26
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
27
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
28
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
30
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
# TODO this is not very good way
|
|
2
2
|
from .source.rlmodel import RLModel, SharedRLModel # noqa: F401, F403
|
|
3
3
|
from .source.output_layer import GaussianLayer, DeterministicLayer # noqa: F401, F403
|
|
4
|
-
from .source.
|
|
4
|
+
from .source.network import MLP # noqa: F401, F403
|
|
@@ -2,17 +2,10 @@ import gymnasium as gym
|
|
|
2
2
|
|
|
3
3
|
import torch.nn as nn
|
|
4
4
|
|
|
5
|
-
from rlmodule.
|
|
6
|
-
from rlmodule.
|
|
7
|
-
from rlmodule.
|
|
8
|
-
|
|
9
|
-
from rlmodule.source.model_builder import build_model
|
|
10
|
-
|
|
11
|
-
# example how this could be called:
|
|
12
|
-
# from rlmodule.skrl.torch.model import SharedRLModelCfg
|
|
13
|
-
# from rlmodule.skrl.torch.module import LstmCfg
|
|
14
|
-
# from rlmodule.skrl.torch.output_layer import DeterministicLayerCfg, GaussianLayerCfg
|
|
15
|
-
# from rlmodule.skrl.torch import build_model
|
|
5
|
+
from rlmodule.skrl.torch import build_model, SharedRLModelCfg, RLModelCfg, SeparatedRLModelCfg
|
|
6
|
+
from rlmodule.skrl.torch.network import MlpCfg, RnnMlpCfg, LstmCfg
|
|
7
|
+
from rlmodule.skrl.torch.output_layer import DeterministicLayerCfg, GaussianLayerCfg
|
|
8
|
+
|
|
16
9
|
|
|
17
10
|
# import the skrl components to build the RL system
|
|
18
11
|
from skrl.agents.torch.ppo import PPO, PPO_RNN, PPO_DEFAULT_CONFIG
|
|
@@ -38,7 +31,7 @@ set_seed() # e.g. `set_seed(42)` for fixed seed
|
|
|
38
31
|
# (Done) Move things logically
|
|
39
32
|
# (Done) Handle input shapes better?
|
|
40
33
|
# (Done except Cnn) Convert all rest modules to use Configclass
|
|
41
|
-
# Rearrange library in the way it can be used for other rllibs and for torch/jax?
|
|
34
|
+
# (Done) Rearrange library in the way it can be used for other rllibs and for torch/jax?
|
|
42
35
|
# Create examples - mlp, rnn,gru,lstm, Lstmmlp, shared - separate , custom net by fcion
|
|
43
36
|
# - examples from modules make in class header not function
|
|
44
37
|
# WRITE README tutorial
|
|
@@ -47,6 +40,8 @@ set_seed() # e.g. `set_seed(42)` for fixed seed
|
|
|
47
40
|
# extensive comments
|
|
48
41
|
# Launch new version to pip
|
|
49
42
|
# Import new version in Isaac-lab
|
|
43
|
+
# Change structure of source
|
|
44
|
+
# lazy linear? what is it ?
|
|
50
45
|
|
|
51
46
|
|
|
52
47
|
|
|
@@ -61,7 +56,7 @@ set_seed() # e.g. `set_seed(42)` for fixed seed
|
|
|
61
56
|
# ),
|
|
62
57
|
# mlp = MlpCfg(
|
|
63
58
|
# hidden_units = [64, 64, 64],
|
|
64
|
-
#
|
|
59
|
+
# activation = nn.ReLU,
|
|
65
60
|
# ),
|
|
66
61
|
# )
|
|
67
62
|
# return RnnMlp(cfg)
|
|
@@ -69,11 +64,11 @@ set_seed() # e.g. `set_seed(42)` for fixed seed
|
|
|
69
64
|
def get_shared_model(env):
|
|
70
65
|
# instantiate the agent's models (function approximators).
|
|
71
66
|
|
|
72
|
-
net_cfg = MlpCfg(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
67
|
+
# net_cfg = MlpCfg(
|
|
68
|
+
# input_size = env.observation_space,
|
|
69
|
+
# hidden_units = [64, 64, 64],
|
|
70
|
+
# activation = nn.ReLU,
|
|
71
|
+
# )
|
|
77
72
|
|
|
78
73
|
# 2
|
|
79
74
|
# net_cfg = LstmCfg(
|
|
@@ -85,19 +80,19 @@ def get_shared_model(env):
|
|
|
85
80
|
# )
|
|
86
81
|
|
|
87
82
|
# 3
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
net_cfg = RnnMlpCfg(
|
|
84
|
+
input_size = env.observation_space,
|
|
85
|
+
rnn = LstmCfg(
|
|
86
|
+
num_envs = env.num_envs,
|
|
87
|
+
num_layers = 1,
|
|
88
|
+
hidden_size = 32,
|
|
89
|
+
sequence_length = 16,
|
|
90
|
+
),
|
|
91
|
+
mlp = MlpCfg(
|
|
92
|
+
hidden_units = [64, 64, 64],
|
|
93
|
+
activation = nn.ReLU,
|
|
94
|
+
),
|
|
95
|
+
)
|
|
101
96
|
|
|
102
97
|
# 3.5
|
|
103
98
|
# net_cfg = RnnMlpCfg(
|
|
@@ -111,7 +106,7 @@ def get_shared_model(env):
|
|
|
111
106
|
# ),
|
|
112
107
|
# mlp = MlpCfg(
|
|
113
108
|
# hidden_units = [64, 64, 64],
|
|
114
|
-
#
|
|
109
|
+
# activation = nn.ReLU,
|
|
115
110
|
# ),
|
|
116
111
|
# )
|
|
117
112
|
|
|
@@ -134,73 +129,38 @@ def get_shared_model(env):
|
|
|
134
129
|
value_output_layer= DeterministicLayerCfg(),
|
|
135
130
|
)
|
|
136
131
|
)
|
|
137
|
-
# RLCfg(
|
|
138
|
-
# Model
|
|
139
|
-
# AgentCfg
|
|
140
|
-
# MemoryCfg
|
|
141
|
-
# )
|
|
142
|
-
|
|
143
|
-
# build_model(cfg.model)
|
|
144
|
-
|
|
145
|
-
# cfg.agent.algoclass(
|
|
146
|
-
# cfg.agent.algo_config
|
|
147
|
-
# cfg.memory
|
|
148
|
-
# )
|
|
149
|
-
|
|
150
|
-
# SharedRLModelCfg(RLModelCfg){
|
|
151
|
-
# class = SharedRLModel
|
|
152
|
-
|
|
153
|
-
# }
|
|
154
|
-
|
|
155
|
-
# net
|
|
156
|
-
# output layers.class()
|
|
157
|
-
|
|
158
|
-
# cfg.model.class( net, output_layers )
|
|
159
|
-
|
|
160
|
-
#configclass -> dataclass - easy (Ron said)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
# variant V:
|
|
164
|
-
# ideas?
|
|
165
|
-
|
|
166
|
-
|
|
167
132
|
return {'policy': model, 'value': model}
|
|
168
133
|
|
|
169
134
|
# TODO Update separate model to configclass
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
# net = MLP(params)
|
|
177
|
-
|
|
178
|
-
# policy_model = RLModel(
|
|
179
|
-
# network=net,
|
|
180
|
-
# device= device,
|
|
181
|
-
# output_layer = GaussianLayer(
|
|
182
|
-
# input_size=64, # TODO
|
|
183
|
-
# output_size=env.action_space,
|
|
184
|
-
# output_activation=nn.Tanh(),
|
|
185
|
-
# clip_actions=False,
|
|
186
|
-
# clip_log_std=True,
|
|
187
|
-
# min_log_std=-1.2,
|
|
188
|
-
# max_log_std=2,
|
|
189
|
-
# initial_log_std=0.2,
|
|
190
|
-
# ),
|
|
191
|
-
# )
|
|
135
|
+
def get_separated_model(env):
|
|
136
|
+
net_cfg = MlpCfg(
|
|
137
|
+
input_size = env.observation_space,
|
|
138
|
+
hidden_units = [64, 64, 64],
|
|
139
|
+
activation = nn.ReLU,
|
|
140
|
+
)
|
|
192
141
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
142
|
+
policy_model = build_model(
|
|
143
|
+
RLModelCfg(
|
|
144
|
+
network= net_cfg,
|
|
145
|
+
device= device,
|
|
146
|
+
output_layer= GaussianLayerCfg(
|
|
147
|
+
output_size=env.action_space,
|
|
148
|
+
min_log_std=-1.2,
|
|
149
|
+
max_log_std=2,
|
|
150
|
+
initial_log_std=0.2,
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
value_model = build_model(
|
|
156
|
+
RLModelCfg(
|
|
157
|
+
network= net_cfg,
|
|
158
|
+
device= device,
|
|
159
|
+
output_layer= DeterministicLayerCfg(),
|
|
160
|
+
)
|
|
161
|
+
)
|
|
202
162
|
|
|
203
|
-
|
|
163
|
+
return {'policy': policy_model, 'value': value_model}
|
|
204
164
|
|
|
205
165
|
|
|
206
166
|
# load and wrap the gymnasium environment.
|
|
@@ -221,6 +181,7 @@ device = env.device
|
|
|
221
181
|
memory = RandomMemory(memory_size=1024, num_envs=env.num_envs, device=device)
|
|
222
182
|
|
|
223
183
|
models = get_shared_model(env)
|
|
184
|
+
#models = get_separated_model(env)
|
|
224
185
|
|
|
225
186
|
print(models)
|
|
226
187
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
# modules:
|
|
3
|
+
"MLP", "RNN", "GRU", "LSTM", "RnnBase", "RnnMlp",
|
|
4
|
+
# configs:
|
|
5
|
+
"NetworkCfg", "MlpCfg", "RnnBaseCfg", "RnnCfg", "GruCfg", "LstmCfg", "RnnMlpCfg"
|
|
6
|
+
]
|
|
7
|
+
from rlmodule.source.network import MLP, RNN, GRU, LSTM, RnnBase, RnnMlp
|
|
8
|
+
from rlmodule.source.network_cfg import NetworkCfg, MlpCfg, RnnBaseCfg, RnnCfg, GruCfg, LstmCfg, RnnMlpCfg
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from rlmodule.source.
|
|
1
|
+
from rlmodule.source.rlmodel_cfg import BaseRLCfg, RLModelCfg, SharedRLModelCfg
|
|
2
2
|
from rlmodule.source.utils import get_output_size
|
|
3
3
|
|
|
4
4
|
#TODO this, or inside RLModel class that have a config passed
|
|
@@ -14,7 +14,7 @@ class MLP(nn.Module):
|
|
|
14
14
|
cfg = MlpCfg(
|
|
15
15
|
input_size = 517,
|
|
16
16
|
hidden_units = [2048, 1024, 1024, 512],
|
|
17
|
-
|
|
17
|
+
activation = nn.ELU,
|
|
18
18
|
)
|
|
19
19
|
net = MLP(cfg)
|
|
20
20
|
"""
|
|
@@ -26,13 +26,13 @@ class MLP(nn.Module):
|
|
|
26
26
|
# input layer
|
|
27
27
|
layers = [
|
|
28
28
|
nn.Linear(cfg.input_size, cfg.hidden_units[0]),
|
|
29
|
-
cfg.
|
|
29
|
+
cfg.activation(),
|
|
30
30
|
]
|
|
31
31
|
|
|
32
32
|
# hidden layers
|
|
33
33
|
for i in range(len(cfg.hidden_units) - 1):
|
|
34
34
|
layers.append(nn.Linear(cfg.hidden_units[i], cfg.hidden_units[i + 1]))
|
|
35
|
-
layers.append(cfg.
|
|
35
|
+
layers.append(cfg.activation())
|
|
36
36
|
|
|
37
37
|
self.mlp = nn.Sequential(*layers)
|
|
38
38
|
|
|
@@ -307,7 +307,7 @@ class RnnMlp(RnnBase):
|
|
|
307
307
|
),
|
|
308
308
|
mlp = MlpCfg(
|
|
309
309
|
hidden_units = [2048, 1024, 1024, 512],
|
|
310
|
-
|
|
310
|
+
activation = nn.ELU,
|
|
311
311
|
)
|
|
312
312
|
)
|
|
313
313
|
net = RnnMlp(cfg)
|
|
@@ -324,7 +324,7 @@ class RnnMlp(RnnBase):
|
|
|
324
324
|
),
|
|
325
325
|
mlp = MlpCfg(
|
|
326
326
|
hidden_units = [2048, 1024, 1024, 512],
|
|
327
|
-
|
|
327
|
+
activation = nn.ELU,
|
|
328
328
|
)
|
|
329
329
|
)
|
|
330
330
|
net = RnnMlp(cfg)
|
|
@@ -341,7 +341,7 @@ class RnnMlp(RnnBase):
|
|
|
341
341
|
),
|
|
342
342
|
mlp = MlpCfg(
|
|
343
343
|
hidden_units = [2048, 1024, 1024, 512],
|
|
344
|
-
|
|
344
|
+
activation = nn.ELU,
|
|
345
345
|
)
|
|
346
346
|
)
|
|
347
347
|
net = RnnMlp(cfg)
|
|
@@ -382,7 +382,7 @@ class RnnMlpWithForwardedInput(RnnBase):
|
|
|
382
382
|
),
|
|
383
383
|
mlp = MlpCfg(
|
|
384
384
|
hidden_units = [2048, 1024, 1024, 512],
|
|
385
|
-
|
|
385
|
+
activation = nn.ELU,
|
|
386
386
|
)
|
|
387
387
|
)
|
|
388
388
|
net = RnnMlp(cfg)
|
|
@@ -400,7 +400,7 @@ class RnnMlpWithForwardedInput(RnnBase):
|
|
|
400
400
|
),
|
|
401
401
|
mlp = MlpCfg(
|
|
402
402
|
hidden_units = [2048, 1024, 1024, 512],
|
|
403
|
-
|
|
403
|
+
activation = nn.ELU,
|
|
404
404
|
)
|
|
405
405
|
)
|
|
406
406
|
net = RnnMlp(cfg)
|
|
@@ -418,7 +418,7 @@ class RnnMlpWithForwardedInput(RnnBase):
|
|
|
418
418
|
),
|
|
419
419
|
mlp = MlpCfg(
|
|
420
420
|
hidden_units = [2048, 1024, 1024, 512],
|
|
421
|
-
|
|
421
|
+
activation = nn.ELU,
|
|
422
422
|
)
|
|
423
423
|
)
|
|
424
424
|
net = RnnMlp(cfg)
|
rlmodule-0.1.0/rlmodule/source/modules_cfg.py → rlmodule-0.1.5.1/rlmodule/source/network_cfg.py
RENAMED
|
@@ -6,7 +6,7 @@ from dataclasses import MISSING
|
|
|
6
6
|
from collections.abc import Callable
|
|
7
7
|
from typing import List, Sequence, Union
|
|
8
8
|
|
|
9
|
-
from rlmodule.source.
|
|
9
|
+
from rlmodule.source.network import GRU, LSTM, MLP, RNN, RnnBase, RnnMlp
|
|
10
10
|
|
|
11
11
|
# use isaac-lab native configclass if available to avoid it being declared twice
|
|
12
12
|
try:
|
|
@@ -18,15 +18,15 @@ except ImportError:
|
|
|
18
18
|
@configclass
|
|
19
19
|
class NetworkCfg:
|
|
20
20
|
module: Union[nn.Module, Callable[..., nn.Module]] = MISSING
|
|
21
|
-
input_size: Union[int, Sequence[int], gym.Space, gymnasium.Space] =
|
|
21
|
+
input_size: Union[int, Sequence[int], gym.Space, gymnasium.Space] = None # None means value should be inferred
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@configclass
|
|
25
25
|
class MlpCfg(NetworkCfg):
|
|
26
26
|
module: type[MLP] = MLP
|
|
27
27
|
|
|
28
|
-
hidden_units:
|
|
29
|
-
|
|
28
|
+
hidden_units: Sequence[int] = MISSING
|
|
29
|
+
activation: type[nn.Module] = MISSING
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
@configclass
|
|
@@ -68,7 +68,7 @@ class GaussianLayer(OutputLayer):
|
|
|
68
68
|
|
|
69
69
|
self.net = nn.Sequential(
|
|
70
70
|
nn.Linear(input_size, cfg.output_size),
|
|
71
|
-
cfg.output_activation
|
|
71
|
+
cfg.output_activation()
|
|
72
72
|
)
|
|
73
73
|
|
|
74
74
|
self.log_std_parameter = nn.Parameter(
|
|
@@ -141,7 +141,7 @@ class DeterministicLayer(OutputLayer):
|
|
|
141
141
|
|
|
142
142
|
self.net = nn.Sequential(
|
|
143
143
|
nn.Linear(input_size, cfg.output_size),
|
|
144
|
-
cfg.output_activation
|
|
144
|
+
cfg.output_activation()
|
|
145
145
|
)
|
|
146
146
|
|
|
147
147
|
def forward(self, input, taken_actions, outputs_dict):
|
|
@@ -15,7 +15,7 @@ except ImportError:
|
|
|
15
15
|
@configclass
|
|
16
16
|
class OutputLayerCfg:
|
|
17
17
|
class_type: type[nn.Module] = MISSING,
|
|
18
|
-
output_size: Union[int, Sequence[int], gym.Space, gymnasium.Space] =
|
|
18
|
+
output_size: Union[int, Sequence[int], gym.Space, gymnasium.Space] = None, # None is inferred
|
|
19
19
|
output_activation: nn.Module = MISSING,
|
|
20
20
|
|
|
21
21
|
clip_actions: bool = False, # TODO what is clip action doing
|
|
@@ -23,16 +23,16 @@ class OutputLayerCfg:
|
|
|
23
23
|
@configclass
|
|
24
24
|
class GaussianLayerCfg(OutputLayerCfg):
|
|
25
25
|
class_type: type[GaussianLayer] = GaussianLayer
|
|
26
|
-
output_activation: nn.Module = nn.Tanh
|
|
26
|
+
output_activation: type[nn.Module] = nn.Tanh
|
|
27
27
|
|
|
28
28
|
clip_log_std: bool = True
|
|
29
|
-
min_log_std: float = -20
|
|
30
|
-
max_log_std: float = 2
|
|
31
|
-
initial_log_std: float = 0
|
|
29
|
+
min_log_std: float = -20.0
|
|
30
|
+
max_log_std: float = 2.0
|
|
31
|
+
initial_log_std: float = 0.0
|
|
32
32
|
reduction: str = "sum"
|
|
33
33
|
|
|
34
34
|
@configclass
|
|
35
35
|
class DeterministicLayerCfg(OutputLayerCfg):
|
|
36
36
|
class_type: type[DeterministicLayer] = DeterministicLayer
|
|
37
37
|
output_size: Union[int, Sequence[int], gym.Space, gymnasium.Space] = 1
|
|
38
|
-
output_activation: nn.Module = nn.Identity
|
|
38
|
+
output_activation: nn.Module = nn.Identity
|
|
@@ -78,13 +78,8 @@ class RLModel(Model):
|
|
|
78
78
|
self._lstm = contains_rnn_module( self, nn.LSTM)
|
|
79
79
|
self._rnn = contains_rnn_module( self, (nn.LSTM, nn.RNN, nn.GRU))
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
print("
|
|
83
|
-
print("!lstm: ", self._lstm)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
print("!rnn: ", self._rnn)
|
|
87
|
-
print("!lstm: ", self._lstm)
|
|
81
|
+
print("is rnn: ", self._rnn)
|
|
82
|
+
print("is lstm: ", self._lstm)
|
|
88
83
|
|
|
89
84
|
# TODO(ll) one liner:
|
|
90
85
|
# self.net = nn.Sequential(network, self._get_num_units_by_shape(self.output_shape), torch.nn.Tanh())
|
|
@@ -120,13 +115,6 @@ class RLModel(Model):
|
|
|
120
115
|
else:
|
|
121
116
|
return {}
|
|
122
117
|
|
|
123
|
-
# TODO(ll) RNN & GRU has this simplier specification
|
|
124
|
-
# def get_specification(self):
|
|
125
|
-
|
|
126
|
-
# # batch size (N) is the number of envs
|
|
127
|
-
# return {"rnn": {"sequence_length": self.sequence_length,
|
|
128
|
-
# "sizes": [(self.num_layers, self.num_envs, self.hidden_size)]}} # hidden states (D ∗ num_layers, N, Hout)
|
|
129
|
-
|
|
130
118
|
def get_entropy(self, role: str = "") -> torch.Tensor:
|
|
131
119
|
"""Compute and return the entropy of the model
|
|
132
120
|
|
|
@@ -163,14 +151,16 @@ class RLModel(Model):
|
|
|
163
151
|
inputs: Mapping[str, Union[torch.Tensor, Any]],
|
|
164
152
|
role: str = "") -> Tuple[torch.Tensor, Union[torch.Tensor, None], Mapping[str, Union[torch.Tensor, Any]]]:
|
|
165
153
|
|
|
154
|
+
states = inputs["states"]
|
|
155
|
+
|
|
166
156
|
# TODO(ll) once shared model is design, you may rethink this to do by call some function pointer or whatever.
|
|
167
157
|
# or consider inheritance GaussianModelRNN
|
|
168
158
|
# TODO(ll) if one of the models is not rnn ... and PPO_RNN is called what happens?
|
|
169
159
|
if self._rnn:
|
|
170
|
-
output, output_dict = self.net(
|
|
160
|
+
output, output_dict = self.net(states, inputs.get('terminated', None), inputs['rnn'])
|
|
171
161
|
else:
|
|
172
162
|
|
|
173
|
-
output = self.net(
|
|
163
|
+
output = self.net(states)
|
|
174
164
|
output_dict = {}
|
|
175
165
|
|
|
176
166
|
# TODO(ll) passing by independetly as together sequential has just one input in forward
|
|
@@ -188,7 +178,7 @@ class RLModel(Model):
|
|
|
188
178
|
|
|
189
179
|
# TODO(ll) output scale removed .. check that tanh where is
|
|
190
180
|
# return output * self.instantiator_output_scale, self.log_std_parameter, {}
|
|
191
|
-
return output, self.log_std_parameter, output_dict
|
|
181
|
+
# return output, self.log_std_parameter, output_dict
|
|
192
182
|
|
|
193
183
|
class SharedRLModel(Model):
|
|
194
184
|
def __init__(self,
|
|
@@ -253,8 +243,8 @@ class SharedRLModel(Model):
|
|
|
253
243
|
self._lstm = contains_rnn_module( self, nn.LSTM)
|
|
254
244
|
self._rnn = contains_rnn_module( self, (nn.LSTM, nn.RNN, nn.GRU))
|
|
255
245
|
|
|
256
|
-
print("
|
|
257
|
-
print("
|
|
246
|
+
print("is rnn: ", self._rnn)
|
|
247
|
+
print("is lstm: ", self._lstm)
|
|
258
248
|
|
|
259
249
|
# caching for shared forward pass for policy and value roles
|
|
260
250
|
self._cached_states = None
|
rlmodule-0.1.0/rlmodule/source/model_cfg.py → rlmodule-0.1.5.1/rlmodule/source/rlmodel_cfg.py
RENAMED
|
@@ -30,4 +30,11 @@ class RLModelCfg(BaseRLCfg):
|
|
|
30
30
|
class SharedRLModelCfg(BaseRLCfg):
|
|
31
31
|
class_type: type[SharedRLModel] = SharedRLModel
|
|
32
32
|
policy_output_layer: OutputLayerCfg = MISSING
|
|
33
|
-
value_output_layer: OutputLayerCfg = MISSING
|
|
33
|
+
value_output_layer: OutputLayerCfg = MISSING
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@configclass
|
|
37
|
+
class SeparatedRLModelCfg:
|
|
38
|
+
"""Convenience class to hold two separate instances of RLModelCfg. One for policy and one for value model."""
|
|
39
|
+
policy: RLModelCfg = MISSING
|
|
40
|
+
value: RLModelCfg = MISSING
|
|
@@ -116,6 +116,9 @@ def get_space_size(space: Union[int, Sequence[int], gym.Space, gymnasium.Space],
|
|
|
116
116
|
size = np.prod(space.shape)
|
|
117
117
|
elif issubclass(type(space), gymnasium.spaces.Dict):
|
|
118
118
|
size = sum([self._get_space_size(space.spaces[key], number_of_elements) for key in space.spaces])
|
|
119
|
+
elif space is None:
|
|
120
|
+
size = -1 # size will be inferred externally
|
|
119
121
|
if size is None:
|
|
120
122
|
raise ValueError(f"Space type {type(space)} not supported")
|
|
123
|
+
print("s", size)
|
|
121
124
|
return int(size)
|
|
@@ -8,18 +8,21 @@ rlmodule.egg-info/dependency_links.txt
|
|
|
8
8
|
rlmodule.egg-info/requires.txt
|
|
9
9
|
rlmodule.egg-info/top_level.txt
|
|
10
10
|
rlmodule/skrl/__init__.py
|
|
11
|
-
rlmodule/skrl/
|
|
12
|
-
rlmodule/skrl/examples/gymnasium/
|
|
11
|
+
rlmodule/skrl/torch/__init__.py
|
|
12
|
+
rlmodule/skrl/torch/examples/gymnasium/skrl_gymnasium_pendulum.py
|
|
13
|
+
rlmodule/skrl/torch/examples/gymnasium/skrl_gymnasium_pendulum_no_module.py
|
|
14
|
+
rlmodule/skrl/torch/network/__init__.py
|
|
15
|
+
rlmodule/skrl/torch/output_layer/__init__.py
|
|
13
16
|
rlmodule/source/__init__.py
|
|
17
|
+
rlmodule/source/build.py
|
|
14
18
|
rlmodule/source/deprecated.py
|
|
15
19
|
rlmodule/source/model.py
|
|
16
|
-
rlmodule/source/
|
|
17
|
-
rlmodule/source/
|
|
18
|
-
rlmodule/source/modules.py
|
|
19
|
-
rlmodule/source/modules_cfg.py
|
|
20
|
+
rlmodule/source/network.py
|
|
21
|
+
rlmodule/source/network_cfg.py
|
|
20
22
|
rlmodule/source/output_layer.py
|
|
21
23
|
rlmodule/source/output_layer_cfg.py
|
|
22
24
|
rlmodule/source/rlmodel.py
|
|
25
|
+
rlmodule/source/rlmodel_cfg.py
|
|
23
26
|
rlmodule/source/utils.py
|
|
24
27
|
rlmodule/source/nvidia_utils/__init__.py
|
|
25
28
|
rlmodule/source/nvidia_utils/configclass.py
|
rlmodule-0.1.0/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 FabricaAI
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|