可以修改r割炬中张量的毕业
我正在尝试修改火炬中的张量的梯度,以r :
library(torch)
x <- torch_randn(10,2)
x$grad <- torch_randn(10,2)
但是,我会遇到以下错误:
Erreur dans f(value) : argument inutilisé (value)
2: `$<-.R7`(`*tmp*`, grad, value = <pointer: 0x55cd40aefae0>)
1: `$<-`(`*tmp*`, grad, value = <pointer: 0x55cd40aefae0>)
我以为我认为我做错了什么(有时梯度有些棘手),但是当我在Python中尝试同一件事,它可以正常工作:
import torch
x = torch.randn(10,2)
x.grad = torch.randn(10,2)
当我调用x $ grad
在r中时,我得到[tensor(undefined)]
,但这不应该是问题由于在Python中效果很好。
谢谢。
I am trying to modify the gradient of a tensor in torch for R:
library(torch)
x <- torch_randn(10,2)
x$grad <- torch_randn(10,2)
However, I get the following error:
Erreur dans f(value) : argument inutilisé (value)
2: `lt;-.R7`(`*tmp*`, grad, value = <pointer: 0x55cd40aefae0>)
1: `lt;-`(`*tmp*`, grad, value = <pointer: 0x55cd40aefae0>)
I thought I was doing something wrong (gradients are a little bit tricky sometimes), but when I try the same thing in python it works just fine:
import torch
x = torch.randn(10,2)
x.grad = torch.randn(10,2)
When I call x$grad
in R, I get [ Tensor (undefined) ]
, but this should not be a problem since it works fine in python.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我在评论中指出时,这看起来像是一个错误。但是,作为解决方法,您可以做类似的事情:
This looks like a bug as I point in the comment. As a workaround, though, you can do something like: