Repository navigation
[Feature] Add CluMuT - #476
Open
FrankYiquan wants to merge 17 commits into
Open
FrankYiquan wants to merge 17 commits into
FrankYiquan wants to merge 17 commits into
Conversation
Leon-Leyang
requested changes
Nov 24, 2026
Leon-Leyang
left a comment
Collaborator
There was a problem hiding this comment.
Hi @FrankYiquan, I've gone through the PR. Please check the issues below:
stable_pretraining/forward.py: there's no CluMuT forward function. Please add one and haveCluMuT.forwardcall it.stable_pretraining/methods/clumut.py:131: the batch-dict path only handles two-view batches, so a single-view validation batch raises aValueError, and on two-view batches it returns no labels matching the stackedembedding(line 173), soOnlineProbecan't be used. The new CluMuT forward function should handle both cases, asforward.simclrdoes.stable_pretraining/__init__.pyi:CluMuTisn't listed, so type checkers and IDEs don't seespt.CluMuT.stable_pretraining/tests/unit/test_clumut.py:91: no test checks the identitization loss or the correlation matrix against a reference value. This test recomputes the loss with the sameF.kl_divcalls as the implementation.stable_pretraining/tests/unit/test_clumut.py:111: no test checks that the loss and gradients stay finite on extreme inputs, such as saturated assignments.stable_pretraining/tests/unit/test_clumut.py:232: no test trainsCluMuTthroughspt.Manager(a small model and a few training steps are enough) and resumes from a checkpoint. This test runs one step with a barepl.Trainer.- There's no real two-process DDP test, although the identitization loss uses the cross-correlation over the batch (
stable_pretraining/losses/clumut.py:54-60). examples/clumut_cifar10.py: please move the script behind the reported runs tobenchmarks/cifar10/.- PR description: the global batch size (per-GPU batch × number of GPUs) isn't stated.
- Please state in the docstrings whether the correlation statistics of the identitization loss (
stable_pretraining/losses/clumut.py:54-60) are per GPU or global under DDP. RELEASES.rst,docs/source/api/: there's no CluMuT release entry, andCluMuTandCluMuTLossaren't listed inmethods.rstandlosses.rst, although the PR checklist ticks both.
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #476 +/- ##
==========================================
- Coverage 98.17% 98.14% -0.04%
==========================================
Files 163 165 +2
Lines 16406 16507 +101
==========================================
+ Hits 16107 16201 +94
- Misses 299 306 +7 🚀 New features to boost your workflow:
|
Leon-Leyang
requested changes
Dec 4, 2026
Leon-Leyang
left a comment
Collaborator
There was a problem hiding this comment.
Hi @FrankYiquan, I've gone through the changes. This point from my review isn't addressed yet:
- PR description: the global batch size of the reported runs (per-GPU batch × number of GPUs) still isn't stated. The script now says
--batch-sizeis per GPU, but not how many GPUs the runs used.
Please also check these items, which weren't raised before:
stable_pretraining/forward.py:317: the CluMuT losses are logged only whenstage == "train", butModule.training_steppassesstage="fit", so training runs such asbenchmarks/cifar10/clumut_cifar10.pyno longer log them.docs/source/api/forward.rst: there's no entry for the newforward.clumut.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements CluMuT (Cluster-based Mutual Targeting), a self-supervised learning method that learns useful image representations by discovering clusters in the embedding space, without requiring labeled data during pretraining, negative pairs, or explicit cluster balancing.
For each input image, CluMuT generates two augmented views and passes them through a shared encoder and projector. Learnable prototypes map the resulting representations to cluster assignments. Training combines two complementary objectives:
The CIFAR-10 example follows a two-stage evaluation pipeline:
This evaluation protocol measures how well the pretrained encoder represents images without fine-tuning its parameters.
Paper: [Self-supervised learning from images: No negative pairs, no cluster-balancing](https://www.sciencedirect.com/science/article/pii/S003132032400832X)
The paper also indicates CluMut is implemented based on this code.
Full CluMuT Project Changes
stable_pretraining/methods/clumut.py— Implements the CluMuT model: a shared encoder and projector, learnable cluster prototypes, two-view assignments, and the combined mutual-targeting and identitization objectives.stable_pretraining/losses/clumut.py— Implements the symmetric stop-gradient KL mutual-targeting loss, batch-wise cross-correlation, and identitization loss with a configurable off-diagonal scale.examples/clumut_cifar10.py— Provides the CIFAR-10 experiment: data loading and two-view augmentation, ResNet-18 training, optimizer and schedule setup, checkpoint save/resume, diagnostics, and frozen-encoder linear evaluation. Includes--lambd(default0.05) and--linear-eval-lr(default0.01).stable_pretraining/tests/unit/test_clumut.py— Tests CluMuT model behavior, loss calculations, CIFAR-10 transforms, diagnostics, and training/checkpoint integration.stable_pretraining/__init__.py— ExposesCluMuTthrough the library’s top-level lazy-import API.stable_pretraining/methods/__init__.py— Registers and exports theCluMuTmethod.stable_pretraining/losses/__init__.py— Registers and exportsCluMuTLoss.METHODS.md— Adds CluMuT to the library’s method catalog.Validation
Implementation and code quality
git diff --checkpassed.Initial comparison with the paper
We pretrained the CluMuT encoder on CIFAR-10 for 300 epochs with a batch size of 128 and λ=0.05. We saved encoder checkpoints during training, froze the encoder at selected checkpoints, and trained a linear classifier over the checkpoint we saved on the labeled CIFAR-10 training set for 300 epochs using a learning rate of 0.01. We evaluated each classifier by its top-1 accuracy on the CIFAR-10 test set and compared the results with those reported in the original paper.
Checklist