Skip to content

Commit a2c419d

Browse files
author
Ervin T
authored
[refactor] Reduce dimension of continuous ent coef (#4725)
1 parent 71e075d commit a2c419d

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

ml-agents/mlagents/trainers/sac/optimizer_torch.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ def __init__(self, policy: TorchPolicy, trainer_params: TrainerSettings):
159159
requires_grad=True,
160160
)
161161
_cont_log_ent_coef = torch.nn.Parameter(
162-
torch.log(
163-
torch.as_tensor([self.init_entcoef] * self._action_spec.continuous_size)
164-
),
165-
requires_grad=True,
162+
torch.log(torch.as_tensor([self.init_entcoef])), requires_grad=True
166163
)
167164
self._log_ent_coef = TorchSACOptimizer.LogEntCoef(
168165
discrete=_disc_log_ent_coef, continuous=_cont_log_ent_coef
@@ -426,7 +423,7 @@ def sac_entropy_loss(
426423
)
427424
# We update all the _cont_ent_coef as one block
428425
entropy_loss += -1 * ModelUtils.masked_mean(
429-
torch.mean(_cont_ent_coef) * target_current_diff, loss_masks
426+
_cont_ent_coef * target_current_diff, loss_masks
430427
)
431428

432429
return entropy_loss

0 commit comments

Comments
 (0)