Skip to content

Conversation

krishung5
Copy link
Contributor

@krishung5 krishung5 commented May 27, 2025

Overview:

Details:

Where should the reviewer start?

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • closes GitHub issue: #xxx

Summary by CodeRabbit

  • New Features

    • Updated multimodal API to use a chat completion-style request format, supporting structured messages with mixed text and images.
    • Enhanced support for both streaming and non-streaming responses in multimodal chat interactions.
  • Bug Fixes

    • Improved error handling and validation for image URLs in requests.
  • Documentation

    • Revised README examples to reflect the new chat-based API format and updated sample responses.
  • Refactor

    • Reworked image loading to be asynchronous and more robust, with improved caching and error logging.
    • Simplified and streamlined response streaming logic for better reliability and maintainability.
    • Adjusted logging to omit image URLs for improved privacy.

Copy link

copy-pr-bot bot commented May 27, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions bot added the feat label May 27, 2025
@krishung5 krishung5 requested a review from nnshah1 May 27, 2025 19:53
@krishung5 krishung5 force-pushed the krish/multimodal/nixl branch from 5f30edf to f6e8f83 Compare May 27, 2025 23:43
@krishung5 krishung5 requested a review from nnshah1 May 28, 2025 01:27
Copy link
Collaborator

@whoisj whoisj 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
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The changes update multimodal example usage to a chat-completion style API with structured messages containing text and image URLs. Backend components now asynchronously load and cache images, extract data from nested message content, support both streaming and aggregated responses, and remove image URLs from logs for privacy.

Changes

File(s) Change Summary
examples/multimodal/README.md Updated client example requests and responses to chat-completion API format with structured messages and JSON output.
examples/multimodal/components/encode_worker.py Replaced synchronous image loading with async method; added async HTTP client; improved caching and error handling; updated method signatures.
examples/multimodal/components/decode_worker.py
examples/multimodal/components/prefill_worker.py
Removed image_url from log messages; changed some log levels; no logic changes.
examples/multimodal/components/frontend.py Added json import; changed API endpoint to /v1/chat/completions; parses JSON responses before yielding; sets streaming media type.
examples/multimodal/components/processor.py Extracts text and image URL from nested chat messages; enforces image presence; simplified streaming logic; renamed parameter.
examples/multimodal/utils/chat_processor.py Enhanced stream_response to support both streaming and aggregated non-streaming chat completions; aggregates content for non-stream mode.
examples/multimodal/utils/protocol.py Added Pydantic models for structured chat message content (text and image_url); replaced prompt/image/max_tokens with messages array; added optional stream flag.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Frontend
    participant Processor
    participant EncodeWorker
    participant DecodeWorker
    participant PrefillWorker

    Client->>Frontend: POST /v1/chat/completions (messages: [text, image_url])
    Frontend->>Processor: generate(raw_request)
    Processor->>Processor: Extract text & image_url from messages
    Processor->>EncodeWorker: encode(image_url)
    EncodeWorker->>EncodeWorker: Async load & cache image
    EncodeWorker-->>Processor: Encoded image features
    Processor->>PrefillWorker: prefill(text, image features)
    PrefillWorker-->>Processor: Prefilled data
    Processor->>DecodeWorker: generate(prefilled data)
    DecodeWorker-->>Processor: Generated response
    Processor-->>Frontend: Stream or aggregate response
    Frontend-->>Client: Return chat-completion response
Loading

Poem

In the warren of code, a new chat flows,
With images and words, as the API grows.
Async we fetch, and cache with care,
No more image URLs in logs to share.
Rabbits hop to structured delight—
Multimodal messages, working just right!
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2090bd3 and c9e1726.

📒 Files selected for processing (1)
  • examples/multimodal/components/frontend.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/multimodal/components/frontend.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
examples/multimodal/utils/chat_processor.py (1)

190-236: Excellent implementation of non-streaming aggregation.

The non-streaming response handling is well-implemented with proper:

  • Chunk collection and aggregation
  • JSON parsing with appropriate data prefix handling
  • Response structure initialization following OpenAI format
  • Content concatenation and finish_reason updates

The logic correctly handles the streaming chunks and builds a complete response object.

Consider adding error handling for edge cases:

+                try:
                     response = json.loads(raw_response.lstrip("data: "))
+                except json.JSONDecodeError:
+                    logger.warning(f"Failed to parse streaming response: {raw_response}")
+                    continue
examples/multimodal/README.md (2)

85-87: Add language specification to code block.

The response example should specify the language for better documentation quality and syntax highlighting.

-```
+```json
 {"id": "c37b946e-9e58-4d54-88c8-2dbd92c47b0c", "object": "chat.completion", "created": 1747725277, "model": "llava-hf/llava-1.5-7b-hf", "choices": [{"index": 0, "message": {"role": "assistant", "content": " In the image, there is a city bus parked on a street, with a street sign nearby on the right side. The bus appears to be stopped out of service. The setting is in a foggy city, giving it a slightly moody atmosphere."}, "finish_reason": "stop"}]}
-```
+```
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

85-85: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


152-154: Add language specification to code block.

Same issue as the previous response example - should specify JSON for proper syntax highlighting.

-```
+```json
 {"id": "c1774d61-3299-4aa3-bea1-a0af6c055ba8", "object": "chat.completion", "created": 1747725645, "model": "llava-hf/llava-1.5-7b-hf", "choices": [{"index": 0, "message": {"role": "assistant", "content": " This image shows a passenger bus traveling down the road near power lines and trees. The bus displays a sign that says \"OUT OF SERVICE\" on its front."}, "finish_reason": "stop"}]}
-```
+```
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

152-152: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b1e089 and 2090bd3.

