CMakeLists.txt 19.2 KB
Newer Older
W
WangZhen 已提交
1 2 3
file(GLOB TEST_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py")
string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}")

4
function(_inference_analysis_python_api_int8_test target model_dir data_path filename use_mkldnn)
5
    py_test(${target} SRCS ${filename}
6
        ENVS CPU_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
7
             FLAGS_use_mkldnn=${use_mkldnn}
8
        ARGS --infer_model ${model_dir}/model
9
             --infer_data ${data_path}
10
             --int8_model_save_path int8_models/${target}
11
             --warmup_batch_size ${WARMUP_BATCH_SIZE}
12 13 14
             --batch_size 50)
endfunction()

15 16
function(inference_analysis_python_api_int8_test target model_dir data_path filename)
    _inference_analysis_python_api_int8_test(${target} ${model_dir} ${data_path} ${filename} False)
17 18
endfunction()

19 20 21 22 23
function(inference_analysis_python_api_int8_test_custom_warmup_batch_size target model_dir data_dir filename warmup_batch_size)
    set(WARMUP_BATCH_SIZE ${warmup_batch_size})
    inference_analysis_python_api_int8_test(${target} ${model_dir} ${data_dir} ${filename})
endfunction()

24 25 26 27
function(inference_analysis_python_api_int8_test_mkldnn target model_dir data_path filename)
    _inference_analysis_python_api_int8_test(${target} ${model_dir} ${data_path} ${filename} True)
endfunction()

W
Wangzheee 已提交
28
function(download_quant_data install_dir data_file check_sum)
29
    if (NOT EXISTS ${install_dir}/${data_file})
W
Wangzheee 已提交
30
	    inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/int8 ${data_file} ${check_sum})
31 32 33
    endif()
endfunction()

W
Wangzheee 已提交
34
function(download_quant_model install_dir data_file check_sum)
35
    if (NOT EXISTS ${install_dir}/${data_file})
W
Wangzheee 已提交
36
	    inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/int8/QAT_models ${data_file} ${check_sum})
37 38 39
    endif()
endfunction()

W
Wangzheee 已提交
40
function(download_quant_fp32_model install_dir data_file check_sum)
41
    if (NOT EXISTS ${install_dir}/${data_file})
W
Wangzheee 已提交
42
	    inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/int8/QAT_models/fp32 ${data_file} ${check_sum})
43 44 45
    endif()
endfunction()

46 47 48 49 50 51
function(download_lstm_model install_dir data_file check_sum)
    if (NOT EXISTS ${install_dir}/${data_file})
	    inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/lstm ${data_file} ${check_sum})
    endif()
endfunction()

W
Wojciech Uss 已提交
52
function(inference_quant_int8_image_classification_test target quant_model_dir dataset_path)
53
    py_test(${target} SRCS "${CMAKE_CURRENT_SOURCE_DIR}/quant_int8_image_classification_comparison.py"
54 55
            ENVS FLAGS_OMP_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
                 OMP_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
56
                 FLAGS_use_mkldnn=true
W
Wojciech Uss 已提交
57
            ARGS --quant_model ${quant_model_dir}
58
                 --infer_data ${dataset_path}
59 60 61 62 63
                 --batch_size 25
                 --batch_num 2
                 --acc_diff_threshold 0.1)
endfunction()

64 65

# set batch_size 10 for UT only (avoid OOM). For whole dataset, use batch_size 25 
W
Wojciech Uss 已提交
66
function(inference_quant2_int8_image_classification_test target quant_model_dir fp32_model_dir dataset_path)
67
    py_test(${target} SRCS "${CMAKE_CURRENT_SOURCE_DIR}/quant2_int8_image_classification_comparison.py"
68 69
            ENVS FLAGS_OMP_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
                 OMP_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
70
                 FLAGS_use_mkldnn=true
W
Wojciech Uss 已提交
71
            ARGS --quant_model ${quant_model_dir}
72 73
                 --fp32_model ${fp32_model_dir}
                 --infer_data ${dataset_path}
74
                 --batch_size 50
75
                 --batch_num 2
W
Wojciech Uss 已提交
76
                 --acc_diff_threshold 0.1)
77 78 79
endfunction()

