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 PIR Unittest No.77,467】Fix test cast in PIR mode #64645

Merged
merged 2 commits into from
May 29, 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
1 change: 0 additions & 1 deletion paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
'sparse_momentum',
'tdm_sampler',
'soft_relu',
'uniform_random_batch_size_like',
'match_matrix_tensor',
'c_reduce_max',
'c_reduce_max_',
Expand Down
16 changes: 16 additions & 0 deletions python/paddle/tensor/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ def uniform_random_batch_size_like(
>>> print(out_2.shape)
[2, 3]
"""
if in_dynamic_or_pir_mode():
dtype = convert_np_dtype_to_dtype_(dtype)
return _C_ops.uniform_random_batch_size_like(
input,
shape,
input_dim_idx,
output_dim_idx,
min,
max,
seed,
0,
0,
1.0,
dtype,
)

check_variable_and_dtype(
input,
'Input',
Expand Down
1 change: 1 addition & 0 deletions test/deprecated/legacy_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ set_tests_properties(test_cumprod_op PROPERTIES TIMEOUT 300)
set_tests_properties(test_split_program PROPERTIES TIMEOUT 120)
set_tests_properties(test_graph_send_ue_recv_op PROPERTIES TIMEOUT 60)
set_tests_properties(test_graph_send_uv_op PROPERTIES TIMEOUT 60)
set_tests_properties(test_uniform_random_op_deprecated PROPERTIES TIMEOUT 60)

set_tests_properties(test_pretrained_model PROPERTIES TIMEOUT 120)
set_tests_properties(test_model PROPERTIES TIMEOUT 300)
Expand Down
67 changes: 67 additions & 0 deletions test/deprecated/legacy_test/test_uniform_random_op_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from test_attribute_var import UnittestBase

import paddle
from paddle.base import Program, program_guard


class TestUniformMinMaxTensor(UnittestBase):
def init_info(self):
self.shapes = [[2, 3, 4]]
self.save_path = os.path.join(self.temp_dir.name, self.path_prefix())

def test_static(self):
main_prog = Program()
startup_prog = Program()
with program_guard(main_prog, startup_prog):
fc = paddle.nn.Linear(4, 10)
x = paddle.randn([2, 3, 4])
x.stop_gradient = False
feat = fc(x) # [2,3,10]
min_v = paddle.to_tensor([0.1])
max_v = paddle.to_tensor([0.9])
y = paddle.uniform([2, 3, 10], min=min_v, max=max_v)
z = paddle.uniform([2, 3, 10], min=min_v, max=max_v)

out = feat + y + z

sgd = paddle.optimizer.SGD()
sgd.minimize(paddle.mean(out))
self.assertTrue(self.var_prefix() in str(main_prog))

exe = paddle.static.Executor()
exe.run(startup_prog)
res = exe.run(fetch_list=[out])
np.testing.assert_array_equal(res[0].shape, [2, 3, 10])

paddle.static.save_inference_model(self.save_path, [x], [out], exe)
# Test for Inference Predictor
infer_out = self.infer_prog()
np.testing.assert_array_equal(res[0].shape, [2, 3, 10])

def path_prefix(self):
return 'uniform_random'

def var_prefix(self):
return "Var["


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import numpy as np
from op import Operator
from op_test import OpTest, convert_uint16_to_float
from test_attribute_var import UnittestBase

import paddle
from paddle import base
Expand Down Expand Up @@ -733,46 +731,5 @@ def test_fixed_random_number(self):
paddle.enable_static()


class TestUniformMinMaxTensor(UnittestBase):
def init_info(self):
self.shapes = [[2, 3, 4]]
self.save_path = os.path.join(self.temp_dir.name, self.path_prefix())

def test_static(self):
main_prog = Program()
startup_prog = Program()
with program_guard(main_prog, startup_prog):
fc = paddle.nn.Linear(4, 10)
x = paddle.randn([2, 3, 4])
x.stop_gradient = False
feat = fc(x) # [2,3,10]
min_v = paddle.to_tensor([0.1])
max_v = paddle.to_tensor([0.9])
y = paddle.uniform([2, 3, 10], min=min_v, max=max_v)
z = paddle.uniform([2, 3, 10], min=min_v, max=max_v)

out = feat + y + z

sgd = paddle.optimizer.SGD()
sgd.minimize(paddle.mean(out))
self.assertTrue(self.var_prefix() in str(main_prog))

exe = paddle.static.Executor()
exe.run(startup_prog)
res = exe.run(fetch_list=[out])
np.testing.assert_array_equal(res[0].shape, [2, 3, 10])

paddle.static.save_inference_model(self.save_path, [x], [out], exe)
# Test for Inference Predictor
infer_out = self.infer_prog()
np.testing.assert_array_equal(res[0].shape, [2, 3, 10])

def path_prefix(self):
return 'uniform_random'

def var_prefix(self):
return "Var["


if __name__ == "__main__":
unittest.main()