Skip to content

Commit

Permalink
"ignore some gradient of specific op"
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhwinter committed Jul 19, 2017
1 parent bf4da3d commit cb95587
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions paddle/framework/op_proto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ message VarProto {
// "temporary_index": [1]
// }
optional bool temporary = 4 [default=false];

// The gradient of operator can be ignored immediately
// e.g. operator AddOp, y = x1 + x2, the gradient of dy/dx1, dy/dx2
// can be ignored for the future optimized on graph.
optional bool ignore_gradient = 6;
}

// Op protocol message for 3rd-party language binding.
Expand All @@ -105,4 +110,5 @@ message OpProto {

// The type of that Op.
required string type = 5;

}
16 changes: 10 additions & 6 deletions paddle/framework/op_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,29 @@ class OpProtoAndCheckerMaker {

protected:
void AddInput(const std::string& name, const std::string& comment,
bool multiple = false) {
bool multiple = false, bool ignore_gradient = false) {
auto input = proto_->mutable_inputs()->Add();
*input->mutable_name() = name;
*input->mutable_comment() = comment;
*input->set_ignore_gradient(ignore_gradient);
input->set_multiple(multiple);
if (multiple) {
SetHasMultipleInput();
}
}

void AddInputs(const std::string& name, const std::string& comment) {
AddInput(name, comment, true);
void AddInputs(const std::string& name, const std::string& comment,
bool ignore_gradient = false) {
AddInput(name, comment, true, ignore_gradient);
}

void AddOutput(const std::string& name, const std::string& comment,
bool temporary = false, bool multiple = false) {
bool temporary = false, bool multiple = false,
bool ignore_gradient = false) {
auto output = proto_->mutable_outputs()->Add();
*output->mutable_name() = name;
*output->mutable_comment() = comment;
*output->set_ignore_gradient(ignore_gradient);
output->set_multiple(multiple);
if (multiple) {
SetHasMultipleOutput();
Expand All @@ -104,8 +108,8 @@ class OpProtoAndCheckerMaker {
}

void AddOutputs(const std::string& name, const std::string& comment,
bool temporary = false) {
AddOutput(name, comment, temporary, true);
bool temporary = false, bool ignore_gradient = false) {
AddOutput(name, comment, temporary, true, ignore_gradient);
}

template <typename T>
Expand Down

0 comments on commit cb95587

Please sign in to comment.