-
Notifications
You must be signed in to change notification settings - Fork 6k
Enhance backward process #18700
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
Enhance backward process #18700
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,18 @@ def simple_net1(): | |
| return loss | ||
|
|
||
|
|
||
| def simple_net2(): | ||
| x = fluid.layers.data(name='image', shape=[784], dtype='float32') | ||
| label = fluid.layers.data(name='label', shape=[1], dtype='int64') | ||
| feature = fluid.layers.fc(input=x, size=10, act=None) | ||
| label = fluid.layers.cast(label, dtype="float32") | ||
| label = fluid.layers.cast(label, dtype='int64') | ||
| # Note that the label is not persistable in fluid.layers.cross_entropy. | ||
| loss = fluid.layers.cross_entropy(input=feature, label=label) | ||
|
Contributor
Author
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. Note that the label is not persistable in
Contributor
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. 这个解释https://github.com/PaddlePaddle/Paddle/pull/18700/files#r305269149 可以加入单测代码中么? |
||
| loss = fluid.layers.mean(loss) | ||
| return loss | ||
|
|
||
|
|
||
| class TestBackward(unittest.TestCase): | ||
| def check_backward(self, model): | ||
| place = fluid.CPUPlace() | ||
|
|
@@ -51,6 +63,7 @@ def check_backward(self, model): | |
|
|
||
| def test_backward(self): | ||
| self.check_backward(simple_net1) | ||
| self.check_backward(simple_net2) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
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.
Maybe better to add comments for grad_op_descs, ops, input_grad_names_set
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