-
-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add check for zero3 * freeze parameters * fixes for deepspeed loading * fix model parameter check * unfrozen parameters in example mixtral and logging when unfreezing
- Loading branch information
Showing
7 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"zero_optimization": { | ||
"stage": 3, | ||
"overlap_comm": true, | ||
"contiguous_gradients": true, | ||
"sub_group_size": 0, | ||
"reduce_bucket_size": "auto", | ||
"stage3_prefetch_bucket_size": "auto", | ||
"stage3_param_persistence_threshold": "auto", | ||
"stage3_max_live_parameters": 0, | ||
"stage3_max_reuse_distance": 0, | ||
"stage3_gather_16bit_weights_on_model_save": true | ||
}, | ||
"bf16": { | ||
"enabled": true | ||
}, | ||
"fp16": { | ||
"enabled": "auto", | ||
"auto_cast": false, | ||
"loss_scale": 0, | ||
"initial_scale_power": 32, | ||
"loss_scale_window": 1000, | ||
"hysteresis": 2, | ||
"min_loss_scale": 1 | ||
}, | ||
"optimizer": { | ||
"type": "AdamW", | ||
"params": { | ||
"lr": "auto", | ||
"betas": "auto", | ||
"eps": "auto", | ||
"weight_decay": "auto" | ||
} | ||
}, | ||
"gradient_accumulation_steps": "auto", | ||
"train_batch_size": "auto", | ||
"train_micro_batch_size_per_gpu": "auto", | ||
"wall_clock_breakdown": false | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
module to freeze/unfreeze parameters by name | ||
""" | ||
import logging | ||
import re | ||
|
||
from axolotl.utils.distributed import is_main_process | ||
|
||
LOG = logging.getLogger("axolotl.utils.freeze") | ||
|
||
|
||
def freeze_parameters_except(model, regex_patterns): | ||
""" | ||
Freezes all layers of the given model except for the layers that match given regex patterns. | ||
Periods in the patterns are treated as literal periods, not as wildcard characters. | ||
Parameters: | ||
- model (nn.Module): The PyTorch model to be modified. | ||
- regex_patterns (list of str): List of regex patterns to match layer names to keep unfrozen. | ||
Returns: | ||
None; the model is modified in place. | ||
""" | ||
# Escape periods and compile the regex patterns | ||
compiled_patterns = [ | ||
re.compile(pattern.replace(".", "\\.")) for pattern in regex_patterns | ||
] | ||
|
||
# First, freeze all parameters in the model | ||
for param in model.parameters(): | ||
param.requires_grad = False | ||
|
||
# Unfreeze layers that match the regex patterns | ||
for name, param in model.named_parameters(): | ||
if any(pattern.match(name) for pattern in compiled_patterns): | ||
if is_main_process(): | ||
LOG.debug(f"unfreezing {name}") | ||
param.requires_grad = True |
This file contains 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
This file contains 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