paddle的nansum不支持empty的求和

im9ewurl  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(48)

bug描述 Describe the Bug

>>> import paddle
>>> x = paddle.to_tensor([])
x>>> x.nansum()
W0517 13:31:49.496955 61548 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 8.0, Driver API Version: 11.8, Runtime API Version: 11.8
W0517 13:31:49.522248 61548 gpu_resources.cc:164] device: 0, cuDNN Version: 8.6.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/paddlejob/workspace/output/wugaosheng/wu391/lib/python3.9/site-packages/paddle/tensor/math.py", line 1762, in nansum
    return sum(tmp_tensor, axis, dtype, keepdim, name)
  File "/root/paddlejob/workspace/output/wugaosheng/wu391/lib/python3.9/site-packages/paddle/tensor/math.py", line 1534, in sum
    return _C_ops.sum(x, axis, dtype, keepdim)
ValueError: (InvalidArgument) Tensor need be reduced must not empty.
  [Hint: Expected x.numel() > 0, but received x.numel():0 <= 0:0.] (at ../paddle/phi/kernels/funcs/reduce_function.h:1055)

>>> x.is_empty()
Tensor(shape=[], dtype=bool, place=Place(cpu), stop_gradient=True,
       True)
>>> import torch
>>> x1 = torch.Tensor([])
>>> x1.nansum()
tensor(0.)

其他补充信息 Additional Supplementary Information

7fyelxc5

7fyelxc51#

你好,从语义上来说,empty Tensor的数值计算应该属于未定义行为,请问目前对这个计算,有具体的需求场景吗

qc6wkl3g

qc6wkl3g2#

大模型alignment算法KTO复现需要。

https://github.com/huggingface/trl/blob/99f2c94b2200927a1dc156f16e012dca11f865e1/trl/trainer/kto_trainer.py#L1328

相关问题