-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Op refine for making build system more automatic #3881
Changes from 8 commits
9d2909b
58369d5
a60128a
740c8ba
3ab9327
020e45f
2beaf3a
4251349
8ef17ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. */ | ||
|
||
#include "paddle/operators/net_op.h" | ||
#include "paddle/operators/scale_op.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
|
||
// identity is a alias of scale op. This is also a example for creating a alias | ||
// operator. | ||
template <typename AttrType> | ||
class IdentityOpMaker : public framework::OpProtoAndCheckerMaker { | ||
public: | ||
IdentityOpMaker(framework::OpProto *proto, | ||
framework::OpAttrChecker *op_checker) | ||
: OpProtoAndCheckerMaker(proto, op_checker) { | ||
AddInput("X", "input tensor of identity op"); | ||
AddOutput("Out", "output tensor of identity op"); | ||
AddComment("identity operator. Just a alias of scale op which scale = 1.0"); | ||
} | ||
}; | ||
|
||
template <typename AttrType> | ||
class IdentityOp : public NetOp { | ||
public: | ||
IdentityOp(const std::string &type, const framework::VariableNameMap &inputs, | ||
const framework::VariableNameMap &outputs, | ||
const framework::AttributeMap &attrs) | ||
: NetOp(type, inputs, outputs, attrs) { | ||
AppendOp(framework::OpRegistry::CreateOp( | ||
"scale", {{"X", {Input("X")}}}, {{"Out", {Output("Out")}}}, | ||
{{"scale", static_cast<AttrType>(1)}})); | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
|
||
REGISTER_OP_WITHOUT_GRADIENT(identity, ops::IdentityOp<float>, | ||
ops::IdentityOpMaker<float>); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ The equation is: Out = scale*X | |
} | ||
}; | ||
|
||
// Identity Op's gradient is identity op, too. | ||
// Scale Op's gradient is scale op, too. | ||
// Grad(Out=scale(X)) => Grad(X) = scale(Grad(Out)) | ||
template <typename AttrType> | ||
class ScaleGradOp : public NetOp { | ||
|
@@ -65,33 +65,6 @@ class ScaleGradOp : public NetOp { | |
} | ||
}; | ||
|
||
// identity is a alias of scale op. This is also a example for creating a alias | ||
// operator. | ||
template <typename AttrType> | ||
class IdentityOpMaker : public framework::OpProtoAndCheckerMaker { | ||
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. Why remove the 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. @reyoung 只是把 |
||
public: | ||
IdentityOpMaker(framework::OpProto *proto, | ||
framework::OpAttrChecker *op_checker) | ||
: OpProtoAndCheckerMaker(proto, op_checker) { | ||
AddInput("X", "input tensor of identity op"); | ||
AddOutput("Out", "output tensor of identity op"); | ||
AddComment("identity operator. Just a alias of scale op which scale = 1.0"); | ||
} | ||
}; | ||
|
||
template <typename AttrType> | ||
class IdentityOp : public NetOp { | ||
public: | ||
IdentityOp(const std::string &type, const framework::VariableNameMap &inputs, | ||
const framework::VariableNameMap &outputs, | ||
const framework::AttributeMap &attrs) | ||
: NetOp(type, inputs, outputs, attrs) { | ||
AppendOp(framework::OpRegistry::CreateOp( | ||
"scale", {{"X", {Input("X")}}}, {{"Out", {Output("Out")}}}, | ||
{{"scale", static_cast<AttrType>(1)}})); | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle | ||
|
||
|
@@ -101,5 +74,3 @@ REGISTER_OP(scale, ops::ScaleOp, ops::ScaleOpMaker<float>, scale_grad, | |
ops::ScaleGradOp<float>); | ||
REGISTER_OP_CPU_KERNEL(scale, | ||
ops::ScaleKernel<paddle::platform::CPUPlace, float>); | ||
REGISTER_OP_WITHOUT_GRADIENT(identity, ops::IdentityOp<float>, | ||
ops::IdentityOpMaker<float>); |
This file was deleted.
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 message is fine, because sometimes we can implement the CPU version only and then implement GPU version.