Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,15 @@ void CumInferMeta(const MetaTensor& x,
bool reverse,
MetaTensor* out) {
auto x_dims = x.dims();
auto x_dtype = x.dtype();
auto out_dtype =
(x_dtype == phi::DataType::UINT8 || x_dtype == phi::DataType::INT8 ||
x_dtype == phi::DataType::INT16 || x_dtype == phi::DataType::INT32)
? phi::DataType::INT64
: x_dtype;
if (flatten) {
out->set_dims(common::make_ddim({common::product(x_dims)}));
out->set_dtype(x.dtype());
out->set_dtype(out_dtype);
} else {
if (x_dims.size() > 0) {
PADDLE_ENFORCE_GE(
Expand Down Expand Up @@ -667,7 +673,7 @@ void CumInferMeta(const MetaTensor& x,
axis));
}
out->set_dims(x_dims);
out->set_dtype(x.dtype());
out->set_dtype(out_dtype);
}

out->share_lod(x);
Expand Down
9 changes: 8 additions & 1 deletion python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -4308,7 +4308,7 @@ def cumsum(
Args:
x (Tensor): The input tensor needed to be cumsumed.
axis (int, optional): The dimension to accumulate along. -1 means the last dimension. The default (None) is to compute the cumsum over the flattened array.
dtype (str|paddle.dtype|np.dtype|None, optional): The data type of the output tensor, can be bfloat16, float16, float32, float64, int32, int64, complex64, complex128. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. The default value is None.
dtype (str|paddle.dtype|np.dtype|None, optional): The data type of the output tensor, can be bfloat16, float16, float32, float64, int32, int64, complex64, complex128. By default, it is int64 if the input x is int8/int16/int32; otherwise, it is None. If it is not None, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
Expand Down Expand Up @@ -4350,6 +4350,13 @@ def cumsum(
flatten = False
if dtype is not None and x.dtype != convert_np_dtype_to_dtype_(dtype):
x = cast(x, dtype)
elif isinstance(x, paddle.Tensor) and x.dtype in [
paddle.uint8,
paddle.int8,
paddle.int16,
paddle.int32,
]:
x = cast(x, "int64")

if in_dynamic_or_pir_mode():
if axis is None:
Expand Down
Loading