-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
C-API quantization core 2 #16396
C-API quantization core 2 #16396
Conversation
dc75415
to
d8a7969
Compare
@luotao1 , I have restarted the failed build, is it possible to spur the CI to start the build faster? |
You can restart the build, but this PR doesn't solve #15987 (comment) |
bf8f5c3
to
79d8cc3
Compare
@luotao1 , #15987 (comment) is also done |
class Quantizer; | ||
Quantizer *quantizer_{nullptr}; | ||
|
||
friend class QuantizerTest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove friend class QuantizerTest
in analysis_predictor.h
. Header file doesn't need to contain a test class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Quantizer
class is a private nested class, and we need the friendship declaration to create an instance of Quantizer
in the QuantizerTest
test (analysis_predictor_tester.cc
).
We could remove the declaration by moving the class Quantizer;
forward declaration to the public
section, but we would like to keep the Quantizer
class hidden as an implementation detail and not to expose it to the outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Superjomn How do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's OK I think, but need to wrap by #ifdef PADDLE_WITH_TESTING
? @luotao1
But the Quantize method should be general, or it should be named to MkldnnQuantize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef PADDLE_WITH_TESTING, be named to MkldnnQuantize
I agree with it @wojtuss @Superjomn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luotao1 , @Superjomn , to avoid too many updates of the PR we could agree to add the Mkldnn
prefix to all "quantize"-related methods, classes, and file names in this PR. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all "quantize"-related methods, classes, and file names
Do you mean MkldnnQuantizerTest, EnableMkldnnQuantizer, mkldnn_quantizer.cc,mkldnn_ quantizer_config.cc, use_mkldnn_quantizer_, mkldnn_quantizer_config_, MkldnnQuantizer, mkldnn_quantizer_enabled,etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luotao1, done.
I left renaming of cpu_quantize_*
passes to another PR.
Do you think it is urgent to have the things in passes renamed asap?
d596d48
to
983017b
Compare
test=develop Co-authored-by: Sylwester Fraczek <sylwester.fraczek@intel.com>
test=develop
test=develop
983017b
to
a07b3fd
Compare
test=develop
50d565e
to
9a920ae
Compare
@@ -143,6 +148,25 @@ void AnalysisConfig::EnableMKLDNN() { | |||
Update(); | |||
} | |||
|
|||
void AnalysisConfig::EnableQuantizer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnableMkldnnQuantizer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -29,13 +29,19 @@ endif() | |||
|
|||
add_subdirectory(details) | |||
|
|||
cc_library(analysis_config SRCS analysis_config.cc DEPS lod_tensor paddle_pass_builder) | |||
if(WITH_MKLDNN) | |||
set(quantizer_src quantizer.cc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkldnn_quantizer.cc?
mkldnn_ quantizer_config.cc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -107,6 +107,11 @@ AnalysisConfig::AnalysisConfig(const AnalysisConfig &other) { | |||
// MKLDNN related. | |||
CP_MEMBER(use_mkldnn_); | |||
CP_MEMBER(mkldnn_enabled_op_types_); | |||
// Quantization related. | |||
CP_MEMBER(use_quantizer_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_mkldnn_quantizer_
mkldnn_quantizer_config_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -141,6 +144,16 @@ class AnalysisPredictor : public PaddlePredictor { | |||
std::vector<framework::OpDesc *> fetches_; | |||
std::map<size_t, std::string> idx2fetches_; | |||
|
|||
#if PADDLE_WITH_MKLDNN | |||
// Helper class to perform quantization | |||
class Quantizer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MkldnnQuantizer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
class Quantizer; | ||
Quantizer *quantizer_{nullptr}; | ||
|
||
friend class QuantizerTest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MkldnnQuantizerTest
@@ -174,6 +177,18 @@ struct AnalysisConfig { | |||
mkldnn_enabled_op_types_ = op_list; | |||
} | |||
|
|||
/** Turn on quantization. | |||
*/ | |||
void EnableQuantizer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnableMkldnnQuantizer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
/** A boolean state telling whether the quantization is enabled. | ||
*/ | ||
bool quantizer_enabled() const { return use_quantizer_; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkldnn_quantizer_enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
… sfraczek/quantization-core3
@luotao1 , the build
It looks like a typo in the code, but there is nothing like that or I can't find it. Rebuild didn't help. |
… sfraczek/quantization-core3
I have a similar error with CI.
result
|
Some observations:
|
|
@@ -148,6 +153,28 @@ void AnalysisConfig::EnableMKLDNN() { | |||
Update(); | |||
} | |||
|
|||
void AnalysisConfig::EnableMkldnnQuantizer() { | |||
#ifdef PADDLE_WITH_MKLDNN | |||
if (!mkldnn_quantizer_config_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if delete line158, then we don't need CP_MEMBER(mkldnn_quantizer_config_)
? Could we delete line158?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luotao1 , copying the shared_ptr
worked and it should be fine, even when it holds nullptr
. I would rather suspect the #ifdef PADDLE_WITH_MKLDNN
in the paddle_analysis_config.h
is the culprit. I am investigating that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luotao1 , I confirm that removing #ifdef PADDLE_WITH_MKLDNN
solved the problem. I took care of it in another way. Please take a look at this patch if it is OK for you: wojtuss@49c5a2b
I am verifying it more thoroughly.
[edit]
It works. I have updated the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I verify on my local machine.
test=develop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this PR passes all the CI in night, please squash and merge it yourself.
@luotao1 , thank you very much for your help! 😄 👍 |
This is a cleaned version of PR #15987.
It contains the core of the second version of INT8 quantization, C-API based only.
test=develop
Co-authored-by: Sylwester Fraczek sylwester.fraczek@intel.com