We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
align with PR 1.2.0
## 🚀 Feature

Atm, we have a hard link to 1.2.0rc0 which is a bit outdated...
Probably some API adjust need to be done, continue in #62

### Motivation

<!-- Please outline the motivation for the proposal. Is your feature request related to a problem? e.g., I'm always frustrated when [...]. If this is related to another GitHub issue, please link here too -->

### Pitch

<!-- A clear and concise description of what you want to happen. -->

### Alternatives

<!-- A clear and concise description of any alternative solutions or features you've considered, if any. -->

### Additional context

<!-- Add any other context or screenshots about the feature request here. -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `flash/vision/detection/finetuning.py`
Content:
```
1 # Copyright The PyTorch Lightning team.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import pytorch_lightning as pl
15 
16 from flash.core.finetuning import FlashBaseFinetuning
17 
18 
19 class ObjectDetectionFineTuning(FlashBaseFinetuning):
20     """
21     Freezes the backbone during Detector training.
22     """
23 
24     def __init__(self, train_bn: bool = True):
25         self.train_bn = train_bn
26 
27     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:
28         model = pl_module.model
29         self.freeze(module=model.backbone, train_bn=self.train_bn)
30
```

Path: `flash/core/finetuning.py`
Content:
```
1 # Copyright The PyTorch Lightning team.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 from typing import List, Union
15 
16 import pytorch_lightning as pl
17 from pytorch_lightning.callbacks import BaseFinetuning
18 from pytorch_lightning.utilities.exceptions import MisconfigurationException
19 from torch import nn
20 from torch.optim import Optimizer
21 
22 
23 class NoFreeze(BaseFinetuning):
24 
25     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:
26         pass
27 
28     def finetunning_function(
29         self,
30         pl_module: pl.LightningModule,
31         epoch: int,
32         optimizer: Optimizer,
33         opt_idx: int,
34     ) -> None:
35         pass
36 
37 
38 class FlashBaseFinetuning(BaseFinetuning):
39 
40     def __init__(self, attr_names: Union[str, List[str]] = "backbone", train_bn: bool = True):
41         r"""
42 
43         FlashBaseFinetuning can be used to create a custom Flash Finetuning Callback.
44 
45         Override ``finetunning_function`` to put your unfreeze logic.
46 
47         Args:
48             attr_names: Name(s) of the module attributes of the model to be frozen.
49 
50             train_bn: Whether to train Batch Norm layer
51 
52         """
53 
54         self.attr_names = [attr_names] if isinstance(attr_names, str) else attr_names
55         self.train_bn = train_bn
56 
57     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:
58         self.freeze_using_attr_names(pl_module, self.attr_names, train_bn=self.train_bn)
59 
60     def freeze_using_attr_names(self, pl_module, attr_names: List[str], train_bn: bool = True):
61         for attr_name in attr_names:
62             attr = getattr(pl_module, attr_name, None)
63             if attr is None or not isinstance(attr, nn.Module):
64                 MisconfigurationException(f"Your model must have a {attr} attribute")
65             self.freeze(module=attr, train_bn=train_bn)
66 
67     def finetunning_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):
68         pass
69 
70 
71 class Freeze(FlashBaseFinetuning):
72 
73     def finetunning_function(
74         self,
75         pl_module: pl.LightningModule,
76         epoch: int,
77         optimizer: Optimizer,
78         opt_idx: int,
79     ) -> None:
80         pass
81 
82 
83 class FreezeUnfreeze(FlashBaseFinetuning):
84 
85     def __init__(self, attr_names: Union[str, List[str]] = "backbone", train_bn: bool = True, unfreeze_epoch: int = 10):
86         super().__init__(attr_names, train_bn)
87         self.unfreeze_epoch = unfreeze_epoch
88 
89     def finetunning_function(
90         self,
91         pl_module: pl.LightningModule,
92         epoch: int,
93         optimizer: Optimizer,
94         opt_idx: int,
95     ) -> None:
96         if epoch != self.unfreeze_epoch:
97             return
98         modules = [getattr(pl_module, attr_name) for attr_name in self.attr_names]
99         self.unfreeze_and_add_param_group(
100             module=modules,
101             optimizer=optimizer,
102             train_bn=self.train_bn,
103         )
104 
105 
106 class UnfreezeMilestones(FlashBaseFinetuning):
107 
108     def __init__(
109         self,
110         attr_names: Union[str, List[str]] = "backbone",
111         train_bn: bool = True,
112         unfreeze_milestones: tuple = (5, 10),
113         num_layers: int = 5
114     ):
115         self.unfreeze_milestones = unfreeze_milestones
116         self.num_layers = num_layers
117 
118         super().__init__(attr_names, train_bn)
119 
120     def finetunning_function(
121         self,
122         pl_module: pl.LightningModule,
123         epoch: int,
124         optimizer: Optimizer,
125         opt_idx: int,
126     ) -> None:
127         backbone_modules = list(pl_module.backbone.modules())
128         if epoch == self.unfreeze_milestones[0]:
129             # unfreeze num_layers last layers
130             self.unfreeze_and_add_param_group(
131                 module=backbone_modules[-self.num_layers:],
132                 optimizer=optimizer,
133                 train_bn=self.train_bn,
134             )
135 
136         elif epoch == self.unfreeze_milestones[1]:
137             # unfreeze remaining layers
138             self.unfreeze_and_add_param_group(
139                 module=backbone_modules[:-self.num_layers],
140                 optimizer=optimizer,
141                 train_bn=self.train_bn,
142             )
143 
144 
145 _DEFAULTS_FINETUNE_STRATEGIES = {
146     "no_freeze": NoFreeze,
147     "freeze": Freeze,
148     "freeze_unfreeze": FreezeUnfreeze,
149     "unfreeze_milestones": UnfreezeMilestones
150 }
151 
152 
153 def instantiate_default_finetuning_callbacks(strategy):
154     if strategy is None or strategy not in _DEFAULTS_FINETUNE_STRATEGIES:
155         raise MisconfigurationException(
156             f"a strategy should be provided. Use {list(_DEFAULTS_FINETUNE_STRATEGIES)} or provide a callback"
157             " instance of `flash.core.finetuning.FlashBaseFinetuning`. Found {strategy} "
158         )
159     if isinstance(strategy, str):
160         strategy = strategy.lower()
161         if strategy in _DEFAULTS_FINETUNE_STRATEGIES:
162             return [_DEFAULTS_FINETUNE_STRATEGIES[strategy]()]
163     return []
164
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/flash/core/finetuning.py b/flash/core/finetuning.py
--- a/flash/core/finetuning.py
+++ b/flash/core/finetuning.py
@@ -25,7 +25,7 @@
     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:
         pass
 
-    def finetunning_function(
+    def finetune_function(
         self,
         pl_module: pl.LightningModule,
         epoch: int,
@@ -42,7 +42,7 @@
 
         FlashBaseFinetuning can be used to create a custom Flash Finetuning Callback.
 
-        Override ``finetunning_function`` to put your unfreeze logic.
+        Override ``finetune_function`` to put your unfreeze logic.
 
         Args:
             attr_names: Name(s) of the module attributes of the model to be frozen.
@@ -62,15 +62,15 @@
             attr = getattr(pl_module, attr_name, None)
             if attr is None or not isinstance(attr, nn.Module):
                 MisconfigurationException(f"Your model must have a {attr} attribute")
-            self.freeze(module=attr, train_bn=train_bn)
+            self.freeze(modules=attr, train_bn=train_bn)
 
-    def finetunning_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):
+    def finetune_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):
         pass
 
 
 class Freeze(FlashBaseFinetuning):
 
-    def finetunning_function(
+    def finetune_function(
         self,
         pl_module: pl.LightningModule,
         epoch: int,
@@ -86,7 +86,7 @@
         super().__init__(attr_names, train_bn)
         self.unfreeze_epoch = unfreeze_epoch
 
-    def finetunning_function(
+    def finetune_function(
         self,
         pl_module: pl.LightningModule,
         epoch: int,
@@ -117,7 +117,7 @@
 
         super().__init__(attr_names, train_bn)
 
-    def finetunning_function(
+    def finetune_function(
         self,
         pl_module: pl.LightningModule,
         epoch: int,
diff --git a/flash/vision/detection/finetuning.py b/flash/vision/detection/finetuning.py
--- a/flash/vision/detection/finetuning.py
+++ b/flash/vision/detection/finetuning.py
@@ -26,4 +26,4 @@
 
     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:
         model = pl_module.model
-        self.freeze(module=model.backbone, train_bn=self.train_bn)
+        self.freeze(modules=model.backbone, train_bn=self.train_bn)

{"golden_diff": "diff --git a/flash/core/finetuning.py b/flash/core/finetuning.py\n--- a/flash/core/finetuning.py\n+++ b/flash/core/finetuning.py\n@@ -25,7 +25,7 @@\n     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n         pass\n \n-    def finetunning_function(\n+    def finetune_function(\n         self,\n         pl_module: pl.LightningModule,\n         epoch: int,\n@@ -42,7 +42,7 @@\n \n         FlashBaseFinetuning can be used to create a custom Flash Finetuning Callback.\n \n-        Override ``finetunning_function`` to put your unfreeze logic.\n+        Override ``finetune_function`` to put your unfreeze logic.\n \n         Args:\n             attr_names: Name(s) of the module attributes of the model to be frozen.\n@@ -62,15 +62,15 @@\n             attr = getattr(pl_module, attr_name, None)\n             if attr is None or not isinstance(attr, nn.Module):\n                 MisconfigurationException(f\"Your model must have a {attr} attribute\")\n-            self.freeze(module=attr, train_bn=train_bn)\n+            self.freeze(modules=attr, train_bn=train_bn)\n \n-    def finetunning_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):\n+    def finetune_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):\n         pass\n \n \n class Freeze(FlashBaseFinetuning):\n \n-    def finetunning_function(\n+    def finetune_function(\n         self,\n         pl_module: pl.LightningModule,\n         epoch: int,\n@@ -86,7 +86,7 @@\n         super().__init__(attr_names, train_bn)\n         self.unfreeze_epoch = unfreeze_epoch\n \n-    def finetunning_function(\n+    def finetune_function(\n         self,\n         pl_module: pl.LightningModule,\n         epoch: int,\n@@ -117,7 +117,7 @@\n \n         super().__init__(attr_names, train_bn)\n \n-    def finetunning_function(\n+    def finetune_function(\n         self,\n         pl_module: pl.LightningModule,\n         epoch: int,\ndiff --git a/flash/vision/detection/finetuning.py b/flash/vision/detection/finetuning.py\n--- a/flash/vision/detection/finetuning.py\n+++ b/flash/vision/detection/finetuning.py\n@@ -26,4 +26,4 @@\n \n     def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n         model = pl_module.model\n-        self.freeze(module=model.backbone, train_bn=self.train_bn)\n+        self.freeze(modules=model.backbone, train_bn=self.train_bn)\n", "issue": "align with PR 1.2.0\n## \ud83d\ude80 Feature\r\n\r\nAtm, we have a hard link to 1.2.0rc0 which is a bit outdated...\r\nProbably some API adjust need to be done, continue in #62\r\n\r\n### Motivation\r\n\r\n<!-- Please outline the motivation for the proposal. Is your feature request related to a problem? e.g., I'm always frustrated when [...]. If this is related to another GitHub issue, please link here too -->\r\n\r\n### Pitch\r\n\r\n<!-- A clear and concise description of what you want to happen. -->\r\n\r\n### Alternatives\r\n\r\n<!-- A clear and concise description of any alternative solutions or features you've considered, if any. -->\r\n\r\n### Additional context\r\n\r\n<!-- Add any other context or screenshots about the feature request here. -->\r\n\n", "before_files": [{"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport pytorch_lightning as pl\n\nfrom flash.core.finetuning import FlashBaseFinetuning\n\n\nclass ObjectDetectionFineTuning(FlashBaseFinetuning):\n    \"\"\"\n    Freezes the backbone during Detector training.\n    \"\"\"\n\n    def __init__(self, train_bn: bool = True):\n        self.train_bn = train_bn\n\n    def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n        model = pl_module.model\n        self.freeze(module=model.backbone, train_bn=self.train_bn)\n", "path": "flash/vision/detection/finetuning.py"}, {"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nfrom typing import List, Union\n\nimport pytorch_lightning as pl\nfrom pytorch_lightning.callbacks import BaseFinetuning\nfrom pytorch_lightning.utilities.exceptions import MisconfigurationException\nfrom torch import nn\nfrom torch.optim import Optimizer\n\n\nclass NoFreeze(BaseFinetuning):\n\n    def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n        pass\n\n    def finetunning_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        pass\n\n\nclass FlashBaseFinetuning(BaseFinetuning):\n\n    def __init__(self, attr_names: Union[str, List[str]] = \"backbone\", train_bn: bool = True):\n        r\"\"\"\n\n        FlashBaseFinetuning can be used to create a custom Flash Finetuning Callback.\n\n        Override ``finetunning_function`` to put your unfreeze logic.\n\n        Args:\n            attr_names: Name(s) of the module attributes of the model to be frozen.\n\n            train_bn: Whether to train Batch Norm layer\n\n        \"\"\"\n\n        self.attr_names = [attr_names] if isinstance(attr_names, str) else attr_names\n        self.train_bn = train_bn\n\n    def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n        self.freeze_using_attr_names(pl_module, self.attr_names, train_bn=self.train_bn)\n\n    def freeze_using_attr_names(self, pl_module, attr_names: List[str], train_bn: bool = True):\n        for attr_name in attr_names:\n            attr = getattr(pl_module, attr_name, None)\n            if attr is None or not isinstance(attr, nn.Module):\n                MisconfigurationException(f\"Your model must have a {attr} attribute\")\n            self.freeze(module=attr, train_bn=train_bn)\n\n    def finetunning_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):\n        pass\n\n\nclass Freeze(FlashBaseFinetuning):\n\n    def finetunning_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        pass\n\n\nclass FreezeUnfreeze(FlashBaseFinetuning):\n\n    def __init__(self, attr_names: Union[str, List[str]] = \"backbone\", train_bn: bool = True, unfreeze_epoch: int = 10):\n        super().__init__(attr_names, train_bn)\n        self.unfreeze_epoch = unfreeze_epoch\n\n    def finetunning_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        if epoch != self.unfreeze_epoch:\n            return\n        modules = [getattr(pl_module, attr_name) for attr_name in self.attr_names]\n        self.unfreeze_and_add_param_group(\n            module=modules,\n            optimizer=optimizer,\n            train_bn=self.train_bn,\n        )\n\n\nclass UnfreezeMilestones(FlashBaseFinetuning):\n\n    def __init__(\n        self,\n        attr_names: Union[str, List[str]] = \"backbone\",\n        train_bn: bool = True,\n        unfreeze_milestones: tuple = (5, 10),\n        num_layers: int = 5\n    ):\n        self.unfreeze_milestones = unfreeze_milestones\n        self.num_layers = num_layers\n\n        super().__init__(attr_names, train_bn)\n\n    def finetunning_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        backbone_modules = list(pl_module.backbone.modules())\n        if epoch == self.unfreeze_milestones[0]:\n            # unfreeze num_layers last layers\n            self.unfreeze_and_add_param_group(\n                module=backbone_modules[-self.num_layers:],\n                optimizer=optimizer,\n                train_bn=self.train_bn,\n            )\n\n        elif epoch == self.unfreeze_milestones[1]:\n            # unfreeze remaining layers\n            self.unfreeze_and_add_param_group(\n                module=backbone_modules[:-self.num_layers],\n                optimizer=optimizer,\n                train_bn=self.train_bn,\n            )\n\n\n_DEFAULTS_FINETUNE_STRATEGIES = {\n    \"no_freeze\": NoFreeze,\n    \"freeze\": Freeze,\n    \"freeze_unfreeze\": FreezeUnfreeze,\n    \"unfreeze_milestones\": UnfreezeMilestones\n}\n\n\ndef instantiate_default_finetuning_callbacks(strategy):\n    if strategy is None or strategy not in _DEFAULTS_FINETUNE_STRATEGIES:\n        raise MisconfigurationException(\n            f\"a strategy should be provided. Use {list(_DEFAULTS_FINETUNE_STRATEGIES)} or provide a callback\"\n            \" instance of `flash.core.finetuning.FlashBaseFinetuning`. Found {strategy} \"\n        )\n    if isinstance(strategy, str):\n        strategy = strategy.lower()\n        if strategy in _DEFAULTS_FINETUNE_STRATEGIES:\n            return [_DEFAULTS_FINETUNE_STRATEGIES[strategy]()]\n    return []\n", "path": "flash/core/finetuning.py"}], "after_files": [{"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport pytorch_lightning as pl\n\nfrom flash.core.finetuning import FlashBaseFinetuning\n\n\nclass ObjectDetectionFineTuning(FlashBaseFinetuning):\n    \"\"\"\n    Freezes the backbone during Detector training.\n    \"\"\"\n\n    def __init__(self, train_bn: bool = True):\n        self.train_bn = train_bn\n\n    def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n        model = pl_module.model\n        self.freeze(modules=model.backbone, train_bn=self.train_bn)\n", "path": "flash/vision/detection/finetuning.py"}, {"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nfrom typing import List, Union\n\nimport pytorch_lightning as pl\nfrom pytorch_lightning.callbacks import BaseFinetuning\nfrom pytorch_lightning.utilities.exceptions import MisconfigurationException\nfrom torch import nn\nfrom torch.optim import Optimizer\n\n\nclass NoFreeze(BaseFinetuning):\n\n    def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n        pass\n\n    def finetune_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        pass\n\n\nclass FlashBaseFinetuning(BaseFinetuning):\n\n    def __init__(self, attr_names: Union[str, List[str]] = \"backbone\", train_bn: bool = True):\n        r\"\"\"\n\n        FlashBaseFinetuning can be used to create a custom Flash Finetuning Callback.\n\n        Override ``finetune_function`` to put your unfreeze logic.\n\n        Args:\n            attr_names: Name(s) of the module attributes of the model to be frozen.\n\n            train_bn: Whether to train Batch Norm layer\n\n        \"\"\"\n\n        self.attr_names = [attr_names] if isinstance(attr_names, str) else attr_names\n        self.train_bn = train_bn\n\n    def freeze_before_training(self, pl_module: pl.LightningModule) -> None:\n        self.freeze_using_attr_names(pl_module, self.attr_names, train_bn=self.train_bn)\n\n    def freeze_using_attr_names(self, pl_module, attr_names: List[str], train_bn: bool = True):\n        for attr_name in attr_names:\n            attr = getattr(pl_module, attr_name, None)\n            if attr is None or not isinstance(attr, nn.Module):\n                MisconfigurationException(f\"Your model must have a {attr} attribute\")\n            self.freeze(modules=attr, train_bn=train_bn)\n\n    def finetune_function(self, pl_module: pl.LightningModule, epoch: int, optimizer: Optimizer, opt_idx: int):\n        pass\n\n\nclass Freeze(FlashBaseFinetuning):\n\n    def finetune_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        pass\n\n\nclass FreezeUnfreeze(FlashBaseFinetuning):\n\n    def __init__(self, attr_names: Union[str, List[str]] = \"backbone\", train_bn: bool = True, unfreeze_epoch: int = 10):\n        super().__init__(attr_names, train_bn)\n        self.unfreeze_epoch = unfreeze_epoch\n\n    def finetune_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        if epoch != self.unfreeze_epoch:\n            return\n        modules = [getattr(pl_module, attr_name) for attr_name in self.attr_names]\n        self.unfreeze_and_add_param_group(\n            module=modules,\n            optimizer=optimizer,\n            train_bn=self.train_bn,\n        )\n\n\nclass UnfreezeMilestones(FlashBaseFinetuning):\n\n    def __init__(\n        self,\n        attr_names: Union[str, List[str]] = \"backbone\",\n        train_bn: bool = True,\n        unfreeze_milestones: tuple = (5, 10),\n        num_layers: int = 5\n    ):\n        self.unfreeze_milestones = unfreeze_milestones\n        self.num_layers = num_layers\n\n        super().__init__(attr_names, train_bn)\n\n    def finetune_function(\n        self,\n        pl_module: pl.LightningModule,\n        epoch: int,\n        optimizer: Optimizer,\n        opt_idx: int,\n    ) -> None:\n        backbone_modules = list(pl_module.backbone.modules())\n        if epoch == self.unfreeze_milestones[0]:\n            # unfreeze num_layers last layers\n            self.unfreeze_and_add_param_group(\n                module=backbone_modules[-self.num_layers:],\n                optimizer=optimizer,\n                train_bn=self.train_bn,\n            )\n\n        elif epoch == self.unfreeze_milestones[1]:\n            # unfreeze remaining layers\n            self.unfreeze_and_add_param_group(\n                module=backbone_modules[:-self.num_layers],\n                optimizer=optimizer,\n                train_bn=self.train_bn,\n            )\n\n\n_DEFAULTS_FINETUNE_STRATEGIES = {\n    \"no_freeze\": NoFreeze,\n    \"freeze\": Freeze,\n    \"freeze_unfreeze\": FreezeUnfreeze,\n    \"unfreeze_milestones\": UnfreezeMilestones\n}\n\n\ndef instantiate_default_finetuning_callbacks(strategy):\n    if strategy is None or strategy not in _DEFAULTS_FINETUNE_STRATEGIES:\n        raise MisconfigurationException(\n            f\"a strategy should be provided. Use {list(_DEFAULTS_FINETUNE_STRATEGIES)} or provide a callback\"\n            \" instance of `flash.core.finetuning.FlashBaseFinetuning`. Found {strategy} \"\n        )\n    if isinstance(strategy, str):\n        strategy = strategy.lower()\n        if strategy in _DEFAULTS_FINETUNE_STRATEGIES:\n            return [_DEFAULTS_FINETUNE_STRATEGIES[strategy]()]\n    return []\n", "path": "flash/core/finetuning.py"}]}