Commit d334a2f
Fix unit test for rowwise adagrad with counter (#5908)
Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2827
Pull Request resolved: #5908
Fix the reference implementation in `backward_optimizers_test.py` for `EXACT_ROWWISE_ADAGRAD` with `WeightDecayMode.COUNTER`. The numerical mismatch was masked by the `differing_executors` health check preventing the test from running.
Two distinct discrepancies between the test reference and the kernel are fixed:
1. **Gradient used for the weight update (`L2`/`COWCLIP`).** The kernel computes momentum (`g_avg_square`) from the L2-modified gradient but uses the raw gradient for the weight update, applying weight decay separately via `exp_reg_correction`. The test was using the L2-modified gradient for both. Fixed by keeping a `raw_grad` copy and passing it to the weight-update helpers.
2. **Missing `lazy_multiplier` (`AdagradW`).** The kernel scales both `adjusted_multiplier` and `exp_reg_correction` by `(1 - wd * lr) ** (min(lazy_delta, iter - adjustment_iter) - 1)`, where `lazy_delta` depends on the *pre-update* `prev_iter` (the kernel reads `prev_iter` before overwriting it with the current iteration). The reference omitted this entirely and only had the post-update `prev_iter` from optimizer state. Fixed by capturing the pre-update `prev_iter` in the setup loop and implementing the `lazy_multiplier` in the `AdagradW` branch.
Reviewed By: q10
Differential Revision: D108710672
fbshipit-source-id: 20d8b2d09a392d510ea21101a409537cce1aabee1 parent 8453f6c commit d334a2f
1 file changed
Lines changed: 38 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
397 | 402 | | |
398 | 403 | | |
399 | 404 | | |
| |||
405 | 410 | | |
406 | 411 | | |
407 | 412 | | |
| 413 | + | |
408 | 414 | | |
409 | 415 | | |
410 | 416 | | |
| |||
491 | 497 | | |
492 | 498 | | |
493 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
494 | 506 | | |
495 | 507 | | |
496 | 508 | | |
| |||
545 | 557 | | |
546 | 558 | | |
547 | 559 | | |
548 | | - | |
| 560 | + | |
549 | 561 | | |
550 | 562 | | |
551 | 563 | | |
| |||
557 | 569 | | |
558 | 570 | | |
559 | 571 | | |
| 572 | + | |
560 | 573 | | |
561 | 574 | | |
562 | 575 | | |
563 | | - | |
| 576 | + | |
564 | 577 | | |
565 | 578 | | |
566 | 579 | | |
| |||
839 | 852 | | |
840 | 853 | | |
841 | 854 | | |
842 | | - | |
| 855 | + | |
843 | 856 | | |
844 | 857 | | |
845 | 858 | | |
| |||
852 | 865 | | |
853 | 866 | | |
854 | 867 | | |
| 868 | + | |
855 | 869 | | |
856 | 870 | | |
857 | 871 | | |
| |||
942 | 956 | | |
943 | 957 | | |
944 | 958 | | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
945 | 980 | | |
946 | 981 | | |
947 | 982 | | |
| |||
0 commit comments