RuntimeError:element 0 of tensors does not require grad and does not have a grad_fn
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
x = torch.ones(1)
# 默认requires_grad = False
print x.requires_grad
# False
y = torch.ones(1)
#y的requires_grad标志也是False
z = x + y
# z的requires_grad也是False, 所以如果试图对z做梯度反传,会抛出Error
z.backward()
RuntimeError: element 0 of tensors does not require grad and does not
have a grad_fn
w = torch.zeros(1, requires_grad=True)
# 创建 requires_grad=True 的Tensor
print w.requires_grad
#True
total = w + z
print total.requires_grad
#True
total.backward()
print w.grad
#tensor([ 1.])
print z.grad == x.grad == y.grad == None
#True
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)