-
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
Fix parallel.do with batch norm #8186
Closed
reyoung
wants to merge
4
commits into
PaddlePaddle:develop
from
reyoung:feature/parallel_do_and_batch_norm
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,8 @@ class ParallelDoGradOp : public framework::OperatorBase { | |
const std::vector<framework::Scope *> &sub_scopes, | ||
const platform::PlaceList &places) const { | ||
for (auto &s : Outputs(framework::GradVarName(kParameters))) { | ||
VLOG(10) << "Accumulating " << s; | ||
if (s == framework::kEmptyVarName) continue; | ||
std::string tmp_name; | ||
auto *tmp = sub_scopes[0]->Var(&tmp_name); | ||
|
||
|
@@ -334,16 +336,9 @@ class ParallelDoGradOpDescMaker : public framework::SingleGradOpDescMaker { | |
class ParallelDoGradOpShapeInference : public framework::InferShapeBase { | ||
public: | ||
void operator()(framework::InferShapeContext *ctx) const override { | ||
std::vector<std::string> input{kParameters, kInputs}; | ||
std::vector<std::string> output{kOutputs}; | ||
|
||
PADDLE_ENFORCE(ctx->HasInputs(kParameters)); | ||
PADDLE_ENFORCE(ctx->HasOutputs(framework::GradVarName(kParameters))); | ||
PADDLE_ENFORCE(ctx->HasInputs(kInputs)); | ||
|
||
for (auto &s : output) { | ||
PADDLE_ENFORCE(ctx->HasInputs(s)); | ||
} | ||
PADDLE_ENFORCE(ctx->HasInputs(kOutputs)); | ||
|
||
ctx->SetOutputsDim(framework::GradVarName(kParameters), | ||
ctx->GetInputsDim(kParameters)); | ||
|
@@ -360,10 +355,14 @@ class ParallelDoGradOpShapeInference : public framework::InferShapeBase { | |
ctx->SetDims({ig_name}, {i_dims[i]}); | ||
} | ||
|
||
if (ctx->HasInputs(kParameters)) { | ||
PADDLE_ENFORCE(ctx->HasOutputs(framework::GradVarName(kParameters))); | ||
ctx->SetOutputsDim(framework::GradVarName(kParameters), | ||
ctx->GetInputsDim(kParameters)); | ||
auto p_dims = ctx->GetInputsDim(kParameters); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If parameter gradient is empty, do not infer shape. |
||
auto pg_names = ctx->Outputs(framework::GradVarName(kParameters)); | ||
for (size_t i = 0; i < pg_names.size(); ++i) { | ||
auto &pg_name = pg_names[i]; | ||
if (pg_name == framework::kEmptyVarName) { | ||
continue; | ||
} | ||
ctx->SetDims({pg_name}, {p_dims[i]}); | ||
} | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,21 +274,20 @@ def get_parameters(self): | |
parent_block = self.parent_block() | ||
|
||
local_inputs = set() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous logic cannot calculate parameters that used and updated by the same operator. |
||
for op in current_block.ops: | ||
for oname in op.output_names: | ||
for out_var_name in op.output(oname): | ||
local_inputs.add(out_var_name) | ||
|
||
params = list() | ||
for var in self.inputs: | ||
local_inputs.add(var.name) | ||
|
||
params = list() | ||
for op in current_block.ops: | ||
for iname in op.input_names: | ||
for in_var_name in op.input(iname): | ||
if in_var_name not in local_inputs: | ||
params.append(in_var_name) | ||
|
||
for oname in op.output_names: | ||
for out_var_name in op.output(oname): | ||
local_inputs.add(out_var_name) | ||
|
||
params = list(set(params)) | ||
|
||
return [parent_block.var(name) for name in params] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do not accumulate
@EMPTY@