问题:AttributeError: 'Tensor' object has no attribute 'creator'

AttributeError: 'Tensor' object has no attribute 'creator'

 问题:AttributeError: 'Tensor' object has no attribute 'creator'_第1张图片

根据pytorch官方文档的说法,变量具有如上的三个属性,在获取y操作的creator属性时,却出现没有该属性的错误。

import torch
from torch.autograd import Variable
x = Variable(torch.ones(1,3), requires_grad=True)
y = x+2
print('x: ', x)
print('y: ', y)
print(y.creator)

问题:AttributeError: 'Tensor' object has no attribute 'creator'_第2张图片

 经查,发现creator属性名称已经改为grad_fn,很多文档还未进行修改

github上修改提交:https://github.com/pytorch/tutorials/pull/91/files

问题:AttributeError: 'Tensor' object has no attribute 'creator'_第3张图片

修改之后,再次运行,即可获取y的已创建Function属性的属性Variable

import torch
from torch.autograd import Variable
x = Variable(torch.ones(1,3), requires_grad=True)
y = x+2
print('x: ', x)
print('y: ', y)
print(y.grad_fn)

你可能感兴趣的:(error)