Skip to content

[Feature] Add CorInfoMax - #468

Open
ChandradithyaJ wants to merge 3 commits into
galilai-group:mainfrom
ChandradithyaJ:corinfomax
Open

ChandradithyaJ wants to merge 3 commits into
galilai-group:mainfrom
ChandradithyaJ:corinfomax

Conversation

@ChandradithyaJ

@ChandradithyaJ ChandradithyaJ commented Oct 11, 2026 •

Copy link
Copy Markdown

Description

Adds CorInfoMax, a self-supervised method that learns from two augmented views using a shared encoder and projector. The objective combines mean-squared agreement between normalized projections with covariance log-determinants that discourage dimensional collapse. Running means and covariances incorporate previous batches. Current-batch statistics remain differentiable, while retained history is detached and checkpointed.

Reference: Ozsoy et al., “Self-Supervised Learning with an Information Maximization Criterion” (NeurIPS 2022).

What's included

  • CorInfoMaxLoss: configurable agreement/covariance weights, normalization, statistics precision, and checkpointed running statistics.
    • stable_pretraining/losses/joint_embedding.py
    • stable_pretraining/losses/__init__.py
  • CorInfoMax: configurable encoders/projectors with tensor and dictionary input support.
    • stable_pretraining/methods/corinfomax.py
    • stable_pretraining/methods/__init__.py
  • Composable forward function: paired-view training and embedding-only evaluation.
    • stable_pretraining/forward.py
  • Public API: lazy top-level export and typing stub.
    • stable_pretraining/__init__.py
    • stable_pretraining/__init__.pyi
  • CIFAR-10 recipe: separate pretraining, frozen linear fitting, and evaluation phases, including checkpoint loading and resume support.
    • examples/corinfomax_cifar10.py
  • 31 dedicated unit test cases: numerical reference comparisons, gradients, checkpoint continuation, precision, evaluation-state preservation, batch layouts, callback compatibility, and scheduler behavior.
    • stable_pretraining/tests/unit/test_corinfomax.py
  • Documentation and release notes:
    • METHODS.md
    • RELEASES.rst
    • docs/source/api/methods.rst
    • docs/source/api/losses.rst
    • docs/source/api/forward.rst

Verification

Completed CIFAR-10 training with ResNet-18: 1,000 self-supervised pretraining epochs followed by 100 epochs of frozen-backbone linear evaluation.

Result Top-1 Top-5
Final linear-evaluation epoch 92.75% 99.84%
Standalone evaluation of the selected checkpoint 92.85% 99.86%
Paper, Table 1 93.18% —

Final-epoch top-1 accuracy is 0.43 percentage points below the paper. The best observed test top-1 was 92.85%; this is reported separately because checkpoint selection used test accuracy. Standalone evaluation is not an independent training seed.

Test Results

  • CorInfoMax: all 31 dedicated test cases passed.
    • None of the failing tests are CorInfoMax tests.
  • Ruff lint: passed.
    • Repository-wide pre-commit: all applicable hooks passed on rerun after the automatic formatting change.
  • New example and test files: all applicable hooks passed in the subsequent targeted pre-commit run.
  • Documentation: HTML build completed with 23 warnings, including docstring formatting and unresolved references. One unresolved reference concerns the CorInfoMax gallery example. Gallery execution was disabled.

Checklist

  • I have read the Contributing document.
  • The documentation is up-to-date with the changes I made (check build artifacts).
  • All tests passed, and additional code has been covered with new tests.
  • I have added the PR to the RELEASES.rst file.

@ChandradithyaJ ChandradithyaJ changed the title Add CorInfoMax [WIP] Add CorInfoMax Oct 13, 2026
@ChandradithyaJ ChandradithyaJ changed the title [WIP] Add CorInfoMax [Feature] Add CorInfoMax Oct 15, 2026
@Leon-Leyang Leon-Leyang mentioned this pull request Nov 21, 2026
4 tasks done

