Files
vllm-omni/docs/user_guide/examples/online_serving/qwen2_5_omni.md
T

7.6 KiB

Qwen2.5-Omni: Online serving

Source https://github.com/vllm-project/vllm-omni/tree/main/examples/online_serving/qwen2_5_omni.

🛠️ Installation

Please refer to README.md

Run examples (Qwen2.5-Omni)

Launch the Server

vllm serve Qwen/Qwen2.5-Omni-7B --omni --port 8091

To use a custom deploy config, launch the server with the command below:

vllm serve Qwen/Qwen2.5-Omni-7B --omni --port 8091 --deploy-config /path/to/deploy_config.yaml

Send Multi-modal Request

Get into the example folder

cd examples/online_serving/qwen2_5_omni

Send request via python

python openai_chat_completion_client_for_multimodal_generation.py --query-type mixed_modalities --port 8091 --host "localhost"

The Python client supports the following command-line arguments:

  • --query-type (or -q): Query type (default: mixed_modalities). Options: mixed_modalities, use_audio_in_video, multi_audios, text
  • --video-path (or -v): Path to local video file or URL. If not provided and query-type uses video, uses default video URL. Supports local file paths (automatically encoded to base64) or HTTP/HTTPS URLs. Example: --video-path /path/to/video.mp4 or --video-path https://example.com/video.mp4
  • --image-path (or -i): Path to local image file or URL. If not provided and query-type uses image, uses default image URL. Supports local file paths (automatically encoded to base64) or HTTP/HTTPS URLs and common image formats: JPEG, PNG, GIF, WebP. Example: --image-path /path/to/image.jpg or --image-path https://example.com/image.png
  • --audio-path (or -a): Path to local audio file or URL. If not provided and query-type uses audio, uses default audio URL. Supports local file paths (automatically encoded to base64) or HTTP/HTTPS URLs and common audio formats: MP3, WAV, OGG, FLAC, M4A. Example: --audio-path /path/to/audio.wav or --audio-path https://example.com/audio.mp3
  • --prompt (or -p): Custom text prompt/question. If not provided, uses default prompt for the selected query type. Example: --prompt "What are the main activities shown in this video?"

For example, to use mixed modalities with all local files:

python openai_chat_completion_client_for_multimodal_generation.py \
    --query-type mixed_modalities \
    --video-path /path/to/your/video.mp4 \
    --image-path /path/to/your/image.jpg \
    --audio-path /path/to/your/audio.wav \
    --prompt "Analyze all the media content and provide a comprehensive summary."

Send request via curl

bash run_curl_multimodal_generation.sh mixed_modalities

Modality control

You can control output modalities to specify which types of output the model should generate. This is useful when you only need text output and want to skip audio generation stages for better performance.

Supported modalities

Modalities Output
["text"] Text only
["audio"] Text + Audio
["text", "audio"] Text + Audio
Not specified Text + Audio (default)

Using curl

Text only

curl http://localhost:8091/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen2.5-Omni-7B",
    "messages": [{"role": "user", "content": "Describe vLLM in brief."}],
    "modalities": ["text"]
  }'

Text + Audio

curl http://localhost:8091/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen2.5-Omni-7B",
    "messages": [{"role": "user", "content": "Describe vLLM in brief."}],
    "modalities": ["audio"]
  }'

Using Python client

python openai_chat_completion_client_for_multimodal_generation.py \
    --query-type mixed_modalities \
    --modalities text

Using OpenAI Python SDK

Text only

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8091/v1", api_key="EMPTY")

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-Omni-7B",
    messages=[{"role": "user", "content": "Describe vLLM in brief."}],
    modalities=["text"]
)
print(response.choices[0].message.content)

Text + Audio

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8091/v1", api_key="EMPTY")

response = client.chat.completions.create(
    model="Qwen/Qwen2.5-Omni-7B",
    messages=[{"role": "user", "content": "Describe vLLM in brief."}],
    modalities=["audio"]
)
# Response contains two choices: one with text, one with audio
print(response.choices[0].message.content)  # Text response
print(response.choices[1].message.audio)    # Audio response

Streaming Output

If you want to enable streaming output, please set the argument as below. The final output will be obtained just after generated by corresponding stage. Now we only support text streaming output. Other modalities can output normally.

python openai_chat_completion_client_for_multimodal_generation.py \
    --query-type mixed_modalities \
    --stream

Run Local Web UI Demo

!!! note "Gradio is an optional dependency" The Gradio demo requires the [demo] extras. Install them first:

```bash
pip install 'vllm-omni[demo]'
```

Or, if installing from source: `pip install -e '.[demo]'`

This Web UI demo allows users to interact with the model through a web browser.

Running Gradio Demo

The Gradio demo connects to a vLLM API server. You have two options:

The convenience script launches both the vLLM server and Gradio demo together:

./run_gradio_demo.sh --model Qwen/Qwen2.5-Omni-7B --server-port 8091 --gradio-port 7861

This script will:

  1. Start the vLLM server in the background
  2. Wait for the server to be ready
  3. Launch the Gradio demo
  4. Handle cleanup when you press Ctrl+C

The script supports the following arguments:

  • --model: Model name/path (default: Qwen/Qwen2.5-Omni-7B)
  • --server-port: Port for vLLM server (default: 8091)
  • --gradio-port: Port for Gradio demo (default: 7861)
  • --deploy-config: Path to a custom deploy config YAML file (optional)
  • --server-host: Host for vLLM server (default: 0.0.0.0)
  • --gradio-ip: IP for Gradio demo (default: 127.0.0.1)
  • --share: Share Gradio demo publicly (creates a public link)

Option 2: Manual Launch (Two-Step Process)

Step 1: Launch the vLLM API server

vllm serve Qwen/Qwen2.5-Omni-7B --omni --port 8091

To use a custom deploy config:

vllm serve Qwen/Qwen2.5-Omni-7B --omni --port 8091 --deploy-config /path/to/deploy_config.yaml

Step 2: Run the Gradio demo

In a separate terminal:

python gradio_demo.py --model Qwen/Qwen2.5-Omni-7B --api-base http://localhost:8091/v1 --port 7861

Then open http://localhost:7861/ on your local browser to interact with the web UI.

The gradio script supports the following arguments:

  • --model: Model name/path (should match the server model)
  • --api-base: Base URL for the vLLM API server (default: http://localhost:8091/v1)
  • --ip: Host/IP for Gradio server (default: 127.0.0.1)
  • --port: Port for Gradio server (default: 7861)
  • --share: Share the Gradio demo publicly (creates a public link)

Example materials

??? abstract "gradio_demo.py" py --8<-- "examples/online_serving/qwen2_5_omni/gradio_demo.py" ??? abstract "run_curl_multimodal_generation.sh" sh --8<-- "examples/online_serving/qwen2_5_omni/run_curl_multimodal_generation.sh" ??? abstract "run_gradio_demo.sh" sh --8<-- "examples/online_serving/qwen2_5_omni/run_gradio_demo.sh"