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.84,94,96,98,100,102,103,105,106,107,109,111,114,116,117,122,128,130,131,132,144,145,153,155,156,159,160,161,162,165,167,172,182,183,184,186,187,188,189,195,199,203,205,214,216,218,220,221,222,226,227,228,229,234,238,246,247,253,254,255,260,264,265,270,273,281,289,294,302,303,304,306,310,311,318,325,328,331,332,333,334,335,337,339,340,343,345,346,347,349,350,351,354,357,360,361,364,365,368,371,372,375,376,379,383,387,394,397,410,414,418,421,424,430,450,454,457,458,468,470,471,473,485,488,489,494,496,502,503,518,520,521,524,532,535,538,539】Fix some test case in PIR #64754

Merged
merged 9 commits into from
Jun 4, 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
81 changes: 3 additions & 78 deletions test/deprecated/legacy_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ endif()

if(WIN32)
list(REMOVE_ITEM TEST_OPS test_complex_matmul)
list(REMOVE_ITEM TEST_OPS test_ops_nms)
list(REMOVE_ITEM TEST_OPS test_trt_convert_preln_residual_bias)
list(REMOVE_ITEM TEST_OPS test_masked_multihead_attention_op)
list(REMOVE_ITEM TEST_OPS test_fused_ec_moe_op)
Expand Down Expand Up @@ -401,8 +400,6 @@ endfunction()
list(REMOVE_ITEM TEST_OPS test_feed_data_check_shape_type)
list(REMOVE_ITEM TEST_OPS test_fetch_lod_tensor_array)
list(REMOVE_ITEM TEST_OPS test_data_norm_op)
list(REMOVE_ITEM TEST_OPS test_bilinear_interp_op)
list(REMOVE_ITEM TEST_OPS test_nearest_interp_op)
list(REMOVE_ITEM TEST_OPS test_imperative_mnist_sorted_gradient)
list(REMOVE_ITEM TEST_OPS test_imperative_mnist)
list(REMOVE_ITEM TEST_OPS test_layers_deprecated)
Expand Down Expand Up @@ -452,8 +449,7 @@ endif()

# Some ops need to check results when gc is enabled
# Currently, only ops that register NoNeedBufferVarsInference need to do this test
set(TEST_OPS_WITH_GC test_affine_channel_op test_gather_nd_op test_scatter_op
test_slice_op)
set(TEST_OPS_WITH_GC test_gather_nd_op test_slice_op)

foreach(TEST_OP ${TEST_OPS_WITH_GC})
list(REMOVE_ITEM TEST_OPS ${TEST_OP})
Expand Down Expand Up @@ -485,10 +481,6 @@ set_tests_properties(test_logcumsumexp_op PROPERTIES TIMEOUT 30)
py_test_modules(test_adam_op_multi_thread MODULES test_adam_op ENVS
FLAGS_inner_op_parallelism=4)

py_test_modules(test_bilinear_interp_op MODULES test_bilinear_interp_op ENVS
${GC_ENVS})
py_test_modules(test_nearest_interp_op MODULES test_nearest_interp_op ENVS
${GC_ENVS})
py_test_modules(test_imperative_mnist MODULES test_imperative_mnist ENVS
FLAGS_cudnn_deterministic=1)
py_test_modules(
Expand All @@ -511,8 +503,6 @@ if((WITH_GPU) AND (WITH_CUDNN_FRONTEND))
test_fused_dot_product_attention_op)
endif()

