PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)

Home Page:http://www.paddlepaddle.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

paddle的nansum不支持empty的求和

w5688414 opened this issue · comments

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

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