Skip to content

[model-gateway] multimodality initialization#13350

Merged
slin1237 merged 5 commits intomainfrom
smg-multimodal-1
Dec 3, 2025
Merged

[model-gateway] multimodality initialization#13350
slin1237 merged 5 commits intomainfrom
smg-multimodal-1

Conversation

@slin1237
Copy link
Collaborator

@github-actions github-actions bot added dependencies Pull requests that update a dependency file Multi-modal multi-modal language model model-gateway labels Nov 15, 2025
@gemini-code-assist
Copy link
Contributor

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 lays the groundwork for supporting multimodal models within the sgl-router. It introduces the necessary infrastructure to process and track various media types, particularly images, alongside text inputs. The changes enable the router to interact with Python-based HuggingFace processors for multimodal model inference, ensuring compatibility and extensibility for future multimodal model integrations.

Highlights

  • Multimodal Feature Integration: Introduced a new python-mm Cargo feature to enable multimodal capabilities within the sgl-router.
  • New Dependencies: Added several new Rust dependencies including pyo3 for Python interoperability, image for image processing, base64 for encoding/decoding, and serde_bytes for efficient byte serialization. Corresponding Python dependencies like pillow, transformers, torch, and numpy were also added.
  • Multimodal Core Modules: Implemented new Rust modules under sgl-router/src/multimodal to handle various aspects of multimodal processing, including error handling, media fetching, model registry, and input tracking.
  • Python Bridge for Model Processing: Created a Python shim (mm_processor_shim.py) and a Rust-Python bridge (python_bridge.rs) to leverage HuggingFace processors for multimodal input processing, mirroring vLLM's invocation.
  • Model-Specific Processing Logic: Developed a ModelRegistry and ModelProcessorSpec trait to define and manage model-specific logic for multimodal inputs, with initial support for Llava, Qwen-VL, and Phi-3-Vision models.
  • Multimodal Input Tracking: Implemented an AsyncMultiModalTracker to manage and process diverse multimodal content parts (text, image URLs, image data) within a conversation, including placeholder insertion and media fetching.
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
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 significant new functionality for multimodal support, which is a substantial and well-architected addition. The new modules for media handling, model-specific processing, and input tracking are logically structured. The use of a Python bridge to interface with HuggingFace processors is a practical choice, and the inclusion of parity tests against vLLM is commendable for ensuring compatibility. My review identifies a few areas for improvement, including a potential performance issue with blocking I/O, the use of deprecated APIs, and a type inconsistency, which I've detailed in the comments.

Comment on lines +62 to +82
pub fn new(client: Client, config: MediaConnectorConfig) -> Result<Self, MediaConnectorError> {
let allowed_domains = config.allowed_domains.map(|domains| {
domains
.into_iter()
.map(|d| d.to_ascii_lowercase())
.collect::<HashSet<_>>()
});

let allowed_local_media_path = if let Some(path) = config.allowed_local_media_path {
Some(std::fs::canonicalize(path)?)
} else {
None
};

Ok(Self {
client,
allowed_domains,
allowed_local_media_path,
fetch_timeout: config.fetch_timeout,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The use of std::fs::canonicalize within the new function is a blocking I/O operation. When this constructor is called from an asynchronous context, it can block the Tokio runtime's worker thread, leading to reduced throughput and potential performance bottlenecks. It is highly recommended to use the asynchronous equivalent, tokio::fs::canonicalize, and make the new function async. This will ensure that the application remains fully non-blocking. Note that this change will require updating the call sites of MediaConnector::new to await its result.

pub async fn new(client: Client, config: MediaConnectorConfig) -> Result<Self, MediaConnectorError> {
    let allowed_domains = config.allowed_domains.map(|domains| {
        domains
            .into_iter()
            .map(|d| d.to_ascii_lowercase())
            .collect::<HashSet<_>>()
    });

    let allowed_local_media_path = if let Some(path) = config.allowed_local_media_path {
        Some(tokio::fs::canonicalize(path).await?)
    } else {
        None
    };

    Ok(Self {
        client,
        allowed_domains,
        allowed_local_media_path,
        fetch_timeout: config.fetch_timeout,
    })
}

@slin1237 slin1237 changed the title [model-gateway] multimodality support WIP [model-gateway] multimodality initialization Dec 3, 2025
@slin1237 slin1237 merged commit d5ea8c7 into main Dec 3, 2025
51 of 55 checks passed
@slin1237 slin1237 deleted the smg-multimodal-1 branch December 3, 2025 03:41
yingluosanqian pushed a commit to yingluosanqian/sglang that referenced this pull request Dec 4, 2025
tonyluj pushed a commit to openanolis/sglang that referenced this pull request Dec 5, 2025
tonyluj pushed a commit to openanolis/sglang that referenced this pull request Dec 5, 2025
yuchengz816-bot pushed a commit to yuchengz816-bot/sglang that referenced this pull request Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file model-gateway Multi-modal multi-modal language model run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments