-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[XPU] reuse logits and softmax to avoid redundant memory allocation #68906
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
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
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 for shareDataWith
|
这个PR修改了 |
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
| logits_2d.Resize({N, D}); | ||
| softmax_2d.Resize({N, D}); | ||
| logits_2d.ShareDataWith(*logits).Resize({N, D}); | ||
| softmax_2d.ShareDataWith(*softmax).Resize({N, D}); |
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.
下面CSoftmaxWithCrossEntropyFunctor(line 389~line 395)那里是不是也可以一起改下?
b59033a to
910294f
Compare
| logits_2d.Resize({N, D}); | ||
| softmax_2d.Resize({N, D}); | ||
| logits_2d.ShareDataWith(*logits).Resize({N, D}); | ||
| softmax_2d.ShareDataWith(*softmax).Resize({N, D}); |
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.
sharedatawith我记得paddle同学说过,是访问同一块地址,会有潜在的风险。之前paddle cast,在数据类型相同时,就是用了sharedatawith,模型训练有时就会有奇怪的现象
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.
这个算子比较特殊,sharedatawith的是两个临时tensor。其中logits_2d不会被修改,softmax_2d在修改后原本就会被写回原地址,逻辑上跟之前一样,所以不会有问题。
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
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
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
PR Category
Custom Device
PR Types
Improvements
Description
Using "ShareDataWith" instead of "TensorCopy" for logits and softmax to avoid redundant memory alloc.