def torch_zeros_like(x):
"""
Polyfill for `torch.zeros_like()`.
"""
# Work around https://github.com/pytorch/pytorch/issues/2906
if isinstance(x, Variable):
return Variable(torch_zeros_like(x.data))
# Support Pytorch before https://github.com/pytorch/pytorch/pull/2489
try:
return torch.zeros_like(x)
except AttributeError:
return torch.zeros(x.size()).type_as(x)
评论列表
文章目录