-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add sgd op #2950
Add sgd op #2950
Conversation
paddle/operators/sgd_op.cc
Outdated
AddInput("param", "input parameter"); | ||
AddInput("grad", "input gradient"); | ||
AddOutput("param_out", "output parameter"); | ||
AddAttr<float>("learning_rate", "learning rate of sgd").SetDefault(0.1); |
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 set a default learning rate, because it should not be set by framework and must be set by user.
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
paddle/operators/sgd_op.cc
Outdated
const std::vector<framework::Tensor *> &outputs) const override { | ||
PADDLE_ENFORCE(inputs.size() == 2, "Input size of SGDOp must be two"); | ||
PADDLE_ENFORCE(outputs.size() == 1, "Output size of SGDOp must be one"); | ||
PADDLE_ENFORCE( |
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.
As we discussed before, PADDLE_ENFORCE
should not take complex logic
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
paddle/operators/sgd_op_test.cc
Outdated
limitations under the License. */ | ||
|
||
#include <gtest/gtest.h> | ||
#define private public |
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.
no black magic, please.
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.
removed
self.grad = numpy.random.random((342, 345)).astype("float32") | ||
self.learning_rate = 0.1 | ||
self.param_out = self.param - self.learning_rate * self.grad | ||
|
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.
seems it is does not finished 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.
By using current op unit test framework, the developer only needs to setUp
this variable, the test method is injected by OpTestMeta
.
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, but need use this #2962 to simplify Op class.
No description provided.