Make the normalization operator more general and fix bug in l2_normalize.#11348
Merged
qingqing01 merged 6 commits intoPaddlePaddle:developfrom Jun 12, 2018
Merged
Make the normalization operator more general and fix bug in l2_normalize.#11348qingqing01 merged 6 commits intoPaddlePaddle:developfrom
qingqing01 merged 6 commits intoPaddlePaddle:developfrom
Conversation
1. Refine the raw norm_op and let it more general to support to normalize Tensor along any axis. 2. There is bug in l2_normalize API, which lacks of sqrt after . 3. Use norm_op to refine the l2_normalize API.
paddle/fluid/operators/norm_op.h
Outdated
|
|
||
| // y = x / sqrt((sum(x * x) + epsilon)) | ||
| // norm = sqrt(sum(x * x) + epsilon) | ||
| norm.device(*place) = norm + x_pow.eval().sum(rdim) + eps; |
Contributor
There was a problem hiding this comment.
你这里是不是多加个eps? 在line 68 不是已经令out_norm=eps了么?
Contributor
Author
There was a problem hiding this comment.
Yeah, refine code here. Thanks! @wanghaoshuang
| // dx = ( dy/sqrt(sum(x*x)) ) * [1 - x*sum(x) / sum(x*x)] | ||
| sum.device(*place) = (x * dy).sum(rdim); | ||
| dx.device(*place) = sum.reshape(rshape).broadcast(bcast) * x; | ||
| dx.device(*place) = dx / norm.pow(2).broadcast(bcast); |
Contributor
There was a problem hiding this comment.
norm.pow(2) = sum(x*x) + eps ,但是我在你的公式里没有看到eps?
Contributor
Author
There was a problem hiding this comment.
I modify the above formula.
paddle/fluid/operators/norm_op.h
Outdated
| Eigen::DSizes<int, 3> bcast(1, n, 1); | ||
| Eigen::DSizes<int, 3> rshape(pre, 1, post); | ||
|
|
||
| // dx = ( dy/sqrt(sum(x*x)) ) * [1 - x*sum(x) / sum(x*x)] |
Contributor
There was a problem hiding this comment.
怎么感觉你这个公式和实际计算过程有diff?可以把每一步的计算标注下么?
Contributor
Author
There was a problem hiding this comment.
Thanks for so detailed review. I add comments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #11345
Fix #7266