# set batch_size 10 for UT only (avoid OOM). For whole dataset, use batch_size 20 
W
Wojciech Uss 已提交
80
function(inference_quant2_int8_nlp_test target quant_model_dir fp32_model_dir dataset_path labels_path ops_to_quantize)
81
    py_test(${target} SRCS "${CMAKE_CURRENT_SOURCE_DIR}/quant2_int8_nlp_comparison.py"
82 83 84
            ENVS FLAGS_OMP_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
                 OMP_NUM_THREADS=${CPU_NUM_THREADS_ON_CI}
                 FLAGS_use_mkldnn=true
W
Wojciech Uss 已提交
85
            ARGS --quant_model ${quant_model_dir}
86 87
		 --fp32_model ${fp32_model_dir}
                 --infer_data ${dataset_path}
88 89 90
		 --labels ${labels_path}
                 --batch_size 10
                 --batch_num 2
W
Wojciech Uss 已提交
91 92
                 --acc_diff_threshold 0.1
		 --ops_to_quantize ${ops_to_quantize})
93 94
endfunction()

95
function(inference_quant2_int8_lstm_model_test target fp32_model quant_model dataset_path)
96 97
    py_test(${target} SRCS "${CMAKE_CURRENT_SOURCE_DIR}/quant2_int8_lstm_model.py"
            ARGS --fp32_model ${fp32_model}
98
                 --quant_model ${quant_model}
99
                 --infer_data ${dataset_path}
100
                 --num_threads 1
101 102 103 104 105
                 --mkldnn_cache_capacity 100
                 --warmup_iter 100
                 --acc_diff_threshold 0.11)
endfunction()

W
Wangzheee 已提交
106
function(download_quant_data install_dir data_file check_sum)
107
    if (NOT EXISTS ${install_dir}/${data_file})
W
Wangzheee 已提交
108
           inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/int8 ${data_file} ${check_sum})
109 110 111
    endif()
endfunction()

W
Wangzheee 已提交
112
function(download_quant_model install_dir data_file check_sum)
113
    if (NOT EXISTS ${install_dir}/${data_file})
W
Wangzheee 已提交
114
           inference_download_and_uncompress(${install_dir} ${INFERENCE_URL}/int8/QAT_models ${data_file} ${check_sum})
115
    endif()
116 117
endfunction()

118
function(save_quant_ic_model_test target quant_model_dir int8_model_save_path)
119
    py_test(${target} SRCS ${CMAKE_CURRENT_SOURCE_DIR}/save_quant_model.py
W
Wojciech Uss 已提交
120
            ARGS --quant_model_path ${quant_model_dir}
121
	         --int8_model_save_path ${int8_model_save_path}
W
Wojciech Uss 已提交
122
		 --debug)
123 124
endfunction()

125
function(save_quant_nlp_model_test target quant_model_dir int8_model_save_path ops_to_quantize)
126
    py_test(${target} SRCS ${CMAKE_CURRENT_SOURCE_DIR}/save_quant_model.py
W
Wojciech Uss 已提交
127
            ARGS --quant_model_path ${quant_model_dir}
W
Wojciech Uss 已提交
128 129
	         --int8_model_save_path ${int8_model_save_path}
		 --ops_to_quantize ${ops_to_quantize})
130
endfunction()
131

132 133 134 135 136 137 138
function(convert_model2dot_test target model_path save_graph_dir save_graph_name)
    py_test(${target} SRCS ${CMAKE_CURRENT_SOURCE_DIR}/convert_model2dot.py
            ARGS --model_path ${model_path}
	         --save_graph_dir ${save_graph_dir}
	         --save_graph_name ${save_graph_name})
endfunction()

W
whs 已提交
139
if(WIN32)
140
	list(REMOVE_ITEM TEST_OPS test_light_nas)
141
	list(REMOVE_ITEM TEST_OPS test_post_training_quantization_mnist)
142
	list(REMOVE_ITEM TEST_OPS test_post_training_quantization_while)
143
	list(REMOVE_ITEM TEST_OPS test_post_training_quantization_mobilenetv1)
C
cc 已提交
144
	list(REMOVE_ITEM TEST_OPS test_post_training_quantization_resnet50)
145
	list(REMOVE_ITEM TEST_OPS test_post_training_quantization_lstm_model)
146
	list(REMOVE_ITEM TEST_OPS test_imperative_ptq)
C
cc 已提交
147 148
	list(REMOVE_ITEM TEST_OPS test_weight_quantization_mobilenetv1)
	list(REMOVE_ITEM TEST_OPS test_quantize_transpiler_v2)
