Skip to content

Conversation

@bingyanghuang
Copy link
Contributor

@bingyanghuang bingyanghuang commented Jun 4, 2019

This PR is to convert QuantizationFreezePass generated IrGraph to MKL-DNN support INT8
runnable IrGraph.
Following transformations have been done in this pass:

    1. Convert int8 range weights with float type, (which generated by the QuantizationFreezePass), to fp32 range weights with float dtype by the corresponding scales.
    2. Create the new conv2d op with the converted weights and link its output to fake_dequantize_abs_max output and set conv2d's attribute "force_fp32_output" as true
    3. Transform fake_quantize_xx to quantize op
    4. Remove fake_dequantize_abs_max op
Unit test is testing based on the Graph already applied QuantizationTransformPass and QuantizationFreezePass, it will check if:
    1. conv2d's output is rightly linked to the fake_dequantize op's output
    2. conv2d's weights has been converted to fp32 range, they are not integer any more
    3. check the graph locally to make sure that op's type have been transformed as we expected.
The latest accuracy of full ImageNet validation set on Cascade Lake (new generation Xeon) is as below:

image

@ghost ghost added this to the v1.5 for Intel milestone Jun 4, 2019
@ghost ghost added Intel int8 labels Jun 4, 2019
@luotao1 luotao1 requested a review from wzzju June 4, 2019 09:14
Copy link

@sfraczek sfraczek left a comment

Choose a reason for hiding this comment

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

We should have checking somehwere if mkldnn is enabled (i.e. FLAGS_use_mkldnn==1). Currently this transformation happens even if FLAGS_use_mkldnn=false when I run test written by @wojtuss #17814.

(This transformation sets attribute use_mkldnn=true for some operators which causes execution of mkldnn operators)

@sfraczek sfraczek self-requested a review June 6, 2019 06:28
sfraczek
sfraczek previously approved these changes Jun 6, 2019
Copy link

@sfraczek sfraczek left a comment

Choose a reason for hiding this comment

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

LGTM. the control whether to run this or not based on use_mkldnn can be added somewhere else

@bingyanghuang
Copy link
Contributor Author

@luotao1 @wzzju This PR has been reviewed inside intel. And has been passed CI once. Could you help review it?

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

Review is not finished.

from paddle.fluid import core

os.environ["CUDA_VISIBLE_DEVICES"] = "0"
os.environ["CPU_NUM"] = "1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use these two flags?

Copy link
Contributor Author

@bingyanghuang bingyanghuang Jun 6, 2019

Choose a reason for hiding this comment

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

In this test, we need to train a model for several iterations to get the weights value. And then converted to int8 and check if it is converted rightly. When we train this model, we need to set "CPU_NUM". This train model idea is following below example:


class TransformForMkldnnPass(object):
def __init__(self, scope=None, place=None):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments are not for __init__ function, they are for class TransformForMkldnnPass. Thus, move them after line 23?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM! @wzzju If you have any suggestions, please feel free to comment it.

@luotao1 luotao1 merged commit 90ebce9 into PaddlePaddle:develop Jun 10, 2019
@bingyanghuang bingyanghuang deleted the int8/mkldnn_quantization_pass branch October 15, 2019 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants