Skip to content
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
7 changes: 4 additions & 3 deletions python/paddle/quantization/imperative/qat.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ def quantize(self, model):
return model

def save_quantized_model(self, layer, path, input_spec=None, **config):
self._quantize_outputs.save_quantized_model(
layer, path, input_spec, **config
)
with paddle.pir_utils.OldIrGuard():
self._quantize_outputs.save_quantized_model(
layer, path, input_spec, **config
)


class ImperativeQuantizeInputs:
Expand Down
28 changes: 9 additions & 19 deletions test/deprecated/quantization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ endfunction()

if(WIN32)
list(REMOVE_ITEM TEST_OPS test_light_nas)
list(REMOVE_ITEM TEST_OPS test_post_training_quantization_while)
list(REMOVE_ITEM TEST_OPS test_post_training_quantization_while_deprecated)
list(REMOVE_ITEM TEST_OPS test_weight_quantization_mobilenetv1)
list(REMOVE_ITEM TEST_OPS test_imperative_qat_amp)
list(REMOVE_ITEM TEST_OPS test_weight_only_linear)
list(REMOVE_ITEM TEST_OPS test_llm_int8_linear)
list(REMOVE_ITEM TEST_OPS test_quant_aware_deprecated)
list(REMOVE_ITEM TEST_OPS test_quant_post_quant_aware)
list(REMOVE_ITEM TEST_OPS test_quant_aware_user_defined)
list(REMOVE_ITEM TEST_OPS test_quant_amp)
list(REMOVE_ITEM TEST_OPS test_quant_amp_deprecated)
list(REMOVE_ITEM TEST_OPS test_apply_per_channel_scale)

endif()
Expand Down Expand Up @@ -237,13 +237,8 @@ list(REMOVE_ITEM TEST_OPS test_filter_pruning)
if(WIN32)
set(SINGLE_CARD_TEST_OPS
test_user_defined_quantization_deprecated
test_quantization_scale_pass_deprecated
test_quantization_pass_deprecated
test_moving_average_abs_max_scale_op_deprecated
test_imperative_qat_channelwise
test_imperative_qat
test_imperative_out_scale
test_graph_deprecated)
test_quantization_scale_pass_deprecated test_quantization_pass_deprecated
test_moving_average_abs_max_scale_op_deprecated test_graph_deprecated)
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)
Expand All @@ -256,29 +251,24 @@ endforeach()

# setting timeout value for old unittests
if(NOT WIN32)
set_tests_properties(test_post_training_quantization_while PROPERTIES TIMEOUT
120)
set_tests_properties(test_post_training_quantization_while_deprecated
PROPERTIES TIMEOUT 120)
set_tests_properties(test_weight_quantization_mobilenetv1 PROPERTIES TIMEOUT
120)
set_tests_properties(test_quant_aware_deprecated PROPERTIES TIMEOUT 200)
set_tests_properties(test_quant_post_quant_aware PROPERTIES TIMEOUT 200)
set_tests_properties(test_quant_aware_user_defined PROPERTIES TIMEOUT 200)
set_tests_properties(test_quant_amp PROPERTIES TIMEOUT 200)
set_tests_properties(test_quant_amp_deprecated PROPERTIES TIMEOUT 200)
endif()

set_tests_properties(test_graph_deprecated PROPERTIES TIMEOUT 120)
set_tests_properties(test_quantization_pass_deprecated PROPERTIES TIMEOUT 120)
set_tests_properties(test_imperative_qat_channelwise PROPERTIES TIMEOUT 200)
set_tests_properties(test_user_defined_quantization_deprecated
PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_qat PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_qat_fuse PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_out_scale PROPERTIES TIMEOUT 200)

if(APPLE)
set_tests_properties(test_post_training_quantization_while PROPERTIES TIMEOUT
300)
set_tests_properties(test_imperative_skip_op PROPERTIES TIMEOUT 300)
set_tests_properties(test_post_training_quantization_while_deprecated
PROPERTIES TIMEOUT 300)
endif()

