Sophiex/dev/pretrained frozen teacher#1824
Open
sophie-xhonneux wants to merge 30 commits intodevelopfrom
Open
Conversation
The fix now: 1. FrozenTeacher inspects the teacher model's actual latent_heads attribute to determine what postprocessing is needed 2. Sets up JEPA/DINO/iBOT postprocessing based on what heads exist (using identity transform for all, with warnings for DINO/iBOT since full centering isn't supported for frozen teachers) 3. Tests updated to use models with latent_heads attributes
Summary of Changes
Key insight from your feedback: The frozen teacher may have been pre-trained with any method
(forecasting, MAE, etc.) and doesn't need to have SSL latent heads. We should:
1. Use the student's training config to know which SSL losses are needed
2. Add identity heads (LatentPredictionHeadIdentity) to the teacher if they don't exist
3. Use identity postprocessing (JEPATargetProcessing) for all SSL losses
Changes Made
src/weathergen/train/target_and_aux_ssl_teacher.py:
- Added import for LatentPredictionHeadIdentity
- Rewrote FrozenTeacher.__init__ to:
- Accept training_cfg (the student's config) to determine required SSL heads
- Call _get_required_ssl_heads() to extract loss names from config
- Call _ensure_identity_heads() to add missing heads to the teacher model
- Set up identity postprocessing for all SSL losses
- Added _get_required_ssl_heads(): extracts SSL loss names from training config, defaults to {"JEPA"} if
none found
- Added _ensure_identity_heads(): adds LatentPredictionHeadIdentity for any missing heads
- Updated from_pretrained() to pass cf.training_config to constructor
tests/test_encoder_teacher.py:
- Added model_without_latent_heads fixture (simulates a forecasting-only teacher)
- Added 5 new tests:
- test_frozen_teacher_adds_identity_heads_when_missing
- test_frozen_teacher_uses_training_cfg_for_heads
- test_frozen_teacher_defaults_to_jepa_without_config
- test_frozen_teacher_preserves_existing_heads
- test_frozen_teacher_all_postprocessing_is_identity
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
The goal is to train against a frozen pre-trained teacher (e.g. by MAE)
Issue Number
#1815
Is this PR a draft? Mark it as draft.
Checklist before asking for review
./scripts/actions.sh lint./scripts/actions.sh unit-test./scripts/actions.sh integration-testlaunch-slurm.py --time 60