oneflow
oneflow copied to clipboard
flow.Tensor.scatter_()算子不存在
这个算子太重要了,实现smoothing损失可能会用到(虽然libai中用了另一种方式替代),以及一系列涉及3D视觉的操作非常需要,可以的话可能需要尽快添加
同时这个和之前那个flow.cumprod对我项目产生了影响,因为我如果要优雅地实现cumprod那就需要scatter,如果没有scatter我只能不优雅地去实现了
import oneflow as flow
import torch
a = torch.randn(1, 10)
c = torch.randn(1, 10)
b = torch.randint(9, (1, 3)).long()
a.scatter_(1, b, c)
print(a)
"""
libibverbs not available, ibv_fork_init skipped
tensor([[-0.7580, -0.3753, 0.1523, -0.5931, 0.5134, -0.5774, -0.4458, 1.3736,
-0.2529, -3.1916]])
Process finished with exit code 0
"""
a = flow.randn(1, 10)
c = flow.randn(1, 10)
b = flow.randint(9, (1, 3)).long()
a.scatter(1, b, c)
print(a)
"""
libibverbs not available, ibv_fork_init skipped
Traceback (most recent call last):
File "/home/sst/product/libai/alignment/ocumprod.py", line 19, in <module>
a.scatter_(1, b, c)
AttributeError: 'Tensor' object has no attribute 'scatter_'
"""
scatter 的inplace 方法还没有,不过 outplace 方法已经有了,可以暂时用
a = flow.scatter(a, ...)
的方式代替
a.scatter(...)
supported in https://github.com/Oneflow-Inc/oneflow/pull/9016