Skip to content

Conversation

@zhooooong
Copy link
Contributor

Motivation

I tried this way to import external custom model:

def import_new_model_classes():
    model_arch_name_to_cls = {"MyModel": MyModel}
    return model_arch_name_to_cls

ModelRegistry.models.update(import_new_model_classes())
llm = sgl.Engine(model_path="path_to_model")

Unfortunately, the scheduler process cannot retrieve the registration information from the original process, so I added some environment variables to fix the problem.

Modifications

Three new environment variables:

  • SGLANG_EXTERNAL_MODEL_PACKAGE: the package name of the external model
  • SGLANG_EXTERNAL_MM_MODEL_ARCH: used for multimodal model
  • SGLANG_EXTERNAL_MM_PROCESSOR_PACKAGE: processor's package name for multimodal model

Accuracy Tests

Benchmarking and Profiling

Checklist

@github-actions github-actions bot added the Multi-modal multi-modal language model label Nov 17, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zhooooong, 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 enhances the SGLang framework by enabling the seamless integration of external custom models. It addresses a critical limitation where custom model registrations were not correctly propagated across processes, particularly to the scheduler. By introducing dedicated environment variables and modifying the model and processor registration mechanisms, users can now easily define and load their own models and multimodal processors, expanding the framework's extensibility and adaptability to diverse model architectures.

Highlights

  • External Model Support: Introduces a mechanism to load and utilize custom, externally defined models within the SGLang framework.
  • Environment Variable Configuration: Implements three new environment variables (SGLANG_EXTERNAL_MODEL_PACKAGE, SGLANG_EXTERNAL_MM_MODEL_ARCH, SGLANG_EXTERNAL_MM_PROCESSOR_PACKAGE) to configure external model and processor packages.
  • Multimodal Processor Overriding: Allows external multimodal processors to override default ones, providing flexibility for custom multimodal model integration.
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.

@zhooooong zhooooong force-pushed the zhong/support_external_custom_models branch from 768094d to 5473e68 Compare November 17, 2025 12:16
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 introduces a robust mechanism for integrating external custom models and multimodal processors into the SGLang framework. By leveraging new environment variables (SGLANG_EXTERNAL_MODEL_PACKAGE, SGLANG_EXTERNAL_MM_MODEL_ARCH, SGLANG_EXTERNAL_MM_PROCESSOR_PACKAGE), users can now dynamically register their custom implementations. The import_processors and ModelRegistry.register functions have been enhanced with an overwrite flag, ensuring that external definitions can seamlessly replace or extend existing ones. The accompanying unit tests (test/srt/external_models/custom_qwen2_vl.py and test/srt/test_external_models.py) effectively demonstrate the end-to-end functionality, confirming that the custom models and processors are correctly loaded and utilized. This is a well-designed and valuable addition for extending the framework's capabilities.

@zhooooong zhooooong changed the title support external custom models Support external custom models Nov 17, 2025
Copy link
Collaborator

@zhaochenyang20 zhaochenyang20 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@zhaochenyang20 zhaochenyang20 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhaochenyang20
Copy link
Collaborator

@Kangyan-Zhou kangyan could you help to merge?

@mickqian mickqian merged commit 48ca9f7 into sgl-project:main Nov 20, 2025
90 of 105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Multi-modal multi-modal language model run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants