Skip to content

Conversation

@mmathew23
Copy link
Collaborator

Most models types have logic to load the model directly from a peft_config (only saved lora adapters and tokenizer). Deepseek OCR since it requires trust_remote_code=True fails in AutoConfig.from_pretrained since trust_remote_code isn't passed (unsloth_zoo.hf_utils). This depends on unslothai/unsloth-zoo#386, which creates a trust_remote_code kwarg. Once accepted this PR can successfully pass trust_remote_code=True when specified by user.

Additionally, a common failure mode is missing package, but that error get swallowed up. This will explicitly raise if an ImportError happens.

This notebook: https://colab.research.google.com/drive/1rQcpPJzFpTId-7KGSvU2zDIg2-emUJTd?usp=sharing
shows regular deepseek ocr works with new code.

Thie notebook: https://colab.research.google.com/drive/1bADSkRQuLQ7VkAV1XlCOH_38nqPhMPye?usp=sharing
shows that direct loading of a save lora_model now works with new code.

check for import error in autoconfig/peftconfig from_pretrained error

handle import
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mmathew23, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue preventing the proper loading of Deepseek OCR LoRA models by ensuring that the trust_remote_code parameter is correctly handled during model configuration. Additionally, it improves the robustness of the model loading process by explicitly re-raising ImportError exceptions, which will help users quickly identify and resolve missing package dependencies.

Highlights

  • Deepseek OCR LoRA Model Loading: Implemented a fix to correctly load Deepseek OCR LoRA models by ensuring trust_remote_code=True is passed to AutoConfig.from_pretrained and related functions, addressing an issue where this parameter was previously not propagated.
  • Improved Error Handling: Enhanced error handling by explicitly catching and re-raising ImportError exceptions during model and PEFT configuration loading. This prevents critical missing package errors from being swallowed by generic exception blocks, providing clearer diagnostics.
  • Dependency on unsloth-zoo: This PR depends on a change in unsloth-zoo (pull/386) which introduces the trust_remote_code keyword argument, enabling the successful passing of this parameter when specified by the user.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mmathew23 mmathew23 changed the title Fix deepseek Ocr Lora Model Load Fix Deepseek OCR Lora Model Load Dec 18, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the model loading failure for Deepseek OCR by correctly propagating the trust_remote_code parameter. The addition of explicit ImportError handling is also a valuable improvement, preventing these errors from being swallowed and providing clearer feedback to the user.

My review includes suggestions to simplify the new except blocks by removing redundant code, which will improve readability and maintainability. Overall, the changes are solid and well-implemented.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 336 to 339
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,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard new trust_remote_code kwarg with matching unsloth_zoo version

The new call to get_transformers_model_type now forwards trust_remote_code, but the imported helper comes from unsloth_zoo.compiler and the repo still requires unsloth_zoo>=2025.12.5 without bumping to a release that accepts that keyword. With the currently published helper (no trust_remote_code parameter), this line will raise TypeError: get_transformers_model_type() got an unexpected keyword argument 'trust_remote_code' before any model can load, even when trust_remote_code is left at its default. Please gate this call on a dependency bump or add a compatibility fallback.

Useful? React with 👍 / 👎.

danielhanchen and others added 4 commits December 18, 2025 04:07
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@danielhanchen danielhanchen merged commit 27185eb into unslothai:main Dec 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants