PyTorch衍生物无度

时间:2018-10-05 09:13:26

标签: python pytorch

我正在研究PyTorch官方docs的教程。我正在尝试了解内容。从You can do many crazy things with autograd!

开始
x = torch.randn(3, requires_grad=True)
y = x * 2

i = 0
while y.data.norm() < 100:
    y = y * 2
    i+= 1

print(x)
print(y)
print(i)

输出:

tensor([-0.6933,  0.1126,  0.3913], requires_grad=True)
tensor([-88.7455,  14.4082,  50.0871], grad_fn=<MulBackward>)
6

在点x上找到w.r.t到[0.1, 1.0, 0.0001]

gradients = torch.tensor([0.1, 1.0, 0.0001], dtype=torch.float)
y.backward(gradients)
print(x.grad)

输出:

tensor([ 12.8000, 128.0000,   0.0128])

据我了解,i等于6。然后y = (2x)^7和导数与PyTorch不同。替换值时,它以7为因数 到我的衍生物。

PyTorch的答案只是用x的给定点替换dy/dx = 2^7 * x

问题:

如何导出导数?

参考:

How to use PyTorch to calculate partial derivatives?

PyTorch Autograd automatic differentiation feature

1 个答案:

答案 0 :(得分:1)

如果仔细观察一下表达式,就会发现y = x * (2^7)的派生词是2^7 * x