Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_int_tensor_list #63593

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None, name=None):
paddle.utils.check_shape(shape)
if isinstance(shape, (list, tuple)):
if paddle.utils._contain_var(shape):
shape = paddle.utils.get_int_tensor_list(shape, place)
shape = paddle.utils.get_int_tensor_list(shape)
elif isinstance(shape, paddle.pir.Value):
pass
else:
Expand Down Expand Up @@ -2150,9 +2150,7 @@ def empty(shape, dtype=None, name=None):
shape = shape.tolist()
if isinstance(shape, (list, tuple)):
if paddle.utils._contain_var(shape):
shape = paddle.utils.get_int_tensor_list(
shape, _current_expected_place()
)
shape = paddle.utils.get_int_tensor_list(shape)
elif isinstance(shape, paddle.pir.Value):
pass
else:
Expand Down
12 changes: 3 additions & 9 deletions python/paddle/tensor/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,9 +931,7 @@ def uniform(shape, dtype=None, min=-1.0, max=1.0, seed=0, name=None):
check_type(min, 'min', (float, int, paddle.pir.Value), 'uniform/rand')
check_type(max, 'max', (float, int, paddle.pir.Value), 'uniform/rand')
if paddle.utils._contain_var(shape):
shape = paddle.utils.get_int_tensor_list(
shape, _current_expected_place()
)
shape = paddle.utils.get_int_tensor_list(shape)
return _C_ops.uniform(
shape,
dtype,
Expand Down Expand Up @@ -1115,9 +1113,7 @@ def randint(low=0, high=None, shape=[1], dtype=None, name=None):
check_shape(shape, 'randint')
check_dtype(dtype, 'dtype', ['int32', 'int64'], 'randint')
if paddle.utils._contain_var(shape):
shape = paddle.utils.get_int_tensor_list(
shape, _current_expected_place()
)
shape = paddle.utils.get_int_tensor_list(shape)
return _C_ops.randint(
low, high, shape, dtype, _current_expected_place()
)
Expand Down Expand Up @@ -1336,9 +1332,7 @@ def randint_like(x, low=0, high=None, dtype=None, name=None):
'randint_like',
)
if paddle.utils._contain_var(shape):
shape = paddle.utils.get_int_tensor_list(
shape, _current_expected_place()
)
shape = paddle.utils.get_int_tensor_list(shape)
out = _C_ops.randint(
low, high, shape, DataType.INT64, _current_expected_place()
)
Expand Down
16 changes: 6 additions & 10 deletions python/paddle/utils/layers_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from ..base.framework import (
Block,
Variable,
_current_expected_place,
in_dygraph_mode,
)
from ..pir import Value
Expand Down Expand Up @@ -383,10 +382,7 @@ def _contain_var(list_or_tuple):
return False


def get_int_tensor_list(ele_list, place=None, default_dtype='int64'):
if place is None:
place = _current_expected_place()

def get_int_tensor_list(ele_list, default_dtype='int64'):
int_tensor_list = []
for ele in ele_list:
if isinstance(ele, paddle.pir.Value):
Expand All @@ -397,11 +393,11 @@ def get_int_tensor_list(ele_list, place=None, default_dtype='int64'):
ele = paddle.reshape(ele, [])
int_tensor_list.append(ele)
else:
temp_out = paddle.full(
[],
ele,
convert_np_dtype_to_dtype_(np.dtype(default_dtype)),
place,
temp_out = paddle.tensor.fill_constant(
shape=[],
dtype=convert_np_dtype_to_dtype_(np.dtype(default_dtype)),
value=ele,
force_cpu=True,
)
int_tensor_list.append(temp_out)
return int_tensor_list
Expand Down