Skip to content

[misc] Add support for 20+ new model architectures to HuggingFace mod…#128

Merged
slin1237 merged 1 commit into
mainfrom
slin/new-models
Jul 4, 2025
Merged

[misc] Add support for 20+ new model architectures to HuggingFace mod…#128
slin1237 merged 1 commit into
mainfrom
slin/new-models

Conversation

@slin1237
Copy link
Copy Markdown
Collaborator

@slin1237 slin1237 commented Jul 4, 2025

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:

  • Language Models: Gemma/Gemma2, StableLM, MiniCPM, ChatGLM/GLM-4, InternLM, Baichuan, XVERSE, ExaONE, Command-R, DBRX
  • Multimodal Models: Qwen2-VL, DeepSeek-VL2, Janus, LLaVA
  • Embedding Models: BERT-based models (BGE, E5), decoder-based embeddings (E5-Mistral, GTE-Qwen2)
  • Architecture Support: Proper handling of MoE models, multimodal configurations, and various parameter counting strategies

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:

  1. Parameter Counting: Each model uses safetensors for accurate parameter counting with appropriate fallbacks. Pay special attention to the MoE
    models (DBRX, DeepSeek-VL) which have specialized counting logic.
  2. Multimodal Support: The multi_modality model type was added specifically for Janus models. DeepSeek-VL models override GetArchitecture() to
    handle missing architecture fields.
  3. Type Handling: MiniCPM's rope_scaling field uses interface{} type to handle both float and object values from different model versions.
  4. Test Coverage: All new models have comprehensive test files with real configuration samples in the testdata directory.
  5. Documentation: Added a single consolidated documentation page covering all supported models without framework-specific references.

Does this PR introduce a user-facing change?

Add support for 20+ new model architectures in the HuggingFace model configuration parser:

  • Language models: Gemma/Gemma2, StableLM, MiniCPM, ChatGLM/GLM-4, InternLM, Baichuan, XVERSE, ExaONE, Command-R, DBRX
  • Multimodal models: Qwen2-VL, DeepSeek-VL2, Janus, LLaVA
  • Embedding models: BGE series, E5 series, E5-Mistral, GTE-Qwen2
  • Improved model auto-detection and parameter counting for MoE and multimodal architectures

Copy link
Copy Markdown
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.

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_modality model type for Janus models and custom GetArchitecture() 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 testdata directory, ensuring the reliability and accuracy of the parsing logic.
  • Updated Documentation: The README.md has 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

  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
Copy Markdown
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 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.Printf for warnings.
  • Configuration Validation: Adopting the explicit Validate() method pattern from gemma.go across all new model configurations.
  • Documentation: A minor clarification in the README.md to 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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?

Comment on lines +39 to +52
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
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

@slin1237 slin1237 merged commit 43ff6b0 into main Jul 4, 2025
23 checks passed
@zhyncs zhyncs deleted the slin/new-models branch July 4, 2025 02:45
slin1237 added a commit that referenced this pull request Dec 22, 2025
#128)

[misc] Add support for 20+ new model architectures to HuggingFace model config parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant