你可以按照讨论进行 这里
它的要点是并非所有运营商目前都支持更高阶梯度。
在Gluon中,您可以尝试以下方法:
with mx.autograd.record(): output = net(x) loss = loss_func(output) dz = mx.autograd.grad(loss, [z], create_graph=True) # where [z] is the parameter(s) you want dz[0].backward() # now the actual parameters should have second order gradients
取自此 论坛帖子