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
SINGA -475 add Sign operator to singa #488
Conversation
ready for merge |
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 have run the test in docker container using cloud K80. It passes the tests.
I have left four comments above which are minor issue. It will be ready for merge after these minor changes.
test/python/test_operation.py
Outdated
|
||
result = autograd.sign(x) | ||
dx = result.creator.backward(dy.data) | ||
#dx = [x/|x|]' |
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.
delete the comment line at 625:
#dx = [x/|x|]'
test/python/test_operation.py
Outdated
|
||
result = autograd.sign(x) | ||
dx = result.creator.backward(dy.data) | ||
#dx = [x/|x|]' |
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.
delete the comment line at 644:
#dx = [x/|x|]'
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.
fix the code
|
||
|
||
class Sign(Operation): | ||
def forward(self, a): |
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.
Add the default initializer:
def __init__(self):
super(Sign, self).__init__()
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.
fix the code
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 for the modification. The below is the reason why this is needed.
This function passes the name "Sign" to the superclass (Operation) initializer.
The superclass Operation initializer is as follows:
class Operation(object):
op_count = 0
def __init__(self, name=None):
if name is None:
self.name = "{}#{}".format(
self.__class__.__name__, Operation.op_count
)
Operation.op_count += 1
else:
self.name = name
If there is no initialzer in the subclass, the superclass initializer will be used instead with the "name=None"
Thanks! Ready for merge |
return singa.Sign(a) | ||
|
||
def backward(self, dy): | ||
dx = singa.MultFloat(dy, 0.0) |
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.
the dx is always 0?
In my opinion: As a result, dx is always 0 while the output shape (size of array) is the same as input shape. |
This is what tensorflow uses: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/gradients/math_grad.cc#L268 Status SignGrad(const Scope& scope, const Operation& op,
const std::vector<Output>& grad_inputs,
std::vector<Output>* grad_outputs) {
auto shape = Shape(scope, op.input(0));
auto zero = Cast(scope, Const(scope, 0.0), op.input(0).type());
auto dx = Fill(scope, shape, zero);
grad_outputs->push_back(dx);
return scope.status();
}
REGISTER_GRADIENT_OP("Sign", SignGrad); seems to fill the dx with all zero using the dy shape |
there are conflicts and there are two solutions (same as what happened in log operator):
(I guess this maybe because different PRs put the new functions at the same line, so git detected it as different ways of changing code and hence conflicts) |
No description provided.