-
Couldn't load subscription status.
- Fork 5.9k
add unused input vars check for OpWithKernel, test=develop #21169
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
Conversation
740b587 to
e9b1db9
Compare
ebcc8a7 to
26d968e
Compare
936ea7f to
6552c8f
Compare
6552c8f to
afc8da5
Compare
c8fbf26 to
5b1047d
Compare
paddle/scripts/paddle_build.sh
Outdated
| fi | ||
|
|
||
| # TODO: jiabin need to refine this part when these tests fixed on mac | ||
| # NOTE(cql): enable unused_var_check for MAC CI |
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.
438行可以去掉了吧。439行请写具体一点,cql用完整的github名字,不然无法对应。
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.
好的
50719e6 to
36487c8
Compare
36487c8 to
e97a64d
Compare
019b5bb to
5d6171c
Compare
5d6171c to
a180079
Compare
| } | ||
|
|
||
| const Variable* ExecutionContext::InputVar(const std::string& name) const { | ||
| LogVarUsageIfUnusedVarCheckEnabled(name); |
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.
Call this function with if (FLAGS_enable_unused_var_check)?
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.
Thanks. To reduce code duplication, I will put the if statement inside LogVarUsageIfUnusedVarCheckEnabled.
| template <> | ||
| const std::vector<const Tensor*> ExecutionContext::MultiInput<Tensor>( | ||
| const std::string& name) const { | ||
| LogVarUsageIfUnusedVarCheckEnabled(name); |
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.
Call this function with if (FLAGS_enable_unused_var_check)?
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.
Thanks. To reduce code duplication, I will put the if statement inside LogVarUsageIfUnusedVarCheckEnabled.
|
|
||
| const std::vector<const Variable*> MultiInputVar( | ||
| const std::string& name) const { | ||
| LogVarUsageIfUnusedVarCheckEnabled(name); |
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.
Same above.
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, thanks.
|
|
||
| template <typename T> | ||
| const std::vector<const T*> MultiInput(const std::string& name) const { | ||
| LogVarUsageIfUnusedVarCheckEnabled(name); |
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.
Same above.
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, thanks.
paddle/fluid/framework/operator.h
Outdated
|
|
||
| //! Get actual name vector for this input. | ||
| const std::vector<std::string>& Inputs(const std::string& name) const { | ||
| LogVarUsageIfUnusedVarCheckEnabled(name); |
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.
Same above.
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, thanks.
| } | ||
| err_msg += | ||
| "please make sure it(them) is(are) needed. If not, remove it(them) " | ||
| "from inputs; if yes, register NoNeedBufferVars or add the operator to " |
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.
register NoNeedBufferVars or remove them in the GradOpMaker or add the operator to white list in unused_var_check.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.
Discussed offline. I use if to discussed failure of unused_var_check on two case,
- If the
input varis not need in computation, the only fix suggestion is "remove them in the inputs." - If the
input varis really need in computation but failed on check (due to some reasons, like different kernels, conditional usage, or only needing dims), the fix suggestion is "register NoNeedBufferVars or add the operator to white list in unused_var_check.cc".
| "please make sure it(them) is(are) needed. If not, remove it(them) " | ||
| "from inputs; if yes, register NoNeedBufferVars or add the operator to " | ||
| "white list in unused_var_check.cc."; | ||
| // VLOG(1) << err_msg; |
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.
Remove unused comments.
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, thanks.
| #include "paddle/fluid/framework/operator.h" | ||
|
|
||
| DECLARE_bool(enable_unused_var_check); | ||
| DECLARE_bool(use_mkldnn); |
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.
Not important: DECLARE_xxx here is not necessary in header file. You can move them to .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.
I remove DECLARE_bool(use_mkldnn) since it is not used, and keep DECLARE_bool(enable_unused_var_check) because some .cc file will include this header file and use the FLAGS.
| DECLARE_INPLACE_OP_INFERER(FlattenGradInplaceinToOut, | ||
| {framework::GradVarName("Out"), | ||
| framework::GradVarName("X")}); | ||
| DECLARE_NO_NEED_BUFFER_VARS_INFERENCE(FlattenGradNoNeedBufferVarsInference, |
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.
Why no need Out? Maybe it is X that is not needed?
| {framework::GradVarName("Out"), | ||
| framework::GradVarName("X")}); | ||
|
|
||
| DECLARE_NO_NEED_BUFFER_VARS_INFERENCE(SqueezeGradNoNeedBufferVarsInference, |
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.
Same above.
tools/check_api_approvals.sh
Outdated
| echo_line="You must have one RD (gongweibao or seiriosPlus) approval for the paddle/fluid/operators/distributed/send_recv.proto.in, which manages the environment variables.\n" | ||
| check_approval 1 10721757 5442383 | ||
| elif [ "${API_FILE}" == "paddle/fluid/framework/unused_var_check.cc" ];then | ||
| echo_line="You must have one RD (zhiqiu (Recommend) , sneaxiy or luotao1) approval for the paddle/fluid/framework/unused_var_check.cc, which manages the white list of operators that have unused input variables.\n" |
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.
You should have a wiki to tell developers what's the problem, and how to fix this problem, otherwise, they don't understand it, and will directly add to the write list.
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.
LGTM
25347ae to
4ead050
Compare
4ead050 to
1d9bb16
Compare
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.
LGTM with 2 things to do in the next PR:
-
Remove
InitThreadLocalUsedVarNameSetinunused_var_check.hsince it is not used and not defined. -
Add custom grad op maker for
squeezeandflattento removeOutdependency.
253cc34 to
cfc3a6e
Compare
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.
Excellent!
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.
LGTM
…dle#21169) * add unused input vars check for OpWithKernel, test=develop * remove unused vars in some ops, test=develop * fix batch_norm, test=develop * add white list, test=develop * add CI check for white list, test=develop * :ove white list to c++, test=develop * solve failure of CI, test=develop * add unittest for unused_var_check, test=develop * refine code, enable check in operator_test, test=develop * skip mkldnn, test=develop * extend white list, test=develop * refine condition of mkldnn, test=develop * fix paddle_build, test=develop * follow comments, test=develop * fix GetExpectedKernelType * add wiki ref to err_msg, test=develop * follow comment, test=develop
…dle#21169) * add unused input vars check for OpWithKernel, test=develop * remove unused vars in some ops, test=develop * fix batch_norm, test=develop * add white list, test=develop * add CI check for white list, test=develop * :ove white list to c++, test=develop * solve failure of CI, test=develop * add unittest for unused_var_check, test=develop * refine code, enable check in operator_test, test=develop * skip mkldnn, test=develop * extend white list, test=develop * refine condition of mkldnn, test=develop * fix paddle_build, test=develop * follow comments, test=develop * fix GetExpectedKernelType * add wiki ref to err_msg, test=develop * follow comment, test=develop
In Paddle, there are several operators that registered some variables as inputs while never use them during computation in kernel. For example,
instance_norm_gradregisteredkernelinInstanceNormGradMaker, which is not used inInstanceNormGradKernel.This could have two problems,
In order to reduce unused variables, this PR,
InputVar,MultiInput,MultiInputVar, compare them with op's inputs registered, and report unused variables during operator running.unused_var_checkto CI job. (PR_CI_Coverage)See wiki for more details.