Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
a162837 committed Nov 3, 2024
1 parent ae29dcc commit e2f56b1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -3831,17 +3831,17 @@ def clip(

else:
if in_dynamic_or_pir_mode():
if isinstance(min, Variable):
if isinstance(min, (Variable, paddle.pir.Value, paddle.Tensor)):
min = min.item(0)
if isinstance(max, Variable):
if isinstance(max, (Variable, paddle.pir.Value, paddle.Tensor)):
max = max.item(0)
min = min_ if min is None else min
max = max_ if max is None else max
return _C_ops.clip(x, min, max)
else:
if min is not None:
check_type(min, 'min', (float, int, Variable), 'clip')
if isinstance(min, Variable):
check_type(min, 'min', (float, int, Variable, paddle.Tensor), 'clip')
if isinstance(min, (Variable, paddle.Tensor)):
check_dtype(
min.dtype,
'min',
Expand All @@ -3850,8 +3850,8 @@ def clip(
'(When the type of min in clip is Variable.)',
)
if max is not None:
check_type(max, 'max', (float, int, Variable), 'clip')
if isinstance(max, Variable):
check_type(max, 'max', (float, int, Variable, paddle.Tensor), 'clip')
if isinstance(max, (Variable, paddle.Tensor)):
check_dtype(
max.dtype,
'max',
Expand All @@ -3870,13 +3870,13 @@ def clip(
inputs = {'X': x}
attrs = {'min': min_, 'max': max_}

if isinstance(min, Variable):
if isinstance(min, (Variable, paddle.Tensor)):
min.stop_gradient = True
inputs['Min'] = min
elif min is not None:
attrs['min'] = min

if isinstance(max, Variable):
if isinstance(max, (Variable, paddle.Tensor)):
max.stop_gradient = True
inputs['Max'] = max
elif max is not None:
Expand Down

0 comments on commit e2f56b1

Please sign in to comment.