Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib] Issue 17653: Torch multi-GPU (>1) broken for LSTMs. #17657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions rllib/agents/cql/cql_tf_policy.py
Expand Up @@ -134,9 +134,8 @@ def cql_loss(policy: Policy, model: ModelV2,
# Q-values for the batched actions.
action_dist_tp1 = policy.dist_class(
model.get_policy_output(model_out_tp1), policy.model)
policy_tp1, log_pis_tp1 = action_dist_tp1.sample_logp()
policy_tp1, _ = action_dist_tp1.sample_logp()

log_pis_tp1 = tf.expand_dims(log_pis_tp1, -1)
q_t = model.get_q_values(model_out_t, actions)
q_t_selected = tf.squeeze(q_t, axis=-1)
if twin_q:
Expand Down
3 changes: 1 addition & 2 deletions rllib/agents/cql/cql_torch_policy.py
Expand Up @@ -143,9 +143,8 @@ def cql_loss(policy: Policy, model: ModelV2,
# Q-values for the batched actions.
action_dist_tp1 = action_dist_class(
model.get_policy_output(model_out_tp1), policy.model)
policy_tp1, log_pis_tp1 = action_dist_tp1.sample_logp()
policy_tp1, _ = action_dist_tp1.sample_logp()

log_pis_tp1 = torch.unsqueeze(log_pis_tp1, -1)
q_t = model.get_q_values(model_out_t, train_batch[SampleBatch.ACTIONS])
q_t_selected = torch.squeeze(q_t, dim=-1)
if twin_q:
Expand Down
5 changes: 5 additions & 0 deletions rllib/policy/torch_policy.py
Expand Up @@ -587,6 +587,11 @@ def learn_on_loaded_batch(self, offset: int = 0, buffer_index: int = 0):
"sgd_minibatch_size", self.config["train_batch_size"]) // \
len(self.devices)

# Set Model to train mode.
if self.model_gpu_towers:
for t in self.model_gpu_towers:
t.train()

# Shortcut for 1 CPU only: Batch should already be stored in
# `self._loaded_batches`.
if len(self.devices) == 1 and self.devices[0].type == "cpu":
Expand Down