C
cc 已提交
149
	list(REMOVE_ITEM TEST_OPS test_imperative_qat_amp)
W
whs 已提交
150 151
endif()

152 153
if(LINUX AND WITH_MKLDNN)

154 155 156
	#### Image classification dataset: ImageNet (small)
	# The dataset should already be downloaded for INT8v2 unit tests
	set(IMAGENET_DATA_PATH "${INFERENCE_DEMO_INSTALL_DIR}/imagenet/data.bin")
157

158 159 160 161
	#### INT8 image classification python api test
	# Models should be already downloaded for INT8v2 unit tests

	set(INT8_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/int8v2")
162

W
Wojciech Uss 已提交
163
	#### QUANT & INT8 comparison python api tests
164

W
Wojciech Uss 已提交
165
	set(QUANT_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/quant")
166

W
Wojciech Uss 已提交
167
	### Quant1 for image classification
168

W
Wojciech Uss 已提交
169 170 171
	# Quant ResNet50
	set(QUANT_RESNET50_MODEL_DIR "${QUANT_INSTALL_DIR}/ResNet50_quant")
	set(QUANT_RESNET50_MODEL_ARCHIVE "ResNet50_qat_model.tar.gz")
W
Wangzheee 已提交
172
	download_quant_model(${QUANT_RESNET50_MODEL_DIR} ${QUANT_RESNET50_MODEL_ARCHIVE} ff89b934ab961c3a4a844193ece2e8a7)
W
Wojciech Uss 已提交
173
	inference_quant_int8_image_classification_test(test_quant_int8_resnet50_mkldnn ${QUANT_RESNET50_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
174

W
Wojciech Uss 已提交
175 176 177
	# Quant ResNet101
	set(QUANT_RESNET101_MODEL_DIR "${QUANT_INSTALL_DIR}/ResNet101_quant")
	set(QUANT_RESNET101_MODEL_ARCHIVE "ResNet101_qat_model.tar.gz")
W
Wangzheee 已提交
178
	download_quant_model(${QUANT_RESNET101_MODEL_DIR} ${QUANT_RESNET101_MODEL_ARCHIVE} 95c6d01e3aeba31c13efb2ba8057d558)
W
Wojciech Uss 已提交
179
	# inference_quant_int8_image_classification_test(test_quant_int8_resnet101_mkldnn ${QUANT_RESNET101_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
180

W
Wojciech Uss 已提交
181 182 183
	# Quant GoogleNet
	set(QUANT_GOOGLENET_MODEL_DIR "${QUANT_INSTALL_DIR}/GoogleNet_quant")
	set(QUANT_GOOGLENET_MODEL_ARCHIVE "GoogleNet_qat_model.tar.gz")
W
Wangzheee 已提交
184
	download_quant_model(${QUANT_GOOGLENET_MODEL_DIR} ${QUANT_GOOGLENET_MODEL_ARCHIVE} 1d4a7383baa63e7d1c423e8db2b791d5)
W
Wojciech Uss 已提交
185
	inference_quant_int8_image_classification_test(test_quant_int8_googlenet_mkldnn ${QUANT_GOOGLENET_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
186

W
Wojciech Uss 已提交
187 188 189
	# Quant MobileNetV1
	set(QUANT_MOBILENETV1_MODEL_DIR "${QUANT_INSTALL_DIR}/MobileNetV1_quant")
	set(QUANT_MOBILENETV1_MODEL_ARCHIVE "MobileNetV1_qat_model.tar.gz")
W
Wangzheee 已提交
190
	download_quant_model(${QUANT_MOBILENETV1_MODEL_DIR} ${QUANT_MOBILENETV1_MODEL_ARCHIVE} 3b774d94a9fcbb604d09bdb731fc1162)
W
Wojciech Uss 已提交
191
	inference_quant_int8_image_classification_test(test_quant_int8_mobilenetv1_mkldnn ${QUANT_MOBILENETV1_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
192

W
Wojciech Uss 已提交
193 194 195
	# Quant MobileNetV2
	set(QUANT_MOBILENETV2_MODEL_DIR "${QUANT_INSTALL_DIR}/MobileNetV2_quant")
	set(QUANT_MOBILENETV2_MODEL_ARCHIVE "MobileNetV2_qat_model.tar.gz")
W
Wangzheee 已提交
196
	download_quant_model(${QUANT_MOBILENETV2_MODEL_DIR} ${QUANT_MOBILENETV2_MODEL_ARCHIVE} 758a99d9225d8b73e1a8765883f96cdd)
W
Wojciech Uss 已提交
197
	inference_quant_int8_image_classification_test(test_quant_int8_mobilenetv2_mkldnn ${QUANT_MOBILENETV2_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
198

W
Wojciech Uss 已提交
199 200 201
	# Quant VGG16
	set(QUANT_VGG16_MODEL_DIR "${QUANT_INSTALL_DIR}/VGG16_quant")
	set(QUANT_VGG16_MODEL_ARCHIVE "VGG16_qat_model.tar.gz")
W
Wangzheee 已提交
202
	download_quant_model(${QUANT_VGG16_MODEL_DIR} ${QUANT_VGG16_MODEL_ARCHIVE} c37e63ca82a102f47be266f8068b0b55)
W
Wojciech Uss 已提交
203
	# inference_quant_int8_image_classification_test(test_quant_int8_vgg16_mkldnn ${QUANT_VGG16_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
204

W
Wojciech Uss 已提交
205 206 207
	# Quant VGG19
	set(QUANT_VGG19_MODEL_DIR "${QUANT_INSTALL_DIR}/VGG19_quant")
	set(QUANT_VGG19_MODEL_ARCHIVE "VGG19_qat_model.tar.gz")
W
Wangzheee 已提交
208
	download_quant_model(${QUANT_VGG19_MODEL_DIR} ${QUANT_VGG19_MODEL_ARCHIVE} 62bcd4b6c3ca2af67e8251d1c96ea18f)
W
Wojciech Uss 已提交
209
	# inference_quant_int8_image_classification_test(test_quant_int8_vgg19_mkldnn ${QUANT_VGG19_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
210

W
Wojciech Uss 已提交
211
	### Quant2 for image classification
212

W
Wojciech Uss 已提交
213
	# Quant2 ResNet50 with input/output scales in `fake_quantize_moving_average_abs_max` operators,
214
	# with weight scales in `fake_dequantize_max_abs` operators
W
Wojciech Uss 已提交
215 216
        set(QUANT2_RESNET50_MODEL_DIR "${QUANT_INSTALL_DIR}/ResNet50_quant2")
	set(QUANT2_RESNET50_MODEL_ARCHIVE "ResNet50_qat_perf.tar.gz")
W
Wangzheee 已提交
217
	download_quant_model(${QUANT2_RESNET50_MODEL_DIR} ${QUANT2_RESNET50_MODEL_ARCHIVE} e87309457e8c462a579340607f064d66)
218
	set(FP32_RESNET50_MODEL_DIR "${INT8_INSTALL_DIR}/resnet50")
W
Wojciech Uss 已提交
219
	inference_quant2_int8_image_classification_test(test_quant2_int8_resnet50_mkldnn ${QUANT2_RESNET50_MODEL_DIR}/ResNet50_qat_perf/float ${FP32_RESNET50_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
220

W
Wojciech Uss 已提交
221
	# Quant2 ResNet50 with input/output scales in `fake_quantize_range_abs_max` operators and the `out_threshold` attributes,
222
	# with weight scales in `fake_dequantize_max_abs` operators
W
Wojciech Uss 已提交
223 224
	set(QUANT2_RESNET50_RANGE_MODEL_DIR "${QUANT_INSTALL_DIR}/ResNet50_quant2_range")
	set(QUANT2_RESNET50_RANGE_MODEL_ARCHIVE "ResNet50_qat_range.tar.gz")
W
Wangzheee 已提交
225
	download_quant_model(${QUANT2_RESNET50_RANGE_MODEL_DIR} ${QUANT2_RESNET50_RANGE_MODEL_ARCHIVE} 2fdc8a139f041c0d270abec826b2d304)
W
Wojciech Uss 已提交
226
	inference_quant2_int8_image_classification_test(test_quant2_int8_resnet50_range_mkldnn ${QUANT2_RESNET50_RANGE_MODEL_DIR}/ResNet50_qat_range ${FP32_RESNET50_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
227

W
Wojciech Uss 已提交
228
	# Quant2 ResNet50 with input/output scales in `fake_quantize_range_abs_max` operators and the `out_threshold` attributes,
229
	# with weight scales in `fake_channel_wise_dequantize_max_abs` operators
W
Wojciech Uss 已提交
230 231
	set(QUANT2_RESNET50_CHANNELWISE_MODEL_DIR "${QUANT_INSTALL_DIR}/ResNet50_quant2_channelwise")
	set(QUANT2_RESNET50_CHANNELWISE_MODEL_ARCHIVE "ResNet50_qat_channelwise.tar.gz")
W
Wangzheee 已提交
232
	download_quant_model(${QUANT2_RESNET50_CHANNELWISE_MODEL_DIR} ${QUANT2_RESNET50_CHANNELWISE_MODEL_ARCHIVE} 887a1b1b0e9a4efd10f263a43764db26)
W
Wojciech Uss 已提交
233
	inference_quant2_int8_image_classification_test(test_quant2_int8_resnet50_channelwise_mkldnn ${QUANT2_RESNET50_CHANNELWISE_MODEL_DIR}/ResNet50_qat_channelwise ${FP32_RESNET50_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
W
Wojciech Uss 已提交
234 235 236 237

	# Quant2 MobileNetV1
        set(QUANT2_MOBILENETV1_MODEL_DIR "${QUANT_INSTALL_DIR}/MobileNetV1_quant2")
	set(QUANT2_MOBILENETV1_MODEL_ARCHIVE "MobileNet_qat_perf.tar.gz")
W
Wangzheee 已提交
238
	download_quant_model(${QUANT2_MOBILENETV1_MODEL_DIR} ${QUANT2_MOBILENETV1_MODEL_ARCHIVE} 7f626e453db2d56fed6c2538621ffacf)
239
	set(FP32_MOBILENETV1_MODEL_DIR "${INT8_INSTALL_DIR}/mobilenetv1")
W
Wojciech Uss 已提交
240
	inference_quant2_int8_image_classification_test(test_quant2_int8_mobilenetv1_mkldnn ${QUANT2_MOBILENETV1_MODEL_DIR}/MobileNet_qat_perf/float ${FP32_MOBILENETV1_MODEL_DIR}/model ${IMAGENET_DATA_PATH})
241
	
W
Wojciech Uss 已提交
242
	### Quant2 for NLP
243 244 245 246 247

	set(NLP_DATA_ARCHIVE "Ernie_dataset.tar.gz")
	set(NLP_DATA_DIR "${INFERENCE_DEMO_INSTALL_DIR}/Ernie_dataset")
	set(NLP_DATA_PATH "${NLP_DATA_DIR}/Ernie_dataset/1.8w.bs1")
	set(NLP_LABLES_PATH "${NLP_DATA_DIR}/Ernie_dataset/label.xnli.dev")
W
Wangzheee 已提交
248
	download_quant_data(${NLP_DATA_DIR} ${NLP_DATA_ARCHIVE} e650ce0cbc1fadbed5cc2c01d4e734dc)
249

W
Wojciech Uss 已提交
250 251 252
	# Quant2 Ernie
	set(QUANT2_ERNIE_MODEL_ARCHIVE "ernie_qat.tar.gz")
	set(QUANT2_ERNIE_MODEL_DIR "${QUANT_INSTALL_DIR}/Ernie_quant2")
W
Wangzheee 已提交
253
	download_quant_model(${QUANT2_ERNIE_MODEL_DIR} ${QUANT2_ERNIE_MODEL_ARCHIVE} f7cdf4720755ecf66efbc8044e9922d9)
254
	set(FP32_ERNIE_MODEL_ARCHIVE "ernie_fp32_model.tar.gz")
W
Wojciech Uss 已提交
255
	set(FP32_ERNIE_MODEL_DIR "${QUANT_INSTALL_DIR}/Ernie_float")
W
Wangzheee 已提交
256
	download_quant_fp32_model(${FP32_ERNIE_MODEL_DIR} ${FP32_ERNIE_MODEL_ARCHIVE} 114f38804a3ef8c45e7259e68bbd838b)
Z
Zuza 已提交
257
	set(QUANT2_ERNIE_OPS_TO_QUANTIZE "fc,reshape2,transpose2,matmul,elementwise_add,slice")
258 259 260 261 262
	inference_quant2_int8_nlp_test(test_quant2_int8_ernie_mkldnn ${QUANT2_ERNIE_MODEL_DIR}/Ernie_qat/float ${FP32_ERNIE_MODEL_DIR}/ernie_fp32_model ${NLP_DATA_PATH} ${NLP_LABLES_PATH} ${QUANT2_ERNIE_OPS_TO_QUANTIZE})

	# Quant2 GRU
	set(QUANT2_GRU_MODEL_ARCHIVE "GRU_quant_acc.tar.gz")
	set(QUANT2_GRU_MODEL_DIR "${QUANT_INSTALL_DIR}/GRU_quant2")
W
Wangzheee 已提交
263
	download_quant_model(${QUANT2_GRU_MODEL_DIR} ${QUANT2_GRU_MODEL_ARCHIVE} cf207f8076dcfb8b74d8b6bdddf9090c)
264
	set(QUANT2_GRU_OPS_TO_QUANTIZE "multi_gru")
265

L
lidanqing 已提交
266 267 268 269 270 271
	# Quant2 LSTM
	set(QUANT2_LSTM_MODEL_ARCHIVE "lstm_quant.tar.gz")
	set(QUANT2_LSTM_MODEL_DIR "${QUANT_INSTALL_DIR}/lstm_quant_test")
	download_quant_model(${QUANT2_LSTM_MODEL_DIR} ${QUANT2_LSTM_MODEL_ARCHIVE} 40a693803b12ee9e251258f32559abcb)
	set(QUANT2_LSTM_OPS_TO_QUANTIZE "fusion_lstm")

W
Wojciech Uss 已提交
272
	### Save FP32 model or INT8 model from Quant model
273
        
W
Wojciech Uss 已提交
274
	set(QUANT2_INT8_RESNET50_SAVE_PATH "${QUANT_INSTALL_DIR}/ResNet50_quant2_int8")
275
	save_quant_ic_model_test(save_quant2_model_resnet50 ${QUANT2_RESNET50_MODEL_DIR}/ResNet50_qat_perf/float ${QUANT2_INT8_RESNET50_SAVE_PATH})
276

W
Wojciech Uss 已提交
277
	set(QUANT2_INT8_ERNIE_SAVE_PATH "${QUANT_INSTALL_DIR}/Ernie_quant2_int8")
278 279 280 281
	save_quant_nlp_model_test(save_quant2_model_ernie ${QUANT2_ERNIE_MODEL_DIR}/Ernie_qat/float ${QUANT2_INT8_ERNIE_SAVE_PATH} ${QUANT2_ERNIE_OPS_TO_QUANTIZE})

	set(QUANT2_INT8_GRU_SAVE_PATH "${QUANT_INSTALL_DIR}/GRU_quant2_int8")
	save_quant_nlp_model_test(save_quant2_model_gru ${QUANT2_GRU_MODEL_DIR}/GRU_quant_acc ${QUANT2_INT8_GRU_SAVE_PATH} ${QUANT2_GRU_OPS_TO_QUANTIZE})
282

L
lidanqing 已提交
283 284 285
	set(QUANT2_INT8_LSTM_SAVE_PATH "${QUANT_INSTALL_DIR}/lstm_quant2_int8")
	save_quant_nlp_model_test(save_quant2_model_lstm ${QUANT2_LSTM_MODEL_DIR}/lstm_quant ${QUANT2_INT8_LSTM_SAVE_PATH} ${QUANT2_LSTM_OPS_TO_QUANTIZE})

W
Wojciech Uss 已提交
286 287 288
	# Convert Quant2 model to dot and pdf files 
	set(QUANT2_INT8_ERNIE_DOT_SAVE_PATH "${QUANT_INSTALL_DIR}/Ernie_quant2_int8_dot_file")
	convert_model2dot_test(convert_model2dot_ernie ${QUANT2_ERNIE_MODEL_DIR}/Ernie_qat/float ${QUANT2_INT8_ERNIE_DOT_SAVE_PATH} "Ernie_quant2_int8")
289

290 291 292 293 294 295 296
	### PTQ INT8

	# PTQ int8 lstm model
	set(LSTM_DATA_ARCHIVE "unittest_model_data/quant_lstm_input_data.tar.gz")
	download_quant_data(${QUANT2_INT8_LSTM_SAVE_PATH} ${LSTM_DATA_ARCHIVE} add84c754e9b792fea1fbd728d134ab7)
	set(QUANT2_FP32_LSTM_MODEL_ARCHIVE "lstm_fp32_model.tar.gz")
	download_lstm_model(${QUANT2_INT8_LSTM_SAVE_PATH} ${QUANT2_FP32_LSTM_MODEL_ARCHIVE} eecd9f44d69a84acc1cf2235c4b8b743)
297
	inference_quant2_int8_lstm_model_test(test_quant2_int8_lstm_mkldnn ${QUANT2_INT8_LSTM_SAVE_PATH}/lstm_fp32_model ${QUANT2_LSTM_MODEL_DIR}/lstm_quant ${QUANT2_INT8_LSTM_SAVE_PATH}/quant_lstm_input_data)
298

299 300
endif()

W
Wojciech Uss 已提交
301
# Since the tests for Quant & INT8 comparison support only testing on Linux 
302
# with MKL-DNN, we remove it here to not test it on other systems.
303 304
list(REMOVE_ITEM TEST_OPS
	test_mkldnn_int8_quantization_strategy
W
Wojciech Uss 已提交
305 306
	quant_int8_image_classification_comparison
	quant_int8_nlp_comparison)
307

I
iducn 已提交
308 309 310
#TODO(wanghaoshuang): Fix this unitest failed on GCC8.
LIST(REMOVE_ITEM TEST_OPS test_auto_pruning)
LIST(REMOVE_ITEM TEST_OPS test_filter_pruning)
311
	
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
# fix
if(WIN32)
    SET(SINGLE_CARD_TEST_OPS
        test_user_defined_quantization
        test_quantization_scale_pass
        test_quantization_pass
        test_moving_average_abs_max_scale_op
        test_imperative_qat_channelwise
        test_imperative_qat
        test_imperative_out_scale
        test_graph)
    LIST(REMOVE_ITEM TEST_OPS ${SINGLE_CARD_TEST_OPS})
    foreach(src ${SINGLE_CARD_TEST_OPS})
        py_test(${src} SRCS ${src}.py ENVS CUDA_VISIBLE_DEVICES=0)
    endforeach()
endif()


W
WangZhen 已提交
330 331 332
foreach(src ${TEST_OPS})
    py_test(${src} SRCS ${src}.py)
endforeach()
Y
YUNSHEN XIE 已提交
333 334

# setting timeout value for old unittests
335
if(NOT WIN32)
336
    set_tests_properties(test_post_training_quantization_lstm_model PROPERTIES TIMEOUT 120)
337 338
    set_tests_properties(test_post_training_quantization_mobilenetv1 PROPERTIES TIMEOUT 600 LABELS "RUN_TYPE=NIGHTLY")
    set_tests_properties(test_post_training_quantization_resnet50 PROPERTIES TIMEOUT 600 LABELS "RUN_TYPE=NIGHTLY")
Y
YUNSHEN XIE 已提交
339
    set_tests_properties(test_post_training_quantization_mnist PROPERTIES TIMEOUT 120)
340
    set_tests_properties(test_post_training_quantization_while PROPERTIES TIMEOUT 120)
341
    set_tests_properties(test_imperative_ptq PROPERTIES TIMEOUT 120)
Y
YUNSHEN XIE 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    set_tests_properties(test_weight_quantization_mobilenetv1 PROPERTIES TIMEOUT 120)
endif()

set_tests_properties(test_graph PROPERTIES TIMEOUT 120)
set_tests_properties(test_quantization_pass PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_qat_channelwise PROPERTIES TIMEOUT 120)
set_tests_properties(test_user_defined_quantization PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_qat PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_out_scale PROPERTIES TIMEOUT 120)
if(LINUX AND WITH_MKLDNN)
    set_tests_properties(test_quant2_int8_mobilenetv1_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(convert_model2dot_ernie PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant2_int8_resnet50_channelwise_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant_int8_mobilenetv2_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant2_int8_resnet50_range_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(save_quant2_model_resnet50 PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant_int8_resnet50_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant_int8_mobilenetv1_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant2_int8_ernie_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant_int8_googlenet_mkldnn PROPERTIES TIMEOUT 120)
    set_tests_properties(test_quant2_int8_resnet50_mkldnn PROPERTIES TIMEOUT 120)
363
	set_tests_properties(test_quant2_int8_lstm_mkldnn PROPERTIES TIMEOUT 120)
Y
YUNSHEN XIE 已提交
364
endif()