Skip to content

Commit 9e1f1ad

Browse files
committed
[API-Compat] XPU fix (attempt)
1 parent d646703 commit 9e1f1ad

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
@@ -600,7 +600,11 @@ def min(input: Tensor, *args: Any, **kwargs: Any) -> Tensor | MinMaxRetType:
600600
dim_or_other, keepdim = _min_max_param_checker("min", *args, **kwargs)
601601

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

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

0 commit comments

Comments
 (0)