Skip to content

Commit 758f7e4

Browse files
committed
Minor bug fixes
1 parent 2caceb0 commit 758f7e4

File tree

5 files changed

+72
-36
lines changed

5 files changed

+72
-36
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ actorch run REINFORCE_CartPole-v1.py # Run experiment
177177

178178
**NOTE**: training artifacts (e.g. checkpoints, metrics, etc.) are saved in nested subdirectories.
179179
This might cause issues on Windows, since the maximum path length is 260 characters. In that case,
180-
move your configuration file (or set `local_dir`) to an upper level directory (e.g. `Desktop`).
180+
move the configuration file (or set `local_dir`) to an upper level directory (e.g. `Desktop`),
181+
shorten the configuration file name, and/or shorten the algorithm name
182+
(e.g. `DistributedDataParallelREINFORCE.rename("DDPR")`).
181183

182184
Wait for a few minutes until the training ends. The mean cumulative reward over
183185
the last 100 episodes should exceed 475, which means that the environment was
@@ -186,8 +188,8 @@ successfully solved. You can now plot the performance metrics saved in the auto-
186188
(or [Matplotlib](https://matplotlib.org/)):
187189

188190
```bash
191+
pip install actorch[vistool] # Install dependencies for VisTool
189192
cd experiments/REINFORCE_CartPole-v1/<auto-generated-experiment-name>
190-
pip install actorch[vistool]
191193
actorch vistool plotly tensorboard
192194
```
193195

actorch/algorithms/algorithm.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,23 @@ def __init__(
455455
**kwargs,
456456
)
457457

458+
@classmethod
459+
def rename(cls, name: "str") -> "Type[Algorithm]":
460+
"""Return a copy of this class with
461+
name set to `name`.
462+
463+
Parameters
464+
----------
465+
name:
466+
The new name.
467+
468+
Returns
469+
-------
470+
The renamed class.
471+
472+
"""
473+
return type(name, (cls,), {})
474+
458475
# override
459476
def setup(self, config: "Dict[str, Any]") -> "None":
460477
self.config = Algorithm.Config(**self.config)
@@ -1388,22 +1405,6 @@ def __init__(
13881405
**worker_config,
13891406
)
13901407

1391-
# override
1392-
def setup(self, config: "Dict[str, Any]") -> "None":
1393-
config = DistributedDataParallelAlgorithm.Config(**config)
1394-
self.log_sys_usage = config.pop("log_sys_usage")
1395-
config["reduction_mode"] = "sum"
1396-
super().setup(config)
1397-
self.config["log_sys_usage"] = self.log_sys_usage
1398-
1399-
# override
1400-
def reset_config(self, new_config: "Dict[str, Any]") -> "bool":
1401-
new_config = DistributedDataParallelAlgorithm.Config(**new_config)
1402-
if self.log_sys_usage != new_config.pop("log_sys_usage"):
1403-
return False
1404-
new_config["reduction_mode"] = "sum"
1405-
return super().reset_config(new_config)
1406-
14071408
# override
14081409
@classmethod
14091410
def get_worker_cls(cls) -> "Type[Trainable]":
@@ -1489,6 +1490,39 @@ def _seed(self) -> "None":
14891490

14901491
return Worker
14911492

1493+
@classmethod
1494+
def rename(cls, name: "str") -> "Type[DistributedDataParallelAlgorithm]":
1495+
"""Return a copy of this class with
1496+
name set to `name`.
1497+
1498+
Parameters
1499+
----------
1500+
name:
1501+
The new name.
1502+
1503+
Returns
1504+
-------
1505+
The renamed class.
1506+
1507+
"""
1508+
return type(name, (cls,), {})
1509+
1510+
# override
1511+
def setup(self, config: "Dict[str, Any]") -> "None":
1512+
config = DistributedDataParallelAlgorithm.Config(**config)
1513+
self.log_sys_usage = config.pop("log_sys_usage")
1514+
config["reduction_mode"] = "sum"
1515+
super().setup(config)
1516+
self.config["log_sys_usage"] = self.log_sys_usage
1517+
1518+
# override
1519+
def reset_config(self, new_config: "Dict[str, Any]") -> "bool":
1520+
new_config = DistributedDataParallelAlgorithm.Config(**new_config)
1521+
if self.log_sys_usage != new_config.pop("log_sys_usage"):
1522+
return False
1523+
new_config["reduction_mode"] = "sum"
1524+
return super().reset_config(new_config)
1525+
14921526
# override
14931527
def _reduce(self, results: "Sequence[Dict[str, Any]]") -> "Dict[str, Any]":
14941528
reduced = results[0]

examples/DDPG_LunarLanderContinuous-v2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class LayerNormFCNet(FCNet):
3131
# override
3232
def _setup_torso(self, in_shape):
3333
super()._setup_torso(in_shape)
34-
idx = 0
35-
for module in self.torso[:]:
36-
idx += 1
34+
torso = nn.Sequential()
35+
for module in self.torso:
36+
torso.append(module)
3737
if isinstance(module, nn.Linear):
38-
self.torso.insert(
39-
idx, nn.LayerNorm(module.out_features, elementwise_affine=False)
38+
torso.append(
39+
nn.LayerNorm(module.out_features, elementwise_affine=False)
4040
)
41-
idx += 1
41+
self.torso = torso
4242

4343

4444
experiment_params = ExperimentParams(

examples/DistributedDataParallelDDPG_LunarLanderContinuous-v2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class LayerNormFCNet(FCNet):
3131
# override
3232
def _setup_torso(self, in_shape):
3333
super()._setup_torso(in_shape)
34-
idx = 0
35-
for module in self.torso[:]:
36-
idx += 1
34+
torso = nn.Sequential()
35+
for module in self.torso:
36+
torso.append(module)
3737
if isinstance(module, nn.Linear):
38-
self.torso.insert(
39-
idx, nn.LayerNorm(module.out_features, elementwise_affine=False)
38+
torso.append(
39+
nn.LayerNorm(module.out_features, elementwise_affine=False)
4040
)
41-
idx += 1
41+
self.torso = torso
4242

4343

4444
experiment_params = ExperimentParams(

examples/TD3_LunarLanderContinuous-v2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class LayerNormFCNet(FCNet):
3131
# override
3232
def _setup_torso(self, in_shape):
3333
super()._setup_torso(in_shape)
34-
idx = 0
35-
for module in self.torso[:]:
36-
idx += 1
34+
torso = nn.Sequential()
35+
for module in self.torso:
36+
torso.append(module)
3737
if isinstance(module, nn.Linear):
38-
self.torso.insert(
39-
idx, nn.LayerNorm(module.out_features, elementwise_affine=False)
38+
torso.append(
39+
nn.LayerNorm(module.out_features, elementwise_affine=False)
4040
)
41-
idx += 1
41+
self.torso = torso
4242

4343

4444
experiment_params = ExperimentParams(

0 commit comments

Comments
 (0)