diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index 3d969d7d3..022be109f 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -1868,7 +1868,25 @@ def patch_peft_model( internal_model.max_seq_length = max_seq_length internal_model = internal_model.model pass - internal_model.max_seq_length = max_seq_length + internal_model.max_seq_length = max_seq_length + + # Patch tokenizer to pad to the right + internal_model = model + while hasattr(internal_model, "model"): + if hasattr(internal_model, "_saved_temp_tokenizer"): + internal_model._saved_temp_tokenizer.padding_side = "right" + pass + internal_model = internal_model.model + pass + if hasattr(internal_model, "_saved_temp_tokenizer"): + internal_model._saved_temp_tokenizer.padding_side = "right" + pass + + # Clear deleted GPU items + for _ in range(3): + gc.collect() + torch.cuda.empty_cache() + pass return model pass diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index d7c0f0760..d87af0a18 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -113,7 +113,8 @@ def from_pretrained( elif not is_model and not is_peft: raise RuntimeError( f"Unsloth: `{model_name}` is not a base model or a PEFT model.\n"\ - "We could not locate a `config.json` or `adapter_config.json` file" + "We could not locate a `config.json` or `adapter_config.json` file.\n"\ + "Are you certain the model name is correct? Does it actually exist?" ) pass