From ac0835d49fee1b807fd44cdc3f48aa0531c475fd Mon Sep 17 00:00:00 2001 From: DoubleMathew Date: Thu, 18 Dec 2025 06:09:17 -0600 Subject: [PATCH] Fix Deepseek OCR Lora Model Load (#3738) * fix deepseek ocr lora_model load: trust_remote_code option check for import error in autoconfig/peftconfig from_pretrained error handle import * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Daniel Han Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unsloth/models/loader.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index bfa94d86d7..6148b1783e 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -289,6 +289,8 @@ class FastLanguageModel(FastLlamaModel): trust_remote_code = trust_remote_code, ) is_model = True + except ImportError: + raise except Exception as error: autoconfig_error = str(error) if "architecture" in autoconfig_error: @@ -305,6 +307,8 @@ class FastLanguageModel(FastLlamaModel): trust_remote_code = trust_remote_code, ) is_peft = True + except ImportError: + raise except Exception as error: peft_error = str(error) if "architecture" in peft_error: @@ -326,7 +330,8 @@ class FastLanguageModel(FastLlamaModel): "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 +831,8 @@ class FastModel(FastBaseModel): trust_remote_code = trust_remote_code, ) is_model = True + except ImportError: + raise except Exception as error: autoconfig_error = str(error) if "architecture" in autoconfig_error: @@ -842,6 +849,8 @@ class FastModel(FastBaseModel): trust_remote_code = trust_remote_code, ) is_peft = True + except ImportError: + raise except Exception as error: peft_error = str(error) if "architecture" in peft_error: @@ -861,7 +870,8 @@ class FastModel(FastBaseModel): "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) + ","