From 9843ad35d1bc5dde6d7cdb0334515ce9bb603a7c Mon Sep 17 00:00:00 2001 From: Isaac Breen Date: Tue, 18 Mar 2025 12:27:56 +0800 Subject: [PATCH] Show both `peft_error` and `autoconfig_error`, not just `autoconfig_error` When loading a PEFT model fails, only the `autoconfig_error` is shown. Instead of the `peft_error`, which is what really matters when we're trying to load a PEFT adapter, the user will see something like this: ``` RuntimeError: Unrecognized model in my_model. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: albert, align, altclip, ... ``` This PR just changes it so `autoconfig_error` and `peft_error` are both displayed. --- unsloth/models/loader.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index 44475780a..ac92d637a 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -212,7 +212,13 @@ def from_pretrained( f'Try `pip install --upgrade "transformers>=4.43.2"`\n'\ f"to obtain the latest transformers build, then restart this session."\ ) - raise RuntimeError(autoconfig_error or peft_error) + # Create a combined error message showing both failures + combined_error = ( + "Unsloth: Failed to load model. Both AutoConfig and PeftConfig loading failed.\n\n" + f"AutoConfig error: {autoconfig_error}\n\n" + f"PeftConfig error: {peft_error}\n\n" + ) + raise RuntimeError(combined_error) pass # Get base model for PEFT: @@ -591,7 +597,13 @@ def from_pretrained( f'Try `pip install --upgrade "transformers>=4.43.2"`\n'\ f"to obtain the latest transformers build, then restart this session."\ ) - raise RuntimeError(autoconfig_error or peft_error) + # Create a combined error message showing both failures + combined_error = ( + "Unsloth: Failed to load model. Both AutoConfig and PeftConfig loading failed.\n\n" + f"AutoConfig error: {autoconfig_error}\n\n" + f"PeftConfig error: {peft_error}\n\n" + ) + raise RuntimeError(combined_error) pass # Get base model for PEFT: