Skip to content

test: add coverage for AMWA (Adaptive Momentum Weight Averaging) - #455

Merged
Demirrr merged 1 commit into
developfrom
test/amwa-coverage
Sep 16, 2026
Merged

Demirrr merged 1 commit into
developfrom
test/amwa-coverage

Conversation

@Demirrr

@Demirrr Demirrr commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #447.

AMWA (dicee/weight_averaging.py, added in #440) was the only weight-averaging technique without dedicated tests — SWA/SWAG/EMA/TWA are covered by tests/test_swa.py, ASWA by tests/test_adaptive_swa.py. It had only ever been smoke-tested manually.

Adds tests/test_amwa.py (22 tests):

  • End-to-end Execute() runs confirming amwa.pt/amwa_history.json get written with the expected fields, under both torchCPUTrainer and PL.
  • Direct unit tests of AMWA._compute_momentum/_compute_beta_n/_compute_delta: zero/negative delta, monotonicity, fixed vs. adaptive beta, delta_history shorter than beta_window, window truncation, maximize=False.
  • Direct tests of the StableNet EMA update formula (w_stable <- m*w_stable + (1-m)*w_base) at momentum 0/0.25/1.
  • A test confirming PeriodicEvalCallback.on_train_epoch_end actually checkpoints AMWA's StableNet (via trainer.wa_model), not the live BaseNet, during AMWA training.

No source changes — test-only PR.

Test plan

  • ruff check dicee/ --line-length=200 — clean (unaffected, test-only change)
  • All 22 new tests pass
  • Verified the periodic-eval test genuinely catches a regression: temporarily forced the live model into the AMWA eval-model-selection branch in dicee/callbacks.py and confirmed the test fails (100% tensor mismatch, not just a shape/type check), then reverted
  • Also confirmed the test correctly tolerates the intentional disk-fallback path (amwa.pt reload) when only trainer.wa_model itself is unset — it's a legitimate alternate route to the same StableNet weights, not a regression

AMWA (dicee/weight_averaging.py, added in #440) was the only weight
averaging technique without dedicated tests - SWA/SWAG/EMA/TWA are
covered by tests/test_swa.py, ASWA by tests/test_adaptive_swa.py. It had
only ever been smoke-tested manually.

Adds tests/test_amwa.py:
- end-to-end Execute() runs confirming amwa.pt/amwa_history.json are
  written with the expected fields, under both torchCPUTrainer and PL
- direct unit tests of AMWA._compute_momentum/_compute_beta_n/
  _compute_delta: zero/negative delta, monotonicity, fixed vs adaptive
  beta, history shorter than beta_window, window truncation, maximize=False
- direct tests of the StableNet EMA update formula
  (w_stable <- m*w_stable + (1-m)*w_base) at momentum 0/0.25/1
- a test confirming PeriodicEvalCallback's on_train_epoch_end actually
  checkpoints AMWA's StableNet (via trainer.wa_model), not the live
  BaseNet, during AMWA training - verified this test genuinely catches a
  regression by temporarily forcing the live model into that code path
  (100% tensor mismatch) before reverting

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Demirrr
Demirrr merged commit 8345b13 into develop Sep 16, 2026
7 checks passed
@Demirrr
Demirrr deleted the test/amwa-coverage branch September 16, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AMWA (Adaptive Momentum Weight Averaging) has no dedicated test

1 participant