Skip to content

Commit 3081556

Browse files
committed
[API-Compat] XPU fix (attempt)
1 parent fd6adf0 commit 3081556

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

python/paddle/tensor/compat.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,11 @@ def min(input: Tensor, *args: Any, **kwargs: Any) -> Tensor | MinMaxRetType:
599599
dim_or_other, keepdim = _min_max_param_checker("min", *args, **kwargs)
600600

601601
if dim_or_other is None:
602-
return _C_ops.min(input, None, False)
602+
if input.numel() == 0:
603+
raise ValueError(
604+
"Reduce max cannot apply on empty tensor (numel == 0)"
605+
)
606+
return paddle.amin(input)
603607
elif isinstance(dim_or_other, int):
604608
if input.place.is_gpu_place():
605609
vals, inds = _C_ops.min_with_index(
@@ -714,7 +718,11 @@ def max(input: Tensor, *args: Any, **kwargs: Any) -> Tensor | MinMaxRetType:
714718
dim_or_other, keepdim = _min_max_param_checker("max", *args, **kwargs)
715719

716720
if dim_or_other is None:
717-
return _C_ops.max(input, None, False)
721+
if input.numel() == 0:
722+
raise ValueError(
723+
"Reduce max cannot apply on empty tensor (numel == 0)"
724+
)
725+
return paddle.amax(input)
718726
elif isinstance(dim_or_other, int):
719727
if input.place.is_gpu_place():
720728
vals, inds = _C_ops.max_with_index(

0 commit comments

Comments
 (0)