@Leon-Leyang Leon-Leyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ChandradithyaJ, I've gone through the PR. Please check the issues below:

  • stable_pretraining/tests/unit/test_corinfomax.py: no test trains CorInfoMax through spt.Manager (a small model and a few training steps are enough) and resumes from a checkpoint, showing that the running means and covariances survive.
  • There's no real two-process DDP test of CorInfoMaxLoss, which gathers the projections across GPUs for its batch statistics and running history (stable_pretraining/losses/joint_embedding.py:185).
  • stable_pretraining/tests/unit/test_corinfomax.py: no test checks that the loss and gradients stay finite on extreme inputs.
  • examples/corinfomax_cifar10.py: please move the script behind the reported results to benchmarks/cifar10/, and update its docstring (line 7), which points to a CorInfoMax.md that isn't in the PR.
  • PR description: the batch size of the reported run isn't stated.
  • stable_pretraining/losses/joint_embedding.py:209-212: with statistics_dtype=torch.float32 and normalize=False, the loss turns NaN when the batch is smaller than the projection width and the projections are large, since float32 rounding makes the covariance passed to torch.logdet indefinite. Please guard against it (e.g. a larger ε relative to the covariance scale) or document that this combination needs float64.

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.52542% with 5 lines in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             main     #468      +/-   ##
==========================================
- Coverage   98.17%   98.15%   -0.03%     
==========================================
  Files         163      164       +1     
  Lines       16406    16465      +59     
==========================================
+ Hits        16107    16161      +54     
- Misses        299      304       +5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChandradithyaJ

ChandradithyaJ commented Nov 30, 2026 •

Copy link
Copy Markdown
Author

Thanks for the detailed review, @Leon-Leyang. I’ve addressed the implementation and test requests and completed a fresh CIFAR-10 run after the numerical fix.

  1. Manager checkpoint/resume: Added a small training test through spt.Manager. It verifies exact restoration of both running means and covariances before training continues, then compares resumed training with uninterrupted training under the same learning-rate schedule.

  2. Real distributed coverage: Added a two-process DDP test comparing the loss, projection gradients, encoder parameter gradients, and running statistics against a global-batch reference over three steps. The two-GPU NCCL test passed in job 9783846. The NCCL case now skips when NCCL or two visible CUDA devices are unavailable.

  3. Extreme-input coverage: Added 16 cases covering zero, tiny, constant, and large projections, with float32/float64 statistics and normalization enabled/disabled. These verify finite losses, gradients, and retained statistics across repeated updates, including batches smaller than the projection width.

  4. Benchmark location: Moved the recipe to benchmarks/cifar10/corinfomax-resnet18.py, updated its docstring and references, and documented commands and results in benchmarks/README.md. Removed the missing CorInfoMax.md reference.

  5. Explicit batch sizes: The CIFAR-10 recipe uses batch size 512 for 1,000 pretraining epochs and batch size 256 for 100 frozen-backbone linear-fitting epochs, on one GPU. Batch sizes count original images; pretraining creates two augmented views per image, with no gradient accumulation.

  6. Float32 numerical guard: The covariance log-determinant now uses diagonal regularization with a covariance-scale roundoff floor, addressing the reported float32 failure with large, low-rank, unnormalized projections. The regularizer is excluded from the stored covariance history.

Using a CIFAR-resolution ResNet-18, a 2048–2048–64 projector:

Run Final test top-1 Final test top-5 Best observed test top-1
Earlier run 92.75% 99.84% 92.85%
After the numerical fix 92.76% 99.83% 92.90%

Both training phases completed their configured epochs and saved their final checkpoints. Standalone evaluation reloaded the final linear checkpoint and reproduced 92.76% top-1 / 99.83% top-5 on all 10,000 CIFAR-10 test images.

The primary result uses the final epoch. Best observed test accuracy is descriptive, and standalone evaluation reloads the same checkpoint rather than adding an independent training seed.

The accuracy rerun preserves the original recipe’s normalized projections and float64 running statistics. The reported float32 configuration is covered separately by the extreme-input regression tests.

Validation completed:

  • 48 non-distributed CorInfoMax tests passed, including Manager checkpoint/resume coverage.
  • The real two-GPU NCCL DDP test passed.
  • All 16 extreme-input cases passed again before the fresh training run.
  • Ruff checks passed during the preceding implementation validation.

@Leon-Leyang Leon-Leyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ChandradithyaJ, I've gone through the changes and it looks good to me.

This branch has not been deployed

No deployments
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