Skip to content

Commit 4d06be0

Browse files
committed
Add various fixes
1 parent a02762b commit 4d06be0

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

alf/algorithms/distributed_off_policy_algorithm.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def __init__(self,
106106
port: int = 50000,
107107
env: AlfEnvironment = None,
108108
config: TrainerConfig = None,
109-
optimizer: alf.optimizers.Optimizer = None,
110109
debug_summaries: bool = False,
111110
name: str = "DistributedOffPolicyAlgorithm",
112111
**kwargs):
@@ -117,7 +116,6 @@ def __init__(self,
117116
to always specify this argument.
118117
port: port number for communication on the *current* machine.
119118
env: The environment to interact with. Its batch size must be 1.
120-
optimizer: optimizer for the training the core algorithm.
121119
debug_summaries: True if debug summaries should be created.
122120
name: the name of this algorithm.
123121
*args: args to pass to ``core_alg_ctor``.
@@ -144,7 +142,6 @@ def __init__(self,
144142
predict_state_spec=core_alg.predict_state_spec,
145143
env=env,
146144
config=config,
147-
optimizer=optimizer,
148145
# Prevent in-alg ckpt since there is no such a use case.
149146
checkpoint=None,
150147
debug_summaries=debug_summaries,
@@ -155,14 +152,22 @@ def __init__(self,
155152
self._ddp_rank = max(0, PerProcessContext().ddp_rank)
156153
self._num_ranks = PerProcessContext().num_processes
157154

155+
def state_dict(self, *args, **kwargs):
156+
return self._core_alg.state_dict(*args, **kwargs)
157+
158+
def load_state_dict(self, state_dict, strict=True, **kwargs):
159+
return self._core_alg.load_state_dict(state_dict,
160+
strict=strict,
161+
**kwargs)
162+
158163
def _distributed_state_dict(self) -> dict:
159164
"""Return `self._core_alg` state dict for distributed training.
160165
161166
This dict will be used for param syncing between a trainer and an unroller.
162167
Sometimes optimizers have large state vectors which we want to exclude.
163-
Also we should exclude other parameters such as those of pretrained models.
168+
Also, we should exclude other parameters such as those of pretrained models.
164169
"""
165-
# Note that self._core_alg won't create a relay buffer so we don't have
170+
# Note that self._core_alg won't create a replay buffer so we don't have
166171
# to worry about including it in the state dict.
167172
return {
168173
k: v
@@ -203,6 +208,9 @@ def after_update(self, root_inputs, info):
203208
def after_train_iter(self, root_inputs, rollout_info):
204209
return self._core_alg.after_train_iter(root_inputs, rollout_info)
205210

211+
def summarize_metrics(self):
212+
self._core_alg.summarize_metrics()
213+
206214

207215
def receive_experience_data(replay_buffer: ReplayBuffer,
208216
new_unroller_ips_and_ports: 'Manager.Queue',
@@ -253,7 +261,9 @@ def receive_experience_data(replay_buffer: ReplayBuffer,
253261
unroller_id, message = socket.recv_multipart()
254262

255263
buffer = io.BytesIO(message)
256-
exp_params = torch.load(buffer, map_location='cpu')
264+
exp_params = torch.load(buffer,
265+
map_location='cpu',
266+
weights_only=False)
257267
# we prune env_info according to the replay buffer for the following reasons:
258268
# 1) avoid env_info mismatch and allow the distributed unroller to have
259269
# a customized env_info for tb summarization,
@@ -308,7 +318,9 @@ def pull_params_from_trainer(memory_name: str, memory_lock: mp.Lock,
308318

309319

310320
@alf.configurable(whitelist=[
311-
'max_utd_ratio', 'push_params_every_n_grad_updates', 'name', 'optimizer'
321+
'max_utd_ratio',
322+
'push_params_every_n_grad_updates',
323+
'name',
312324
])
313325
class DistributedTrainer(DistributedOffPolicyAlgorithm):
314326

@@ -319,7 +331,6 @@ def __init__(self,
319331
push_params_every_n_grad_updates: int = 1,
320332
env: AlfEnvironment = None,
321333
config: TrainerConfig = None,
322-
optimizer: alf.optimizers.Optimizer = None,
323334
debug_summaries: bool = False,
324335
name: str = "DistributedTrainer",
325336
**kwargs):
@@ -347,7 +358,6 @@ def __init__(self,
347358
port=_trainer_addr_config.port,
348359
env=env,
349360
config=config,
350-
optimizer=optimizer,
351361
debug_summaries=debug_summaries,
352362
name=name,
353363
**kwargs)
@@ -582,8 +592,7 @@ def _train_iter_off_policy(self):
582592
return steps
583593

584594

585-
@alf.configurable(
586-
whitelist=['episode_length', 'name', 'optimizer', 'unroller_only'])
595+
@alf.configurable(whitelist=['episode_length', 'name', 'unroller_only'])
587596
class DistributedUnroller(DistributedOffPolicyAlgorithm):
588597

589598
def __init__(self,

0 commit comments

Comments
 (0)