[misc] Add support for 20+ new model architectures to HuggingFace mod…#128
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @slin1237, 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 significantly expands the capabilities of the HuggingFace model configuration parser by integrating support for over 20 new model architectures. This enhancement allows the system to automatically detect, parse, and analyze configurations for a much broader spectrum of state-of-the-art language, multimodal, and embedding models, improving overall model compatibility and information extraction.
Highlights
- Expanded Model Support: I've significantly expanded the HuggingFace model configuration parser to support over 20 new model architectures, including various Language Models (e.g., Gemma, ChatGLM, DBRX), Multimodal Models (e.g., Qwen2-VL, LLaVA), and Embedding Models (e.g., BERT-based, E5).
- Enhanced Parameter Counting: The parameter counting logic has been improved to accurately handle new architectures, including specialized counting for Mixture-of-Experts (MoE) models like DBRX and DeepSeek-VL, with robust fallbacks to safetensors parsing.
- Multimodal Configuration Handling: Specific support for multimodal configurations has been added, including a new
multi_modalitymodel type for Janus models and customGetArchitecture()overrides for DeepSeek-VL to ensure correct architecture identification. - Comprehensive Test Coverage: All newly added model configurations come with comprehensive test files, utilizing real configuration samples stored in the
testdatadirectory, ensuring the reliability and accuracy of the parsing logic. - Updated Documentation: The
README.mdhas been updated to provide a consolidated and categorized overview of all supported models, improving clarity and ease of reference for users.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This is an impressive and substantial contribution, adding support for a wide range of new model architectures. The code is well-structured, following a consistent pattern with the RegisterModelLoader for discoverability, and the fallback logic in GetParameterCount is robust. The addition of comprehensive test cases for each new model is particularly commendable.
My review focuses on a few areas for improvement to enhance maintainability and consistency across the new files:
- Logging: Using a structured logger instead of
fmt.Printffor warnings. - Configuration Validation: Adopting the explicit
Validate()method pattern fromgemma.goacross all new model configurations. - Documentation: A minor clarification in the
README.mdto ensure it accurately reflects the supported models in this PR.
Great work on this significant expansion of capabilities!
| ### Multimodal Models | ||
| - **Qwen2-VL**: Vision-language models | ||
| - **Phi-3 Vision**: Multimodal Phi models | ||
| - **MLlama**: Multimodal Llama models (Llama 3.2 Vision) |
There was a problem hiding this comment.
The documentation lists MLlama as a supported multimodal model, but there doesn't appear to be a corresponding mllama.go implementation or loader registered in this pull request. This might confuse users about the currently supported models. Could you please clarify if this is intended for a future PR and should be removed for now, or if it's handled by another existing model configuration?
| func LoadBaichuanConfig(configPath string) (*BaichuanConfig, error) { | ||
| data, err := os.ReadFile(configPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read Baichuan config file '%s': %w", configPath, err) | ||
| } | ||
|
|
||
| var config BaichuanConfig | ||
| if err := json.Unmarshal(data, &config); err != nil { | ||
| return nil, fmt.Errorf("failed to parse Baichuan config JSON from '%s': %w", configPath, err) | ||
| } | ||
|
|
||
| config.ConfigPath = configPath | ||
| return &config, nil | ||
| } |
There was a problem hiding this comment.
The gemma.go implementation includes a Validate() method on the config struct, which is called after unmarshalling. This is an excellent pattern for ensuring the loaded configuration is sane before it's used.
Consider adding a similar Validate() method here and in the other new model configurations to check for required positive values (like HiddenSize, NumHiddenLayers, etc.). This would improve robustness and consistency across the codebase.
| } | ||
|
|
||
| // Log the error | ||
| fmt.Printf("Warning: failed to get parameter count from safetensors: %v\n", err) |
There was a problem hiding this comment.
Using fmt.Printf for logging warnings can be problematic in a library, as it writes directly to standard output and isn't configurable (e.g., to change level, format, or destination). It's better to use a proper logging mechanism. The standard log package would be an improvement (log.Printf(...)), or an injected logger interface for more flexibility.
This comment applies to all newly added model files that use fmt.Printf for logging errors or warnings.
#128) [misc] Add support for 20+ new model architectures to HuggingFace model config parser
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR significantly expands the HuggingFace model configuration parser to support 20+ new model architectures from the SGLang documentation. The
changes enable OME to automatically detect and parse configurations for a much wider range of models, including state-of-the-art language models,
multimodal models, and embedding models.
Key additions:
Each model implementation follows the established patterns with comprehensive test coverage and proper parameter counting logic.
Which issue(s) this PR fixes:
Fixes #[issue_number]
Special notes for your reviewer:
models (DBRX, DeepSeek-VL) which have specialized counting logic.
handle missing architecture fields.
Does this PR introduce a user-facing change?
Add support for 20+ new model architectures in the HuggingFace model configuration parser: