Skip to content

Conversation

@avinashsingh77
Copy link

@avinashsingh77 avinashsingh77 commented Nov 11, 2025

This PR adds support for providing model_url to modctl modelfile generate
Tests added, run output:

go test ./pkg/hfhub -v
=== RUN   TestParseModelURL
=== RUN   TestParseModelURL/full_URL
=== RUN   TestParseModelURL/full_URL_with_trailing_slash
=== RUN   TestParseModelURL/short_form
=== RUN   TestParseModelURL/http_URL
=== RUN   TestParseModelURL/invalid_format_-_missing_repo
=== RUN   TestParseModelURL/invalid_format_-_only_owner
=== RUN   TestParseModelURL/empty_URL
=== RUN   TestParseModelURL/URL_with_spaces_(trimmed)
--- PASS: TestParseModelURL (0.00s)
    --- PASS: TestParseModelURL/full_URL (0.00s)
    --- PASS: TestParseModelURL/full_URL_with_trailing_slash (0.00s)
    --- PASS: TestParseModelURL/short_form (0.00s)
    --- PASS: TestParseModelURL/http_URL (0.00s)
    --- PASS: TestParseModelURL/invalid_format_-_missing_repo (0.00s)
    --- PASS: TestParseModelURL/invalid_format_-_only_owner (0.00s)
    --- PASS: TestParseModelURL/empty_URL (0.00s)
    --- PASS: TestParseModelURL/URL_with_spaces_(trimmed) (0.00s)
PASS
ok      github.com/modelpack/modctl/pkg/hfhub   (cached)

Closes #308

@gemini-code-assist
Copy link

Summary of Changes

Hello @avinashsingh77, 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 significant new capability to the modctl tool, allowing users to generate modelfiles directly from models hosted on Hugging Face Hub. By providing a --model_url flag to the modctl modelfile generate command, users can now specify a Hugging Face model, which the tool will automatically download and then use to create the modelfile. This integration simplifies the workflow for developers leveraging Hugging Face models, making it easier to manage and deploy them within the modctl ecosystem.

Highlights

  • Hugging Face Model URL Support: The modctl modelfile generate command now supports generating modelfiles directly from Hugging Face model URLs, using a new --model_url flag.
  • Flexible Input: Users can provide either a local directory path or a Hugging Face model URL (e.g., "owner/repo" or full "https://huggingface.co/owner/repo" format).
  • Hugging Face Integration: A new pkg/hfhub package has been introduced to handle parsing Hugging Face URLs, checking user authentication, and downloading models using the huggingface-cli tool.
  • Command Line Enhancements: The generate command's usage, short description, long description, and examples have been updated to reflect the new functionality, and argument validation now accommodates the optional path when --model_url is used.
  • Robust URL Parsing: Comprehensive unit tests have been added for the ParseModelURL function, ensuring correct handling of various URL formats and edge cases.
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 valuable feature for generating a modelfile directly from a Hugging Face model URL. The implementation is well-structured, primarily by leveraging the huggingface-cli tool. My review focuses on enhancing user experience, ensuring proper resource management, and improving code clarity. I've suggested making the <path> argument and the --model_url flag mutually exclusive to prevent user confusion, adding cleanup for temporary directories, refining output handling within the hfhub package, and simplifying test logic for better maintainability.

Copy link
Member

@chlins chlins left a comment

Choose a reason for hiding this comment

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

Can we abstract a generic interface for the download part, and then support different drivers or vendors? Because in addition to Hugging Face, there are also model hubs like ModelScope.

@avinashsingh77
Copy link
Author

avinashsingh77 commented Nov 19, 2025 via email

@avinashsingh77
Copy link
Author

@chlins Implemented a provider interface and added providers for HuggingFace and ModelScope as suggested. Does it look okay now?

@avinashsingh77 avinashsingh77 changed the title Add support for modelFile generate via HF model_url Add support for modelFile generate via model providers model_url Nov 24, 2025
@chlins
Copy link
Member

chlins commented Nov 25, 2025

@chlins Implemented a provider interface and added providers for HuggingFace and ModelScope as suggested. Does it look okay now?

@avinashsingh77 Great work! thanks for adding the provider interface with HuggingFace and ModelScope implementations. I'll take a look at the changes in a bit and share my thoughts.

flags.StringVarP(&generateConfig.Output, "output", "O", ".", "specify the output path of modelfilem, must be a directory")
flags.BoolVar(&generateConfig.IgnoreUnrecognizedFileTypes, "ignore-unrecognized-file-types", false, "ignore the unrecognized file types in the workspace")
flags.BoolVar(&generateConfig.Overwrite, "overwrite", false, "overwrite the existing modelfile")
flags.StringVar(&generateConfig.ModelURL, "model_url", "", "download model from a supported provider (HuggingFace: owner/repo or full URL, ModelScope: full URL)")
Copy link
Member

Choose a reason for hiding this comment

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

The flag name should align with other flags naming style, suggest to use model-url.


// SupportsURL checks if this provider can handle the given model URL
// This enables automatic provider detection based on URL patterns
SupportsURL(url string) bool
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to use explicit statement for this part, such as by scheme provided by user, which is more simple and clear, e.g --model-url hf://meta-llama/Llama-3.3-70B-Instruct

}

// NewRegistry creates a new provider registry with all available providers
func NewRegistry() *Registry {
Copy link
Member

Choose a reason for hiding this comment

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

Actually, this registry can be a global singleton.


// Create a temporary directory for downloading the model
// Clean up the temporary directory after the function returns
tmpDir, err := os.MkdirTemp("", "modctl-model-downloads-*")
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to consider expose this temp dir to user? because in some limited environment, user may only have write access to specific dirs.

}

// downloadFile downloads a single file from HuggingFace
func downloadFile(ctx context.Context, owner, repo, filename, destPath string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Where is this method used?

}

// downloadFile downloads a single file from ModelScope
func downloadFile(ctx context.Context, owner, repo, filename, destPath string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Where is this method used?

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.

Support converting from huggingface URL

2 participants