-
Notifications
You must be signed in to change notification settings - Fork 825
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
Dev bcewithlogits loss #4024
Dev bcewithlogits loss #4024
Conversation
推导了一下,知道 pytroch 的公式为什么是这个形式的了: 下面是带 pos_weight 的版本: 文档说是用到了 log-sum-exp 这个 trick,查了下资料 |
之前看过几个基于softmax的,现在好像更清晰了, 为了避免负数 在 计算 e^(-x) 出现溢出情况, 先反转,取到max,再间接通过 log-sum-exp 这个小技巧来避免了数值溢出 |
* remove sigmoid * add Bce with logits loss * add test cases * refine * change random distribution Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com> Former-commit-id: 40e939e
BCEWithLogitsLoss 相当于 sigmoid + bceloss, 但是Pytorch为了更好的数值稳定性, 没有直接使用sigmoid运算, 而是做了一些数学操作, 下面是其源代码
使用了大量数学操作,以及inplace操作
为了更清晰的表示整个计算思路,相关计算的python版本,会在单测中体现