Skip to content

fix: honor train_bn in BackboneFinetuning.freeze_before_training#21652

Open
javierdejesusda wants to merge 1 commit intoLightning-AI:masterfrom
javierdejesusda:bugfix/21531_backbone-finetuning-train-bn
Open

fix: honor train_bn in BackboneFinetuning.freeze_before_training#21652
javierdejesusda wants to merge 1 commit intoLightning-AI:masterfrom
javierdejesusda:bugfix/21531_backbone-finetuning-train-bn

Conversation

@javierdejesusda
Copy link
Copy Markdown
Contributor

@javierdejesusda javierdejesusda commented Apr 6, 2026

What does this PR do?

Fixes #21531

BackboneFinetuning.freeze_before_training() called self.freeze(pl_module.backbone) without forwarding the train_bn parameter, so BatchNorm layers stayed trainable during the initial frozen phase regardless of the train_bn setting passed to the constructor.

The unfreezing path in finetune_function() already passed train_bn=self.train_bn correctly — this change makes the freezing path consistent.

Before submitting


📚 Documentation preview 📚: https://pytorch-lightning--21652.org.readthedocs.build/en/21652/

…ning

freeze_before_training() called self.freeze(pl_module.backbone)
without forwarding self.train_bn, so BatchNorm layers stayed
trainable during the initial frozen phase regardless of the
train_bn setting. The unfreezing path already passed the flag
correctly.
@github-actions github-actions Bot added the pl Generic label for PyTorch Lightning package label Apr 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79%. Comparing base (bb7820f) to head (55c2ea2).
✅ All tests successful. No failed tests found.

❗ There is a different number of reports uploaded between BASE (bb7820f) and HEAD (55c2ea2). Click for more details.

HEAD has 2053 uploads less than BASE
Flag BASE (bb7820f) HEAD (55c2ea2)
cpu 503 42
python 36 3
lightning_fabric 162 0
pytest 252 0
python3.13 108 9
lightning 179 15
python3.11 71 6
python3.12 144 12
python3.10 36 3
python3.12.7 108 9
pytorch2.1 36 6
pytest-full 251 42
pytorch_lightning 162 27
pytorch2.7 18 3
pytorch2.8 36 6
pytorch2.10 36 6
pytorch2.3 17 3
pytorch2.2.2 18 3
pytorch2.9 36 6
pytorch2.5.1 18 3
pytorch2.4.1 18 3
pytorch2.6 18 3
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #21652     +/-   ##
=========================================
- Coverage      87%      79%     -8%     
=========================================
  Files         270      267      -3     
  Lines       23934    23875     -59     
=========================================
- Hits        20713    18798   -1915     
- Misses       3221     5077   +1856     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pl Generic label for PyTorch Lightning package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackboneFinetuning: train_bn only applied during unfreezing phase

1 participant