Skip to content

feat: enhance Auto Class to support remote and local path#5

Merged
Tohrusky merged 26 commits intoEutropicAI:mainfrom
TohruskyDev:main
Sep 26, 2025
Merged

feat: enhance Auto Class to support remote and local path#5
Tohrusky merged 26 commits intoEutropicAI:mainfrom
TohruskyDev:main

Conversation

@Tohrusky
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Tohrusky, 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 introduces a major feature enhancement to the Auto classes, allowing users to load and utilize models from external sources such as remote Git repositories or local file system paths. This change significantly broadens the accessibility and integration capabilities of the model loading system, moving beyond pre-registered models to support a more dynamic and user-defined model ecosystem. The update includes robust handling for cloning and managing external model repositories, alongside clearer error reporting for registry operations.

Highlights

  • Enhanced Model Loading Flexibility: The AutoConfig and AutoModel classes have been significantly enhanced to support loading model configurations and models directly from remote Git repositories (via URL) or local file paths, in addition to previously registered names. This greatly improves the flexibility for users to integrate custom or external models.
  • New Git Cloning Utility: A new utility function, git_clone, has been introduced in cccv.util.remote to handle the cloning and updating of Git repositories. This function supports specifying branches and commit hashes, and intelligently updates existing local clones.
  • Refactored Configuration Handling: The internal logic for AutoConfig.from_pretrained has been rewritten to intelligently determine if the input is a registered name, a remote URL, or a local path. It now dynamically loads configurations from config.json files within cloned repositories or local directories, and imports associated Python files to register architectures and models.
  • Improved Registry Error Handling: The Registry class now raises KeyError exceptions instead of printing warnings when attempting to register an object with a name that already exists or when trying to retrieve a non-existent object. This provides clearer error feedback.
  • Documentation and Examples Updated: The README.md has been updated with new sections and code examples demonstrating how to load custom models from remote repositories and local paths using the enhanced AutoModel.from_pretrained method. A new example file example/remote.py was also added.
  • Cache Directory Management: The model caching mechanism has been centralized and improved, with cccv/cache_models/__init__.py being renamed to cccv/util/remote.py. It now includes get_cache_dir to manage the default cache location, which can be overridden via an environment variable.
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.

Copy link

@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 introduces a significant enhancement, allowing models to be loaded from remote git repositories or local file paths. The implementation involves refactoring model caching and remote file handling into a new cccv.util.remote module and updating the AutoConfig and AutoModel classes. The registration process for custom models has also been clarified by removing the register methods from Auto* classes in favor of direct registry usage. My review focuses on improving security, robustness, and developer experience by suggesting better warning mechanisms, documenting security implications and external dependencies, and making the git URL parsing more resilient.

@Tohrusky
Copy link
Member Author

/gemini review

@Tohrusky Tohrusky requested a review from Copilot September 26, 2025 19:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the Auto Class to support loading models from remote repositories and local paths, in addition to the existing registered model names. The key changes include refactoring model loading logic, improving error handling with proper warnings, and updating import statements.

  • Adds support for remote git repository URLs and local directory paths in AutoModel.from_pretrained()
  • Refactors cache/remote functionality from cccv.cache_models to cccv.util.remote with enhanced git cloning capabilities
  • Updates error handling to use warnings.warn() instead of print() statements throughout the codebase

Reviewed Changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cccv/auto/config.py Implements new logic to handle remote URLs, local paths, and registered config names
cccv/auto/model.py Updates from_pretrained() to use new config loading and removes registration methods
cccv/util/remote.py New module containing relocated and enhanced remote file/git functionality
cccv/cache_models/__init__.py Removed - functionality moved to cccv.util.remote
example/remote.py New example demonstrating remote model loading
Various test files Updated import paths and added remote model testing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@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 introduces a significant enhancement by enabling AutoModel and AutoConfig to load models from remote git repositories and local paths. This greatly improves the flexibility of the library. The refactoring to centralize registration logic within the registries is a commendable design choice, and the move from print statements to warnings.warn for non-critical issues is a positive step towards better logging practices.

However, there are some critical issues in the error handling logic, where exit() and os._exit() are used instead of raising exceptions. This can lead to silent failures or abrupt termination of the application. Additionally, the registry's behavior for duplicate registrations has become too strict, potentially hindering the new dynamic loading feature. I've also suggested adding a security warning to the docstring for the new loading mechanism.

