diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 88a9e9661e..77509cd8da 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -95,11 +95,22 @@ def prepare_model_for_kbit_training( """ # Freeze all parameters except LoRA - for name, param in model.named_parameters(): - if ".lora_A." in name or ".lora_B." in name or ".lora_magnitude_vector" in name: - param.requires_grad_(True) - else: - param.requires_grad_(False) + import re + with torch.inference_mode(): + for name, param in model.named_parameters(): + if ".lora_A." in name or ".lora_B." in name or ".lora_magnitude_vector" in name: + param.requires_grad_(True) + # Also must be in float32! + if param.dtype != torch.float32: + name = name.replace("base_model", "model", 1) + layer_number = re.search(r"\.[\d]{1,}\.", name).group(0) + name = name.replace(layer_number, f"[{layer_number[1:-1]}].") + name = name.replace(".weight", "", 1) + exec(f"{name}.to(torch.float32)") + pass + else: + param.requires_grad_(False) + pass pass # Gradient checkpointing! diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index 0b8092eaac..202c692c4e 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -1030,7 +1030,7 @@ class FastLlamaModel: f' "-____-" Free Apache license: http://github.com/unslothai/unsloth' print(statistics) model_patcher.pre_patch() - get_statistics() + # get_statistics() if dtype is None: dtype = torch.float16 if not SUPPORTS_BFLOAT16 else torch.bfloat16 diff --git a/unsloth/models/mapper.py b/unsloth/models/mapper.py index f24108b75a..b1d2faedb3 100644 --- a/unsloth/models/mapper.py +++ b/unsloth/models/mapper.py @@ -122,10 +122,6 @@ __INT_TO_FLOAT_MAPPER = \ "unsloth/codegemma-7b", "google/codegemma-7b", ), - "unsloth/codegemma-2b-it-bnb-4bit" : ( - "unsloth/codegemma-2b-it", - "google/codegemma-2b-it", - ), "unsloth/codegemma-7b-it-bnb-4bit" : ( "unsloth/codegemma-7b-it", "google/codegemma-7b-it", diff --git a/unsloth/models/mistral.py b/unsloth/models/mistral.py index 87f5c85ad1..3034b83d2a 100644 --- a/unsloth/models/mistral.py +++ b/unsloth/models/mistral.py @@ -319,7 +319,7 @@ class FastMistralModel(FastLlamaModel): f' "-____-" Free Apache license: http://github.com/unslothai/unsloth' print(statistics) model_patcher.pre_patch() - get_statistics() + # get_statistics() if dtype is None: dtype = torch.float16 if not SUPPORTS_BFLOAT16 else torch.bfloat16