Skip to content

[Feature] Add Spectral Contrastive Learning - #452

Open
Chris-ZiyuK wants to merge 6 commits into
galilai-group:mainfrom
Chris-ZiyuK:add-spectral-contrastive
Open

Chris-ZiyuK wants to merge 6 commits into
galilai-group:mainfrom
Chris-ZiyuK:add-spectral-contrastive

Conversation

@Chris-ZiyuK

@Chris-ZiyuK Chris-ZiyuK commented Oct 3, 2026 •

Copy link
Copy Markdown

Description

Adds Spectral Contrastive Learning as spt.SpectralCL, with a reusable SpectralContrastiveLoss and spt.forward.spectral. SpectralCL trains directly with spt.Manager. Includes documentation, release notes and a CIFAR-10 benchmark.

DDP loss and parameter gradients are tested with two real CPU/gloo processes. Tests also cover zero/tiny-input gradients and training SpectralCL with spt.Manager, including checkpoint resume.

CIFAR-10 results

ResNet-18, 200 epochs, batch size 512, seed 0, one RTX 3090. Both objectives use the same backbone, projector and training setup.

Method KNN top-1 Online linear top-1
SimCLR / NT-Xent 82.78% 83.30%
Spectral (μ=1) 81.59% 81.38%
Spectral (μ=10) 84.30% 84.68%

Final-epoch online scores from one run per configuration. The paper uses offline linear evaluation.

Testing

Feature tests, real-process DDP tests and pre-commit pass. Docs build with the same warnings as base. The full macOS unit suite has three failures that also occur on the unchanged base; GitHub CI is awaiting maintainer approval.

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. (the three macOS unit failures also occur on base)
  • I have added the PR to the RELEASES.rst file.

@RandallBalestriero

Copy link
Copy Markdown
Contributor

Please support the dict-based training contract, add the top-level export, and test DDP gradients with real processes rather than mocked gathering.

@Chris-ZiyuK Chris-ZiyuK changed the title [WIP] Add Spectral Contrastive Learning [Feature] Add Spectral Contrastive Learning Oct 19, 2026
@Chris-ZiyuK
Chris-ZiyuK marked this pull request as draft October 19, 2026 19:35
Keep ball-projection gradients finite for tiny inputs, expose composable loss
and forward APIs, and seed identical benchmark architectures before initialization.
Run real CPU DDP regressions in CI and reject crashed or timed-out workers.
@Chris-ZiyuK
Chris-ZiyuK marked this pull request as ready for review October 21, 2026 15:24
@Leon-Leyang

Copy link
Copy Markdown
Collaborator

Hi @Chris-ZiyuK, I've gone through the changes, and everything Randall asked for is addressed. Please also check the items below, which weren't raised in the first review:

  • benchmarks/cifar10/spectral-resnet18.py:162, stable_pretraining/tests/unit/test_spectral_forward.py:69: neither the benchmark nor any test trains SpectralCL itself through spt.Manager. The benchmark wraps it in a separate spt.Module that calls model(view1, view2), and the Manager test uses a composable spt.Module with an nn.Linear backbone.
  • .github/workflows/testing.yml:84, TESTING.md, stable_pretraining/tests/distributed/_dist_harness.py:56: please remove the new CI job and the run_distributed changes from this PR. Tests marked distributed aren't run in CI by design, like main's own two-process tests, and the maintainers run them separately, so your DDP test is fine as it is.

Since these weren't in the first review, this comment doesn't count as an extra review round.

The CIFAR-10 benchmark passes SpectralCL itself to Manager instead of
wrapping it in a separate Module, and a unit test trains SpectralCL with
Manager and checks checkpoint resume. Remove the CPU/gloo CI job, the
TESTING.md notes and the run_distributed changes; the spectral DDP
gradient test stays with the other distributed tests.
@Chris-ZiyuK

Copy link
Copy Markdown
Author

Hi @Leon-Leyang ! Thanks for the review.
Both are addressed in bb42ebe:

  • The benchmark now passes SpectralCL directly to spt.Manager, and test_spectral_cl.py has a new test that trains SpectralCL with spt.Manager, including checkpoint resume.
  • Removed the CI job, the TESTING.md changes, the run_distributed changes and test_harness_dist.py. The DDP test is unchanged.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@           Coverage Diff           @@
##             main     #452   +/-   ##
=======================================
  Coverage   98.17%   98.18%           
=======================================
  Files         163      165    +2     
  Lines       16406    16496   +90     
=======================================
+ Hits        16107    16197   +90     
  Misses        299      299           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 @Chris-ZiyuK, 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.

3 participants