Skip to content

Commit

Permalink
Remove tests with save_quant_model.py (#50307)
Browse files Browse the repository at this point in the history
* got rid of save_quant_model

* review changes
  • Loading branch information
paulinagacek authored Feb 23, 2023
1 parent 7f87d75 commit db170b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 257 deletions.
53 changes: 1 addition & 52 deletions python/paddle/static/quantization/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,6 @@ function(download_quant_model install_dir data_file check_sum)
endif()
endfunction()

function(save_quant_ic_model_test target quant_model_dir int8_model_save_path)
py_test(
${target}
SRCS ${CMAKE_CURRENT_SOURCE_DIR}/save_quant_model.py
ARGS
--quant_model_path
${quant_model_dir}
--int8_model_save_path
${int8_model_save_path}
--debug)
endfunction()

function(save_quant_nlp_model_test target quant_model_dir int8_model_save_path
ops_to_quantize)
py_test(
${target}
SRCS ${CMAKE_CURRENT_SOURCE_DIR}/save_quant_model.py
ARGS
--quant_model_path
${quant_model_dir}
--int8_model_save_path
${int8_model_save_path}
--ops_to_quantize
${ops_to_quantize})
endfunction()

function(convert_model2dot_test target model_path save_graph_dir
save_graph_name)
py_test(
Expand Down Expand Up @@ -438,31 +412,6 @@ if(LINUX AND WITH_MKLDNN)
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")

### Save FP32 model or INT8 model from Quant model

set(QUANT2_INT8_RESNET50_SAVE_PATH
"${QUANT_INSTALL_DIR}/ResNet50_quant2_int8")
save_quant_ic_model_test(
save_quant2_model_resnet50
${QUANT2_RESNET50_MODEL_DIR}/ResNet50_qat_perf/float
${QUANT2_INT8_RESNET50_SAVE_PATH})

set(QUANT2_INT8_ERNIE_SAVE_PATH "${QUANT_INSTALL_DIR}/Ernie_quant2_int8")
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})

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})

# Convert Quant2 model to dot and pdf files
set(QUANT2_INT8_ERNIE_DOT_SAVE_PATH
Expand All @@ -474,6 +423,7 @@ if(LINUX AND WITH_MKLDNN)
### PTQ INT8

# PTQ int8 lstm model
set(QUANT2_INT8_LSTM_SAVE_PATH "${QUANT_INSTALL_DIR}/lstm_quant2_int8")
set(LSTM_DATA_FILE "quant_lstm_input_data.tar.gz")
set(LSTM_URL "${INFERENCE_URL}/int8/unittest_model_data")
download_data(${QUANT2_INT8_LSTM_SAVE_PATH} ${LSTM_URL} ${LSTM_DATA_FILE}
Expand Down Expand Up @@ -561,7 +511,6 @@ if(LINUX AND WITH_MKLDNN)
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)
Expand Down
28 changes: 12 additions & 16 deletions python/paddle/static/quantization/tests/quant2_int8_lstm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import unittest

import numpy as np
from save_quant_model import transform_and_save_int8_model

import paddle
from paddle.framework import core
Expand Down Expand Up @@ -107,7 +106,7 @@ def set_config(
mkldnn_cache_capacity,
warmup_data=None,
use_analysis=False,
enable_ptq=False,
mode="fp32",
):
config = core.AnalysisConfig(model_path)
config.set_cpu_math_library_num_threads(num_threads)
Expand All @@ -118,12 +117,15 @@ def set_config(
config.enable_mkldnn()
config.disable_mkldnn_fc_passes() # fc passes caused dnnl error
config.set_mkldnn_cache_capacity(mkldnn_cache_capacity)
if enable_ptq:
if mode == "ptq":
# This pass to work properly, must be added before fc_fuse_pass
config.pass_builder().insert_pass(5, "fc_lstm_fuse_pass")
config.enable_quantizer()
config.quantizer_config().set_quant_data(warmup_data)
config.quantizer_config().set_quant_batch_size(1)
elif mode == "qat":
config.enable_mkldnn_int8()

return config

def run_program(
Expand All @@ -134,7 +136,7 @@ def run_program(
mkldnn_cache_capacity,
warmup_iter,
use_analysis=False,
enable_ptq=False,
mode="fp32",
):
place = paddle.CPUPlace()
warmup_data, inputs = self.get_warmup_tensor(data_path, place)
Expand All @@ -145,7 +147,7 @@ def run_program(
mkldnn_cache_capacity,
warmup_data,
use_analysis,
enable_ptq,
mode,
)

predictor = core.create_paddle_predictor(config)
Expand Down Expand Up @@ -228,7 +230,7 @@ def test_lstm_model(self):
mkldnn_cache_capacity,
warmup_iter,
False,
False,
mode="fp32",
)

(int8_hx_acc, int8_ctc_acc, int8_fps) = self.run_program(
Expand All @@ -238,23 +240,17 @@ def test_lstm_model(self):
mkldnn_cache_capacity,
warmup_iter,
True,
True,
)

quant_model_save_path = quant_model + "_int8"
# transform model to quant2
transform_and_save_int8_model(
quant_model, quant_model_save_path, "fusion_lstm,concat"
mode="ptq",
)

(quant_hx_acc, quant_ctc_acc, quant_fps) = self.run_program(
quant_model_save_path,
quant_model + "_int8",
infer_data,
num_threads,
mkldnn_cache_capacity,
warmup_iter,
True,
False,
mode="qat",
)

print(
Expand All @@ -270,7 +266,7 @@ def test_lstm_model(self):
)

print(
"QUANT2_INT8: fps {0}, hx_acc {1}, ctc_acc {2}".format(
"QAT: fps {0}, hx_acc {1}, ctc_acc {2}".format(
quant_fps, quant_hx_acc, quant_ctc_acc
)
)
Expand Down
189 changes: 0 additions & 189 deletions python/paddle/static/quantization/tests/save_quant_model.py

This file was deleted.

0 comments on commit db170b2

Please sign in to comment.