mirror of
https://github.com/wassname/ray.git
synced 2026-07-11 21:43:06 +08:00
[RLlib] Fix PyTorch A3C / A2C loss function using mixed reduced sum / mean (#11449)
This commit is contained in:
@@ -18,11 +18,13 @@ def actor_critic_loss(policy, model, dist_class, train_batch):
|
||||
values = model.value_function()
|
||||
dist = dist_class(logits, model)
|
||||
log_probs = dist.logp(train_batch[SampleBatch.ACTIONS])
|
||||
policy.entropy = dist.entropy().mean()
|
||||
policy.entropy = dist.entropy().sum()
|
||||
policy.pi_err = -train_batch[Postprocessing.ADVANTAGES].dot(
|
||||
log_probs.reshape(-1))
|
||||
policy.value_err = nn.functional.mse_loss(
|
||||
values.reshape(-1), train_batch[Postprocessing.VALUE_TARGETS])
|
||||
policy.value_err = torch.sum(
|
||||
torch.pow(
|
||||
values.reshape(-1) - train_batch[Postprocessing.VALUE_TARGETS],
|
||||
2.0))
|
||||
overall_err = sum([
|
||||
policy.pi_err,
|
||||
policy.config["vf_loss_coeff"] * policy.value_err,
|
||||
|
||||
Reference in New Issue
Block a user