我已经尝试使用具有状态好奇心奖励的状态优化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
张量中发散。
答案 0 :(得分:0)
发现了问题...在主模型中,我使用softmax进行评估运行,并在输出层中使用log_softmax进行训练,根据PyTorch文档,CrossEntropyLoss在内部使用log_softmax,因此建议使用NLLLoss但是对于在输出层中没有softmax fnc的ICM模型损失的计算!因此,切换回 CrossEntropyLoss(这是参考代码中的原始内容)解决了ICM损耗差异。