Skip to content

[Data][LLM] Add multimodal support to SGLang engine path - #67543

Closed
vijit-vishnoi wants to merge 2 commits into
ray-project:masterfrom
vijit-vishnoi:sglang-multimodal
Closed

vijit-vishnoi wants to merge 2 commits into
ray-project:masterfrom
vijit-vishnoi:sglang-multimodal

Conversation

@vijit-vishnoi

Copy link
Copy Markdown

Description

Currently, the SGLangEngineProcessorConfig in ray.data.llm silently degrades to text-only when passed rows containing media columns (images, video, audio).

This PR adds full multimodal support to the SGLang engine path, ensuring a batch job mixing text and media can be run on either the vLLM or SGLang engine using the exact same column conventions and expected output schema.

Related issues

Fixes #66928

Additional information

Implementation Details:

  1. Wired PrepareMultimodalStage into the SGLang processor builder to ensure pipeline preprocessing parity with vLLM.
  2. Prevented memory leaks by popping large media payloads (multimodal_data, image_data, etc.) from the row in _prepare_llm_request.
  3. Enforced fail-closed validation: the engine now explicitly raises a ValueError for unsupported modalities or conflicting media inputs rather than silently ignoring them.
  4. Aligned SGLangOutputData with vLLMOutputData (added embeddings, logprobs, prompt_logprobs, and metrics).

Testing:

  • Added 7 new test cases in test_sglang_engine_stage.py verifying fail-closed logic, media popping, schema alignment, and kwarg forwarding.
  • Added a test case in test_sglang_engine_proc.py for pipeline stage ordering.
  • Verified locally that all processor and stage logic tests pass cleanly.

(Note: AI assistance was utilized during the development and testing of this patch).

@vijit-vishnoi
vijit-vishnoi requested a review from a team as a code owner October 29, 2026 15:35

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces multimodal support (images, audio, and video) to the SGLang engine processor by adding a new preprocessing stage, updating request and output schemas, and forwarding media arguments to the underlying engine. It also adds comprehensive unit tests to validate input extraction, error handling, and schema alignment. The review feedback highlights two valuable improvement opportunities: simplifying a redundant conditional dictionary retrieval for embeddings, and unconditionally popping all potential media keys from the input row to prevent memory leaks when alternative media columns are present.

generated_text=output["text"] if "text" in output else None,
num_generated_tokens=output["meta_info"]["completion_tokens"],
num_generated_tokens=meta_info["completion_tokens"],
embeddings=output.get("embedding", None) if "embedding" in output else None,

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 conditional expression output.get("embedding", None) if "embedding" in output else None is redundant. Since dict.get() already returns None (or a specified default) if the key is missing, this can be simplified to a direct .get() call.

Suggested change
embeddings=output.get("embedding", None) if "embedding" in output else None,
embeddings=output.get("embedding"),

Comment on lines +198 to +210
direct_image = row.pop("image_data", None)
if direct_image is None:
direct_image = row.pop("image", None)
if direct_image is None:
direct_image = row.pop("images", None)

direct_audio = row.pop("audio_data", None)
if direct_audio is None:
direct_audio = row.pop("audio", None)

direct_video = row.pop("video_data", None)
if direct_video is None:
direct_video = row.pop("video", None)

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

To prevent memory leaks and ensure large media payloads do not linger in the dataset, all potential media columns should be unconditionally popped from the row. In the current implementation, if image_data is present and not None, the image and images keys are never popped, which could leave large media blobs in the row.

        image_data_val = row.pop("image_data", None)
        image_val = row.pop("image", None)
        images_val = row.pop("images", None)
        direct_image = image_data_val if image_data_val is not None else (image_val if image_val is not None else images_val)

        audio_data_val = row.pop("audio_data", None)
        audio_val = row.pop("audio", None)
        direct_audio = audio_data_val if audio_data_val is not None else audio_val

        video_data_val = row.pop("video_data", None)
        video_val = row.pop("video", None)
        direct_video = video_data_val if video_data_val is not None else video_val

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8a64692. Configure here.

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 13, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data][LLM][SGLang] Multimodal support for the SGLang engine

1 participant