Skip to content

Commit 809e8c2

Browse files
committed
[API-Compat] XPU fix (attempt)
1 parent 0135ca0 commit 809e8c2

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

417417
if dim_or_other is None:
418-
return _C_ops.min(input, None, False)
418+
if input.numel() == 0:
419+
raise ValueError(
420+
"Reduce max cannot apply on empty tensor (numel == 0)"
421+
)
422+
return paddle.amin(input)
419423
elif isinstance(dim_or_other, int):
420424
if input.place.is_gpu_place():
421425
vals, inds = _C_ops.min_with_index(
@@ -530,7 +534,11 @@ def max(input: Tensor, *args: Any, **kwargs: Any) -> Tensor | MinMaxRetType:
530534
dim_or_other, keepdim = _min_max_param_checker("max", *args, **kwargs)
531535

532536
if dim_or_other is None:
533-
return _C_ops.max(input, None, False)
537+
if input.numel() == 0:
538+
raise ValueError(
539+
"Reduce max cannot apply on empty tensor (numel == 0)"
540+
)
541+
return paddle.amax(input)
534542
elif isinstance(dim_or_other, int):
535543
if input.place.is_gpu_place():
536544
vals, inds = _C_ops.max_with_index(

0 commit comments

Comments
 (0)