使用 LSTM 在 PPO + ICM 中分散损失

Diverging losses in PPO + ICM using LSTM

我已尝试为有状态 LSTM 神经网络实施具有内在好奇心奖励的近端策略优化。

PPO 和 ICM 的损失是不同的,我想知道它是代码错误还是超参数选择不当。

代码(可能是一些错误的实现):

我使用 https://github.com/adik993/ppo-pytorch 作为默认代码,并在我的环境中将其改写为 运行 并使用 LSTM

如果由于行数过多而特别要求,我可能会稍后提供代码示例

超参数:

def __init_curiosity(self):
        curiosity_factory=ICM.factory(MlpICMModel.factory(), policy_weight=1,
                                      reward_scale=0.1, weight=0.2,
                                      intrinsic_reward_integration=0.01,
                                      reporter=self.reporter)
        self.curiosity = curiosity_factory.create(self.state_converter,
                                                  self.action_converter)
        self.curiosity.to(self.device, torch.float32)
        self.reward_normalizer = StandardNormalizer()
    
def __init_PPO_trainer(self):
        self.PPO_trainer = PPO(agent = self,
                               reward = GeneralizedRewardEstimation(gamma=0.99, lam=0.95),
                               advantage = GeneralizedAdvantageEstimation(gamma=0.99, lam=0.95),
                               learning_rate = 1e-3,
                               clip_range = 0.3,
                               v_clip_range = 0.3,
                               c_entropy = 1e-2,
                               c_value = 0.5,
                               n_mini_batches = 32,
                               n_optimization_epochs = 10,                               
                               clip_grad_norm = 0.5)
        self.PPO_trainer.to(self.device, torch.float32)

训练图:

(注意 y 轴上的大数字)


更新

现在我已经重新处理 LSTM 处理以在所有地方(对于主模型和 ICM)使用批处理和隐藏内存,但问题仍然存在。我已经追踪到 ICM 模型的输出,这里的输出主要在 action_hat 张量中发散。

发现问题...在主模型中,我使用 softmax 进行评估运行,使用 log_softmax 进行输出层训练,根据 PyTorch 文档,CrossEntropyLoss uses log_softmax inside, so as advised I used NLLLoss but forthe computation of ICM model loss which does not have softmax fnc in output layer! So switching back to CrossEntropyLoss(在参考代码中是原始的)解决了 ICM 损失分歧。