📒 Files selected for processing (8)
  • examples/multimodal/README.md (2 hunks)
  • examples/multimodal/components/decode_worker.py (5 hunks)
  • examples/multimodal/components/encode_worker.py (3 hunks)
  • examples/multimodal/components/frontend.py (2 hunks)
  • examples/multimodal/components/prefill_worker.py (1 hunks)
  • examples/multimodal/components/processor.py (2 hunks)
  • examples/multimodal/utils/chat_processor.py (1 hunks)
  • examples/multimodal/utils/protocol.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
examples/multimodal/components/processor.py (4)
examples/multimodal/components/frontend.py (1)
  • generate (42-48)
examples/multimodal/components/decode_worker.py (1)
  • generate (197-336)
examples/multimodal/utils/protocol.py (1)
  • MultiModalRequest (117-122)
examples/llm/components/processor.py (2)
  • _generate (189-218)
  • RequestType (41-43)
🪛 markdownlint-cli2 (0.17.2)
examples/multimodal/README.md

85-85: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


152-152: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (24)
examples/multimodal/components/prefill_worker.py (1)

194-195: LGTM: Privacy improvement in logging.

Removing the image_url from the log message is a good privacy practice that reduces potential exposure of sensitive image URLs in logs while maintaining essential debugging information (request_id and engine_id).

examples/multimodal/components/decode_worker.py (6)

200-200: LGTM: Consistent privacy improvement.

Removing image_url from the log message improves privacy by not exposing potentially sensitive image URLs in logs.


204-207: LGTM: Privacy improvement in debug logging.

Consistent removal of image_url from debug log messages maintains essential debugging information while protecting sensitive data.


225-226: LGTM: Privacy improvement in remote prefill logging.

Good practice to remove image_url from logs while retaining key debugging information like request ID and prompt length.


238-239: LGTM: Privacy improvement in local prefill logging.

Consistent removal of image_url maintains debugging capability while improving privacy.


261-263: LGTM: Privacy improvement in aggregated mode logging.

Removing image_url from aggregated mode logs is consistent with the privacy improvements across the codebase.


296-298: LGTM: Appropriate log level and privacy improvement.

Changing from info to debug level is appropriate for detailed execution flow information, and removing image_url improves privacy consistency.

examples/multimodal/components/frontend.py (3)

16-16: LGTM: Required import for JSON processing.

Adding the json import is necessary for the response parsing functionality added below.


41-41: LGTM: OpenAI-compatible endpoint naming.

Using "v1/chat/completions" aligns with OpenAI's API specification for chat completion endpoints.


48-48: LGTM: Proper streaming response configuration.

Using StreamingResponse with "text/event-stream" media type is appropriate for server-sent events format commonly used in chat completion APIs.

examples/multimodal/utils/chat_processor.py (1)

177-189: LGTM: Clean streaming response handling.

The streaming response logic preserves the existing behavior and properly delegates to the OpenAI serving layer.

examples/multimodal/README.md (2)

58-82: LGTM! Clean API format update.

The updated curl example properly demonstrates the new chat completion style API with structured messages containing mixed text and image content. This aligns well with the OpenAI format standard.


125-149: LGTM! Consistent API format for disaggregated serving.

The disaggregated serving example properly mirrors the aggregated serving format with the same structured message API.

examples/multimodal/components/processor.py (3)

151-151: LGTM! Simplified streaming response handling.

The direct yielding of responses is cleaner than manual aggregation and properly delegates streaming logic to the underlying components.


204-212: Good error handling for image URL extraction.

The iteration through messages and content items to find the image URL is well-implemented, and the ValueError for missing image URLs provides clear feedback.


213-214: LGTM! Clean integration with the updated API.

The call to _generate with the extracted image URL and the JSON serialization of responses properly implements the new chat completion format.

examples/multimodal/utils/protocol.py (3)

95-109: Excellent structured content design.

The TextContent and ImageContent models with Literal types provide strong type safety and align perfectly with the OpenAI chat completion format. The union type MessageContent enables flexible mixed content.


112-115: Good role-based message structure.

The ChatMessage model properly encapsulates the role and content list, supporting the multi-modal conversation format expected by the processor.


117-123: Well-designed request model refactor.

The updated MultiModalRequest with messages field, optional max_tokens, and stream flag properly supports the new chat completion API while maintaining backward compatibility through sensible defaults.

examples/multimodal/components/encode_worker.py (5)

16-23: Good async-focused imports.

The addition of asyncio, base64, binascii, and httpx properly supports the async image loading functionality. The urlparse import enables proper URL handling for different schemes.


77-79: Proper async HTTP client setup.

The optional HTTP client initialization and timeout configuration provide good foundation for async operations.


80-148: Excellent async image loading implementation.

This is a well-designed async image loading method with several strengths:

  1. Multi-format support: Handles both HTTP(S) URLs and data URLs
  2. Proper caching: LRU cache with size limits and eviction
  3. Robust validation: Checks image formats and converts to RGB
  4. Thread safety: Uses asyncio.to_thread for PIL operations
  5. Comprehensive error handling: Covers HTTP errors, validation errors, and decoding issues

The implementation properly handles the async nature while maintaining image processing quality.


165-208: Good error handling and logging practices.

The try-catch block in the encode method provides proper error propagation while maintaining detailed logging. The privacy-conscious logging (omitting image URLs) is appropriate for production environments.


209-218: Proper async initialization.

Moving HTTP client initialization to async_init ensures proper async context and resource management.

@krishung5 krishung5 merged commit 5a30923 into main May 28, 2025
8 checks passed
@krishung5 krishung5 deleted the krish/multimodal/nixl branch May 28, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants