Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Fix unfreeze strategies with onecyclelr and reduced lr #1329

Merged
merged 5 commits into from
May 6, 2022

Conversation

ethanwharris
Copy link
Collaborator

What does this PR do?

Fixes #1321

Note: This also changes the behaviour to no longer divide the learning rate by 10 when unfreezing. This could be seen as a breaking change, but also as a bug since this behaviour is undocumented and doesn't normally make sense (generally it's a good idea to use a smaller LR after unfreezing for the whole model but this should be handled by an LR scheduler not done silently by us).

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests? [not needed for typos/docs]
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@ethanwharris ethanwharris added the bug / fix Something isn't working label May 5, 2022
@ethanwharris ethanwharris added this to the 0.7.x milestone May 5, 2022
@codecov
Copy link

codecov bot commented May 5, 2022

Codecov Report

Merging #1329 (3bd7963) into master (48a2500) will increase coverage by 1.62%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1329      +/-   ##
==========================================
+ Coverage   89.84%   91.47%   +1.62%     
==========================================
  Files         287      287              
  Lines       12894    12900       +6     
==========================================
+ Hits        11585    11800     +215     
+ Misses       1309     1100     -209     
Flag Coverage Δ
unittests 91.47% <100.00%> (+1.62%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
flash/core/finetuning.py 90.69% <100.00%> (+0.69%) ⬆️
flash/core/serve/dag/task.py 96.82% <0.00%> (-1.06%) ⬇️
flash/text/question_answering/input.py 95.06% <0.00%> (+2.46%) ⬆️
flash/core/optimizers/optimizers.py 100.00% <0.00%> (+3.03%) ⬆️
flash/text/seq2seq/translation/model.py 63.63% <0.00%> (+4.54%) ⬆️
flash/text/question_answering/collate.py 97.64% <0.00%> (+7.05%) ⬆️
flash/text/question_answering/model.py 92.51% <0.00%> (+7.48%) ⬆️
flash/text/classification/collate.py 100.00% <0.00%> (+8.33%) ⬆️
flash/text/seq2seq/translation/cli.py 70.00% <0.00%> (+10.00%) ⬆️
flash/text/seq2seq/core/collate.py 100.00% <0.00%> (+12.50%) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48a2500...3bd7963. Read the comment docs.

Copy link
Contributor

@krshrimali krshrimali left a comment

Choose a reason for hiding this comment

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

Nice! I agree that we should not change the LR silently. Should we also update the docs here? (in the code sample)

def finetune_function(self, pl_module, current_epoch, optimizer, opt_idx):
    # unfreeze any module you want by overriding this function

    # When ``current_epoch`` is 5, backbone will start to be trained.
    if current_epoch == self._unfreeze_epoch:
        self.unfreeze_and_add_param_group(
             pl_module.backbone,
             optimizer,
        )

@ethanwharris ethanwharris merged commit 1ed7938 into master May 6, 2022
@ethanwharris ethanwharris deleted the bugfix/scheduler_freeze_unfreeze branch May 6, 2022 15:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug / fix Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OneCycleLR scheduler does not work with freeze-unfreeze finetuning strategy
2 participants