-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implement torch._foreach_lerp
#87562
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
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/87562
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 9961184: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Also, unfortuately, it doesn't solve all needed foreach-needs of adam :( torch._foreach_mul_(acc_deltas, rho)
torch._foreach_addcmul_(acc_deltas, deltas, deltas, value=1 - rho)But foreach_lerp is useful for a more idiomatic EMA optimizer anyway. A related discussion on a generalization: ax + by #79352 (comment), maybe a more generalization would be abc + def where a, b, c, d, e, f can be scalars or tensors |
a58390e to
af90bca
Compare
|
This has now integrated |
|
Another usecase for foreach_lerp is to implement explicit, manual running stats updates for a bunch of batchnorm modules (context in #90342 (comment)). In this way, the fields running_mean/var of batchnorm modules are used to store current batch mean/var, and then the update of running_mean/var parameters is done by a separate optimizer / manually using foreach_lerp |
36d6cd7 to
2b01c3c
Compare
|
@ngimel friendly ping |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
@crcrpar Could you please then comment in #71683 what is implemented? Are the remaining things there the EMA optimizer? Btw now with this foreach_lerp, one could do elegant manual updates of BatchNorm stats params (with a manual call to foreach_lerp or to a separate EMA optimizer) and guard against NaN/Inf as one wishes |
|
There may be another frequent idiom in optimizers: that would be fixed by fused op for |
Merge failedReason: 2 additional jobs have failed, first few of them are: trunk ,trunk / linux-focal-rocm5.3-py3.8 / test (default, 2, 2, linux.rocm.gpu) Details for Dev Infra teamRaised by workflow job |
702a886 to
55c0ad4
Compare
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
and hopefully build as well. I have no idea why previous commits did work even without `<ATen/ops/_foreach_lerp_native.h>`. Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
which is a Python3.8 feature... https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
to use SampleInput Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
| #define FOREACH_TERNARY_OP(OP) \ | ||
| std::vector<Tensor> foreach_tensor_ternary_##OP##_slow(TensorList tensors1, TensorList tensors2, TensorList tensors3) { \ | ||
| check_foreach_api_restrictions(tensors1, tensors2, tensors3); \ | ||
| std::vector<Tensor> result; \ |
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.
@crcrpar Probably should have done and result.reserve(tensors1.size()); here.
As per title.
Q: Do we wanttorch._foreach_lerp.ScalarListas well?we might want to haveATen/native/cuda/lerp.cuhand include it inATen/native/cuda/Lerp.cuandATen/native/cuda/ForeachTernaryOp.cuRelated:
cc @vadimkantorov @ptrblck