梯度裁剪出错


#1

我在训练一个LSTM网络的时候,梯度裁剪是这样的:

params = [p.data() for p in model.collect_params().values()]
d2l.grad_clipping(params, clipping_theta, ctx)

与教程一致的,但在运行的时候报错:
File “E:/lstmtrain/first/firstlstm.py”, line 56, in train_rnn
d2l.grad_clipping(params, clipping_theta, ctx)

File “E:\lstmtrain\first\d2lzh\utils.py”, line 240, in grad_clipping
norm += (param.grad ** 2).sum()

TypeError: unsupported operand type(s) for ** or pow(): ‘NoneType’ and ‘int’

在训练程序中print(params),是存在的(至少打印出了),疑惑的是,para.grad好像在某个时候消失,出现NoneType。

请各位大神指点,谢谢!