From 45189934a263ff8d57ebe1dab2694157b0acfd6f Mon Sep 17 00:00:00 2001 From: DoubleMathew Date: Wed, 17 Dec 2025 18:04:29 -0600 Subject: [PATCH 1/5] fix deepseek ocr lora_model load: trust_remote_code option check for import error in autoconfig/peftconfig from_pretrained error handle import --- unsloth/models/loader.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index bfa94d86d7..afed58592f 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -289,6 +289,10 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_model = True + except ImportError as error: + autoconfig_error = str(error) + is_model = False + raise error except Exception as error: autoconfig_error = str(error) if "architecture" in autoconfig_error: @@ -305,6 +309,10 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_peft = True + except ImportError as error: + peft_error = str(error) + is_peft = False + raise error except Exception as error: peft_error = str(error) if "architecture" in peft_error: @@ -326,7 +334,8 @@ def from_pretrained( "Please separate the LoRA and base models to 2 repos." ) model_types = get_transformers_model_type( - peft_config if peft_config is not None else model_config + peft_config if peft_config is not None else model_config, + trust_remote_code = trust_remote_code, ) if len(model_types) == 1: model_type = model_types[0] @@ -826,6 +835,10 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_model = True + except ImportError as error: + autoconfig_error = str(error) + is_model = False + raise error except Exception as error: autoconfig_error = str(error) if "architecture" in autoconfig_error: @@ -842,6 +855,10 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_peft = True + except ImportError as error: + peft_error = str(error) + is_peft = False + raise error except Exception as error: peft_error = str(error) if "architecture" in peft_error: @@ -861,7 +878,8 @@ def from_pretrained( "Please separate the LoRA and base models to 2 repos." ) model_types = get_transformers_model_type( - peft_config if peft_config is not None else model_config + peft_config if peft_config is not None else model_config, + trust_remote_code = trust_remote_code, ) model_types_all = ",".join(model_types) + "," From cbac62ee26512dca9f8d91d69afd4357d7e5b98b Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 18 Dec 2025 04:07:52 -0800 Subject: [PATCH 2/5] Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unsloth/models/loader.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index afed58592f..d27bb3f3e8 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -289,10 +289,8 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_model = True - except ImportError as error: - autoconfig_error = str(error) - is_model = False - raise error + except ImportError: + raise except Exception as error: autoconfig_error = str(error) if "architecture" in autoconfig_error: From ba551aafc3d8d222127c08aed2532e646bcd32d7 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 18 Dec 2025 04:08:13 -0800 Subject: [PATCH 3/5] Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unsloth/models/loader.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index d27bb3f3e8..bea47eb1af 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -307,10 +307,8 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_peft = True - except ImportError as error: - peft_error = str(error) - is_peft = False - raise error + except ImportError: + raise except Exception as error: peft_error = str(error) if "architecture" in peft_error: From 17e3616c2013d51e727315bd1933d6112deb6f49 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 18 Dec 2025 04:08:28 -0800 Subject: [PATCH 4/5] Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unsloth/models/loader.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index bea47eb1af..8fdf090a09 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -831,10 +831,8 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_model = True - except ImportError as error: - autoconfig_error = str(error) - is_model = False - raise error + except ImportError: + raise except Exception as error: autoconfig_error = str(error) if "architecture" in autoconfig_error: From 5d4b852a66d7114042dffc3a780acaef1556abfb Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 18 Dec 2025 04:08:46 -0800 Subject: [PATCH 5/5] Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unsloth/models/loader.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index 8fdf090a09..6148b1783e 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -849,10 +849,8 @@ def from_pretrained( trust_remote_code = trust_remote_code, ) is_peft = True - except ImportError as error: - peft_error = str(error) - is_peft = False - raise error + except ImportError: + raise except Exception as error: peft_error = str(error) if "architecture" in peft_error: