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

时间:2019-07-11 23:14:52

标签: python lstm recurrent-neural-network reinforcement-learning

我已经尝试使用具有状态好奇心奖励的状态优化LSTM神经网络实现近端策略优化。

PPO和ICM的损失都存在差异,我想找出它的代码错误还是选择错误的超参数。

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

  • 在ICM模型中,我也使用第一层LSTM来匹配输入尺寸。
  • 在ICM中,整个数据集一次传播,初始隐藏为零(结果张量不同,这与如果我仅传播1个状态或批处理并重复使用隐藏的单元格会不同)
  • 在PPO优势和折扣奖励处理中,数据集被一次传播,并且隐藏的单元被重复使用(与ICM中的情况完全相反,因为在这里它使用相同的模型来选择动作,并且这种方法“类似于实时” )
  • 在PPO中,训练模型是分批训练的,可重复使用隐藏细胞

我已经使用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张量中发散。

1 个答案:

答案 0 :(得分:0)

发现了问题...在主模型中,我使用softmax进行评估运行,并在输出层中使用log_softmax进行训练,根据PyTorch文档,CrossEntropyLoss在内部使用log_softmax,因此建议使用NLLLoss但是对于在输出层中没有softmax fnc的ICM模型损失的计算!因此,切换回 CrossEntropyLoss(这是参考代码中的原始内容)解决了ICM损耗差异。