set_tests_properties(test_conv2d_op_depthwise_conv
PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE")
set_tests_properties(test_conv2d_api_deprecated PROPERTIES LABELS
"RUN_TYPE=EXCLUSIVE")
set_tests_properties(test_conv_nn_grad PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE")
Expand Down Expand Up @@ -644,17 +634,10 @@ endif()
set_tests_properties(test_cross_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_lod_tensor_to_selected_rows
PROPERTIES TIMEOUT 200)
set_tests_properties(test_lstm_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_star_gan_with_gradient_penalty
PROPERTIES TIMEOUT 120)

set_tests_properties(test_bicubic_interp_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_deformable_conv_op PROPERTIES TIMEOUT 200)
set_tests_properties(test_nearest_interp_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_inplace_softmax_with_cross_entropy PROPERTIES TIMEOUT
120)
set_tests_properties(test_cross_entropy2_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_gru_unit_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_regularizer_api PROPERTIES TIMEOUT 150)
if(NOT WIN32)
if(WITH_NV_JETSON)
Expand All @@ -666,75 +649,45 @@ set_tests_properties(test_bilateral_slice_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_fleet_util PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_transformer_sorted_gradient
PROPERTIES TIMEOUT 120)
set_tests_properties(test_matmul_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_nearest_interp_v2_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_trilinear_interp_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_static_save_load PROPERTIES TIMEOUT 250)
set_tests_properties(test_paddle_save_load_binary PROPERTIES TIMEOUT 120)
if(WIN32)
set_tests_properties(test_static_save_load_large PROPERTIES TIMEOUT 900)
else()
set_tests_properties(test_static_save_load_large PROPERTIES TIMEOUT 600)
endif()
if(WITH_NV_JETSON)
set_tests_properties(test_conv3d_transpose_part2_op PROPERTIES TIMEOUT 1200)
set_tests_properties(test_layer_norm_op PROPERTIES TIMEOUT 1500)
set_tests_properties(test_pool3d_op PROPERTIES TIMEOUT 1500)
else()
set_tests_properties(test_conv3d_transpose_part2_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_layer_norm_op PROPERTIES TIMEOUT 250)
set_tests_properties(test_pool3d_op PROPERTIES TIMEOUT 150)
endif()

set_tests_properties(test_imperative_selected_rows_to_lod_tensor
PROPERTIES TIMEOUT 200)
set_tests_properties(test_index_select_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_index_add_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_argsort_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_gather_nd_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_row_conv_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_deformable_conv_v1_op PROPERTIES TIMEOUT 300)
set_tests_properties(test_imperative_ptb_rnn_sorted_gradient PROPERTIES TIMEOUT
120)
set_tests_properties(test_crop_tensor_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_ptb_rnn PROPERTIES TIMEOUT 120)
set_tests_properties(test_svd_op PROPERTIES TIMEOUT 80)
set_tests_properties(test_qr_op PROPERTIES TIMEOUT 60)
set_tests_properties(test_trilinear_interp_v2_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_masked_select_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_sigmoid_cross_entropy_with_logits_op
PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_optimizer_v2 PROPERTIES TIMEOUT 150)
set_tests_properties(test_partial_sum_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_sgd_op PROPERTIES TIMEOUT 250)
set_tests_properties(test_generator_dataloader_deprecated PROPERTIES TIMEOUT
120)
set_tests_properties(test_partial_concat_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_reduce_op PROPERTIES TIMEOUT 500)
set_tests_properties(test_conv_nn_grad PROPERTIES TIMEOUT 220)
set_tests_properties(test_program_prune_backward PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_optimizer_v2 PROPERTIES TIMEOUT 250)
set_tests_properties(test_bilinear_interp_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_decoupled_py_reader PROPERTIES TIMEOUT 120)
set_tests_properties(test_fuse_bn_act_pass PROPERTIES TIMEOUT 120)
set_tests_properties(test_conv2d_op_depthwise_conv PROPERTIES TIMEOUT 120)
set_tests_properties(test_conv2d_api_deprecated PROPERTIES TIMEOUT 120)
set_tests_properties(test_elementwise_mul_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_dygraph_multi_forward PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_ocr_attention_model PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_mnist PROPERTIES TIMEOUT 120)
set_tests_properties(test_gru_op PROPERTIES TIMEOUT 200)
set_tests_properties(test_regularizer PROPERTIES TIMEOUT 150)
set_tests_properties(test_matmul_v2_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_slice_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_pad3d_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_dataloader_keep_order PROPERTIES TIMEOUT 120)
set_tests_properties(test_dataloader_unkeep_order PROPERTIES TIMEOUT 120)
set_tests_properties(test_reader_reset PROPERTIES TIMEOUT 120)
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)
Expand All @@ -756,36 +709,17 @@ set_tests_properties(test_inplace_addto_strategy_deprecated PROPERTIES TIMEOUT

set(TEST_CINN_OPS
test_softmax_op
test_expand_v2_op
test_reduce_op
test_slice_op
test_full_like_op
test_index_select_op
test_top_k_v2_op
test_elementwise_mul_op
test_gather_nd_op
test_elementwise_pow_op
test_reshape_op
test_meshgrid_op
test_scale_op
test_scatter_op
test_layer_norm_op
test_cast_op
test_roll_op
test_atan2_op
test_top_k_op
test_where_op
test_arg_min_max_op
test_reverse_op
test_flip
test_triangular_solve_op
test_scatter_nd_op
test_instance_norm_op
test_cumsum_op
test_split_op
test_erf_op
test_assign_op
test_flatten_contiguous_range_op)
test_erf_op)

foreach(TEST_CINN_OP ${TEST_CINN_OPS})
if(WITH_CINN)
Expand All @@ -810,16 +744,12 @@ set(STATIC_BUILD_TESTS
test_batch_norm_op
test_bincount_op
test_decoupled_py_reader
test_eigh_op
test_fetch_lod_tensor_array
test_fuse_bn_act_pass
test_layer_norm_op
test_lookup_table_v2_op_deprecated
test_matmul_op
test_matmul_v2_op
test_momentum_op
test_nce
test_paddle_save_load_binary
test_reduce_op
test_sparse_conv_op
test_sparse_norm_op
Expand Down Expand Up @@ -863,18 +793,13 @@ set_tests_properties(
ENVIRONMENT
"FLAGS_cudnn_deterministic=1;FLAGS_cudnn_batchnorm_spatial_persistent=1;FLAGS_conv_workspace_size_limit=1000"
)
set_tests_properties(test_matmul_op_static_build PROPERTIES TIMEOUT 120)
set_tests_properties(test_matmul_v2_op_static_build PROPERTIES TIMEOUT 120)
set_tests_properties(test_layer_norm_op_static_build PROPERTIES TIMEOUT 1500)
set_tests_properties(test_paddle_save_load_binary_static_build
PROPERTIES TIMEOUT 120)
set_tests_properties(test_reduce_op_static_build PROPERTIES TIMEOUT 500)
py_test_modules(test_stride MODULES test_stride ENVS
FLAGS_use_stride_kernel=true)

set_tests_properties(test_linalg_matrix_exp PROPERTIES TIMEOUT 120)
set_pir_tests_properties()

set_tests_properties(test_fractional_max_pool2d_op PROPERTIES TIMEOUT 120)

set_tests_properties(test_reduce_as_op PROPERTIES TIMEOUT 30)
set_tests_properties(test_attribute_var_deprecated PROPERTIES TIMEOUT 100)
2 changes: 1 addition & 1 deletion test/deprecated/legacy_test/test_adaptive_avg_pool2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unittest

import numpy as np
from test_attribute_var import UnittestBase
from test_attribute_var_deprecated import UnittestBase

import paddle
from paddle.base import Program, core, program_guard
Expand Down
2 changes: 1 addition & 1 deletion test/deprecated/legacy_test/test_arg_min_max_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
from op_test import OpTest, convert_float_to_uint16
from test_attribute_var import UnittestBase
from test_attribute_var_deprecated import UnittestBase

import paddle
from paddle.base import Program, program_guard
Expand Down
107 changes: 107 additions & 0 deletions test/deprecated/legacy_test/test_attribute_var_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright (c) 2022 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 tempfile
import unittest

import numpy as np

import paddle
import paddle.inference as paddle_infer
from paddle.base.framework import Program, program_guard

paddle.enable_static()


class UnittestBase(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.init_info()

def tearDwon(self):
self.temp_dir.cleanup()

def init_info(self):
self.shapes = None
self.save_path = None

def path_prefix(self):
return type(self).__name__

def infer_prog(self):
config = paddle_infer.Config(
self.save_path + '.pdmodel', self.save_path + '.pdiparams'
)
config.disable_mkldnn()
predictor = paddle_infer.create_predictor(config)
input_names = predictor.get_input_names()
for i, shape in enumerate(self.shapes):
input_handle = predictor.get_input_handle(input_names[i])
self.fake_input = np.random.randn(*shape).astype("float32")
input_handle.reshape(shape)
input_handle.copy_from_cpu(self.fake_input)
predictor.run()
output_names = predictor.get_output_names()
res = []
for out_name in output_names:
output_handle = predictor.get_output_handle(out_name)
output_data = output_handle.copy_to_cpu()
res.append(output_data)

if len(output_names) == 1:
res = res[0]

return res


class TestDropout(UnittestBase):
def init_info(self):
self.shapes = [[10, 10]]
self.save_path = os.path.join(self.temp_dir.name, 'dropout')

def test_static(self):
main_prog = Program()
startup_prog = Program()
with program_guard(main_prog, startup_prog):
fc = paddle.nn.Linear(10, 10)
x = paddle.randn(self.shapes[0])
x.stop_gradient = False
feat = fc(x)
# p is a Variable
p = paddle.randn([1])
out = paddle.nn.functional.dropout(feat, p=p)
sgd = paddle.optimizer.SGD()
sgd.minimize(paddle.mean(out))
# test _to_string
self.assertTrue("Var[" in str(main_prog))

exe = paddle.static.Executor()
exe.run(startup_prog)
res = exe.run(fetch_list=[x, out])
# export model
paddle.static.save_inference_model(self.save_path, [x], [out], exe)

# Test for Inference Predictor
infer_out = self.infer_prog()
self.assertEqual(infer_out.shape, (10, 10))

self.assertEqual(
main_prog.block(0).ops[4].all_attrs()['dropout_prob'].name,
p.name,
)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion test/deprecated/legacy_test/test_eye_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
from op_test import OpTest
from test_attribute_var import UnittestBase
from test_attribute_var_deprecated import UnittestBase

import paddle
from paddle import base
Expand Down
2 changes: 1 addition & 1 deletion test/deprecated/legacy_test/test_multinomial_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
from op_test import OpTest, convert_float_to_uint16
from test_attribute_var import UnittestBase
from test_attribute_var_deprecated import UnittestBase

import paddle
from paddle import base
Expand Down
Loading