@Tohrusky
Copy link
Member Author

/gemini review

Copy link

@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 introduces a powerful new feature, allowing AutoModel and AutoConfig to load models from remote git repositories and local paths, in addition to pre-registered names. The implementation is robust, handling git cloning, dynamic module registration, and configuration parsing. I'm also very impressed with the numerous code quality improvements throughout the repository, such as replacing print/exit calls with proper exceptions and warnings, which significantly enhances the library's reliability and usability. The changes are well-tested and documented. I have a few suggestions to further improve consistency and documentation.

Comment on lines 63 to +64
elif True:
print(strVariable, type(objValue))
print(f"[CCCV] {strVariable}, {type(objValue)}")

Choose a reason for hiding this comment

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

high

This elif True: acts as a catch-all that simply prints information about unhandled types. This can hide bugs or unsupported cases. It would be more robust to raise an exception for unexpected types to ensure the program fails fast and provides a clear error.

Suggested change
elif True:
print(strVariable, type(objValue))
print(f"[CCCV] {strVariable}, {type(objValue)}")
else:
raise TypeError(f"Unsupported type for cuda_kernel variable '{strVariable}': {type(objValue)}")

Comment on lines 108 to +112
elif isinstance(objValue, torch.Tensor):
print(strVariable, objValue.dtype)
print(f"[CCCV] {strVariable}, {objValue.dtype}")

elif True:
print(strVariable, type(objValue))
print(f"[CCCV] {strVariable}, {type(objValue)}")

Choose a reason for hiding this comment

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

high

Similar to the previous comment, these elif blocks handle unexpected tensor dtypes and other types by printing to the console. This can mask errors. It's better to raise a TypeError to explicitly signal that an unsupported type was passed to the function.

Suggested change
elif isinstance(objValue, torch.Tensor):
print(strVariable, objValue.dtype)
print(f"[CCCV] {strVariable}, {objValue.dtype}")
elif True:
print(strVariable, type(objValue))
print(f"[CCCV] {strVariable}, {type(objValue)}")
elif isinstance(objValue, torch.Tensor):
raise TypeError(f"Unsupported tensor dtype for cuda_kernel variable '{strVariable}': {objValue.dtype}")
else:
raise TypeError(f"Unsupported type for cuda_kernel variable '{strVariable}': {type(objValue)}")

Comment on lines 20 to 26
"""
Get a config instance of a pretrained model configuration.
Get a config instance of a pretrained model configuration, can be a registered config name or a local path or a git url.

:param pretrained_model_name: The name of the pretrained model configuration
:param pretrained_model_name_or_path:
:param model_dir: The path to cache the downloaded model configuration. Should be a full path. If None, use default cache path.
:return:
"""

Choose a reason for hiding this comment

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

medium

The new functionality to load from a path or URL is great! To help users adopt it, it would be very beneficial to expand this docstring to describe the expected directory structure. For example:

  • The path should point to a directory.
  • The directory must contain a config.json file.
  • config.json must have name, arch, and model keys.
  • Any custom Python code (e.g., for architectures or models) should be in .py files in that directory to be auto-registered.
  • The model weights file path is determined by the path key in config.json. If path is omitted, it defaults to a file in the same directory with a name matching the name key.

Comment on lines +32 to +40
def get_cache_dir(model_dir: Optional[Union[Path, str]] = None) -> Path:
if model_dir is None or str(model_dir) == "":
model_dir = str(CCCV_CACHE_MODEL_DIR)
print(
f"[CCCV] Using default cache model path {model_dir}, override it by setting environment variable CCCV_CACHE_MODEL_DIR"
)
if not os.path.exists(model_dir):
os.makedirs(model_dir)
return Path(model_dir)

Choose a reason for hiding this comment

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

medium

This file uses print() for informational messages (e.g., here on line 35, and also on lines 81, 96, 97, 141, 151). In a library, it's a best practice to use the logging module instead of print(). This gives the users of your library control over the verbosity and output stream. It would be great to refactor these print() calls to use logging.info() or logging.debug().

@Tohrusky Tohrusky merged commit 1ad50b0 into EutropicAI:main Sep 26, 2025
5 of 18 checks 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.

1 participant

Comments