fix: squeeze old_log_prob and advantages dims (match upstream)

This commit is contained in:
8x54zj-m
2026-06-30 15:39:03 +08:00
parent aa17ea853e
commit 6348cf72bc

View File

@@ -158,9 +158,9 @@ class DreamWaQPPO(PPO):
old_actions_log_prob_batch, advantages_batch old_actions_log_prob_batch, advantages_batch
) -> torch.Tensor: ) -> torch.Tensor:
"""计算 PPO 代理损失(从父类 PPO.update() 中提取)。""" """计算 PPO 代理损失(从父类 PPO.update() 中提取)。"""
ratio = torch.exp(actions_log_prob_batch - old_actions_log_prob_batch) ratio = torch.exp(actions_log_prob_batch - torch.squeeze(old_actions_log_prob_batch))
surrogate = -advantages_batch * ratio surrogate = -torch.squeeze(advantages_batch) * ratio
surrogate_clipped = -advantages_batch * torch.clamp( surrogate_clipped = -torch.squeeze(advantages_batch) * torch.clamp(
ratio, 1.0 - self.clip_param, 1.0 + self.clip_param) ratio, 1.0 - self.clip_param, 1.0 + self.clip_param)
return torch.max(surrogate, surrogate_clipped).mean() return torch.max(surrogate, surrogate_clipped).mean()