set_tests_properties(test_quantization_scale_pass_deprecated PROPERTIES TIMEOUT
Expand Down
11 changes: 8 additions & 3 deletions test/quantization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ list(REMOVE_ITEM TEST_OPS test_filter_pruning)
if(WIN32)
set(SINGLE_CARD_TEST_OPS
test_imperative_qat_channelwise test_imperative_qat
test_imperative_qat_lsq test_imperative_qat_matmul
test_imperative_out_scale)
test_imperative_qat_fuse test_imperative_qat_lsq
test_imperative_qat_matmul test_imperative_out_scale)
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)
Expand Down Expand Up @@ -493,7 +493,11 @@ endif()
set_tests_properties(test_imperative_qat_user_defined PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_qat_lsq PROPERTIES TIMEOUT 300)
set_tests_properties(test_imperative_qat_matmul PROPERTIES TIMEOUT 300)

set_tests_properties(test_imperative_qat PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_qat_fuse PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_qat_channelwise PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_out_scale PROPERTIES TIMEOUT 200)
set_tests_properties(test_imperative_skip_op PROPERTIES TIMEOUT 300)
if(LINUX AND WITH_ONEDNN)
set_tests_properties(test_quant2_int8_mobilenetv1_mkldnn PROPERTIES TIMEOUT
120)
Expand All @@ -517,4 +521,5 @@ if(APPLE)
set_tests_properties(test_post_training_quantization_mnist PROPERTIES TIMEOUT
300)
set_tests_properties(test_imperative_ptq PROPERTIES TIMEOUT 300)
set_tests_properties(test_imperative_skip_op PROPERTIES TIMEOUT 300)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,22 @@ def test_qat(self):
else:
place = core.CPUPlace()
exe = paddle.static.Executor(place)
[
inference_program,
feed_target_names,
fetch_targets,
] = paddle.static.load_inference_model(
tmpdir,
executor=exe,
model_filename="lenet" + INFER_MODEL_SUFFIX,
params_filename="lenet" + INFER_PARAMS_SUFFIX,
)
(quant_out,) = exe.run(
inference_program,
feed={feed_target_names[0]: test_data},
fetch_list=fetch_targets,
)
with paddle.pir_utils.OldIrGuard():
[
inference_program,
feed_target_names,
fetch_targets,
] = paddle.static.load_inference_model(
tmpdir,
executor=exe,
model_filename="lenet" + INFER_MODEL_SUFFIX,
params_filename="lenet" + INFER_PARAMS_SUFFIX,
)
(quant_out,) = exe.run(
inference_program,
feed={feed_target_names[0]: test_data},
fetch_list=fetch_targets,
)
paddle.disable_static()
quant_out = paddle.to_tensor(quant_out)
quant_acc = paddle.metric.accuracy(quant_out, label).numpy()
Expand Down
5 changes: 4 additions & 1 deletion test/quantization/test_imperative_qat_amp.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def test_ptq(self):
input_spec = [
paddle.static.InputSpec(shape=[None, 1, 28, 28], dtype='float32')
]
paddle.jit.save(layer=model, path=self.save_path, input_spec=input_spec)
with paddle.pir_utils.OldIrGuard():
paddle.jit.save(
layer=model, path=self.save_path, input_spec=input_spec
)
print(f'Quantized model saved in {{{self.save_path}}}')

end_time = time.time()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ def test_out_scale_acc(self):
else:
place = core.CPUPlace()
exe = paddle.static.Executor(place)

[
inference_program,
feed_target_names,
fetch_targets,
] = paddle.static.load_inference_model(
save_dir,
executor=exe,
model_filename="lenet" + INFER_MODEL_SUFFIX,
params_filename="lenet" + INFER_PARAMS_SUFFIX,
)
with paddle.pir_utils.OldIrGuard():
[
inference_program,
feed_target_names,
fetch_targets,
] = paddle.static.load_inference_model(
save_dir,
executor=exe,
model_filename="lenet" + INFER_MODEL_SUFFIX,
params_filename="lenet" + INFER_PARAMS_SUFFIX,
)
model_ops = inference_program.global_block().ops

conv2d_count, matmul_count = 0, 0
Expand Down