Skip to content

[MNT] SIGReg cleanup: dedup tests, backfill docstring, document weights#1925

Open
RecreationalMath wants to merge 4 commits into
lightly-ai:masterfrom
RecreationalMath:sigreg-cleanup
Open

[MNT] SIGReg cleanup: dedup tests, backfill docstring, document weights#1925
RecreationalMath wants to merge 4 commits into
lightly-ai:masterfrom
RecreationalMath:sigreg-cleanup

Conversation

@RecreationalMath
Copy link
Copy Markdown
Contributor

Description

Follow-up to #1916. Four small SIGReg-area improvements in lightly/loss/lejepa_loss.py and tests/loss/test_lejepa_loss.py. No production behaviour change.

  1. Remove duplicate TestSIGReg class. Refer to this comment. Aligns with the test-layout rule mentioned in this comment: one test file per source file.
  2. Tighten TestLeJEPALoss distributed test mocks to mirror the pattern TestSIGReg uses after Fix SIGReg distributed gradient under DDP #1923. Mock torch.distributed.all_reduce and torch.distributed.nn.all_reduce separately, then assert their counts individually (1 and 2) rather than the conflated call_count == 3 assertion.
  3. Backfill SIGReg class docstring with Attributes: and Examples: sections, matching the convention used by DINOLoss, VICRegLoss, BarlowTwinsLoss, etc.
  4. Document the trapezoidal weights symmetry exploit with an inline comment. The weights look like an off-by-2 bug at first glance, but the comment explains why they are not.

Documentation

  • I have updated the documentation.
  • I need help on it.

Tests

  • I have updated the tests.
  • I need help on it.

TestLeJEPALoss.test_forward_gather_distributed_world_size_gt_one
was using the pre-1923 mock pattern that only patched
torch.distributed.all_reduce.
The assertion call_count == 3 passed only because
torch.distributed.nn.all_reduce is internally implemented via
torch.distributed.all_reduce, so the mock caught both APIs together.

Mock the two APIs separately and assert their counts individually
(c10d all_reduce: 1 call for num_samples_tensor,
nn all_reduce: 2 calls for cos_sum and sin_sum),
matching the pattern TestSIGReg uses after lightly-ai#1923.
Added an inline comment explaining the symmetry exploit,
the SIGReg integrand (cos_mean - phi)^2 + sin_mean^2 is even in t,
so the integral over [-t_max, t_max] equals twice the integral over [0, t_max].
Evaluating at only the non-negative knots and doubling the
trapezoidal weights gives the same result while halving the
number of knots to evaluate.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.26%. Comparing base (5aa9d51) to head (aacfc4b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1925   +/-   ##
=======================================
  Coverage   86.26%   86.26%           
=======================================
  Files         170      170           
  Lines        7104     7104           
=======================================
  Hits         6128     6128           
  Misses        976      976           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants