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

[PIR] fix property overwrite #60225

Merged
merged 8 commits into from
Dec 26, 2023
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
19 changes: 12 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,21 @@ function(set_pit_tests_properties)
PIR_OP_TESTS)
foreach(IR_OP_TEST ${PIR_OP_TESTS})
if(TEST ${IR_OP_TEST})
set_tests_properties(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will lead to property overwritten by later settings and cause environment variables invaid.

${IR_OP_TEST} PROPERTIES ENVIRONMENT "FLAGS_PIR_OPTEST_WHITE_LIST=True")
set_property(
TEST ${IR_OP_TEST}
APPEND
PROPERTY ENVIRONMENT "FLAGS_PIR_OPTEST_WHITE_LIST=True")
endif()
endforeach()

file(STRINGS "${CMAKE_SOURCE_DIR}/test/white_list/pir_op_test_no_check_list"
PIR_OP_NO_CHECK_TESTS)
foreach(IR_OP_TEST ${PIR_OP_NO_CHECK_TESTS})
if(TEST ${IR_OP_TEST})
set_tests_properties(${IR_OP_TEST} PROPERTIES ENVIRONMENT
"FLAGS_PIR_NO_CHECK=True")
set_property(
TEST ${IR_OP_TEST}
APPEND
PROPERTY ENVIRONMENT "FLAGS_PIR_NO_CHECK=True")
endif()
endforeach()

Expand All @@ -115,9 +119,10 @@ function(set_pit_tests_properties)
PIR_OP_RELAXED_TESTS)
foreach(IR_OP_TEST ${PIR_OP_RELAXED_TESTS})
if(TEST ${IR_OP_TEST})
set_tests_properties(
${IR_OP_TEST} PROPERTIES ENVIRONMENT
"FLAGS_PIR_OPTEST_RELAX_CHECK=True")
set_property(
TEST ${IR_OP_TEST}
APPEND
PROPERTY ENVIRONMENT "FLAGS_PIR_OPTEST_RELAX_CHECK=True")
endif()
endforeach()

Expand Down
31 changes: 24 additions & 7 deletions test/legacy_test/op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,13 @@ def _check_ir_output(self, place, program, feed_map, fetch_list, outs):

check_method = np.testing.assert_array_equal
if os.getenv("FLAGS_PIR_OPTEST_RELAX_CHECK", None) == "True":
check_method = lambda x, y, z: np.testing.assert_allclose(
x, y, err_msg=z, atol=1e-6, rtol=1e-6
)

def relaxed_check(x, y, err_msg=""):
np.testing.assert_allclose(
x, y, err_msg=err_msg, atol=1e-6, rtol=1e-6
)

check_method = relaxed_check
if os.getenv("FLAGS_PIR_NO_CHECK", None) == "True":
check_method = lambda x, y, err_msg: None

Expand Down Expand Up @@ -3537,12 +3541,25 @@ def _check_ir_grad_output(

check_method = np.testing.assert_array_equal
if os.getenv("FLAGS_PIR_OPTEST_RELAX_CHECK", None) == "True":
check_method = lambda x, y, z: np.testing.assert_allclose(
x, y, err_msg=z, atol=1e-6, rtol=1e-6
)

def relaxed_check_method(x, y, err_msg):
atol = 1e-6
rtol = 1e-6
if x.dtype == np.float16:
atol = 1e-5
rtol = 1e-3
np.testing.assert_allclose(
x, y, err_msg=err_msg, atol=atol, rtol=rtol
)

check_method = relaxed_check_method

if os.getenv("FLAGS_PIR_NO_CHECK", None) == "True":
check_method = lambda x, y, err_msg: None

def no_check_method(x, y, err_msg):
pass

check_method = no_check_method

for i in range(len(new_gradients)):
check_method(
Expand Down
6 changes: 0 additions & 6 deletions test/white_list/pir_op_test_white_list
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ test_adadelta_op
test_adagrad_op
test_adagrad_op_static_build
test_adamax_op
test_adamw_op
test_adamw_op_static_build
test_addmm_op
test_affine_grid_op
test_allclose_op
test_amp_check_finite_and_scale_op
test_angle_op
Expand Down Expand Up @@ -60,14 +57,12 @@ test_conv2d_bf16_mkldnn_op
test_conv2d_int8_mkldnn_op
test_conv2d_mkldnn_op
test_conv2d_op
test_conv2d_op_depthwise_conv
test_conv2d_transpose_bf16_mkldnn_op
test_conv2d_transpose_mkldnn_op
test_conv2d_transpose_op
test_conv2d_transpose_op_depthwise_conv
test_conv3d_mkldnn_op
test_conv3d_op
test_conv3d_transpose_op
test_conv3d_transpose_part2_op
test_crop_tensor_op
test_cross_op
Expand Down Expand Up @@ -232,7 +227,6 @@ test_polygamma_op
test_pool2d_int8_mkldnn_op
test_pool2d_mkldnn_op
test_pool2d_op
test_pool3d_op
test_pool_max_op
test_prelu_mkldnn_op
test_prelu_op
Expand Down