2025-12-30 21:55:32 +08:00
# Profiling vLLM-Omni
2025-12-12 01:52:53 -05:00
2026-04-10 18:13:12 +08:00
> **Warning:** Profiling is for development and debugging only. It adds significant overhead and should not be enabled in production.
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
vLLM-Omni supports two profiler backends through `profiler_config` :
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
- `torch` : detailed CPU/CUDA traces written to `torch_profiler_dir`
- `cuda` : low-overhead CUDA range control for NVIDIA Nsight Systems (`nsys` )
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
## 1. Configure Profiling
Use the same `profiler_config` shape everywhere:
```yaml
profiler_config :
profiler : torch
torch_profiler_dir : ./perf
```
Supported fields:
| Field | Description |
|---|---|
| `profiler` | Profiler backend. Supported values: `torch` , `cuda` . |
| `torch_profiler_dir` | Output directory for torch traces. Required when `profiler: torch` . |
| `delay_iterations` | Number of worker iterations to skip before profiling starts. |
| `max_iterations` | Maximum number of worker iterations to capture before auto-stop. |
| `warmup_iterations` | Torch-profiler warmup iterations. |
| `active_iterations` | Torch-profiler active iterations. |
| `wait_iterations` | Torch-profiler wait iterations before warmup. |
For multi-stage omni pipelines, put `profiler_config` under the target stage's `engine_args` .
2026-03-24 15:25:52 +08:00
```yaml
stage_args :
- stage_id : 0
stage_type : llm
engine_args :
profiler_config :
profiler : torch
torch_profiler_dir : ./perf
2026-01-06 08:58:00 +08:00
```
2026-04-10 18:13:12 +08:00
For single-stage diffusion usage, pass `profiler_config` directly to `Omni(...)` or `vllm serve` .
2026-03-24 15:25:52 +08:00
2026-04-10 18:13:12 +08:00
## 2. Profiling Omni Pipelines
2026-03-24 15:25:52 +08:00
2026-04-10 18:13:12 +08:00
It is usually best to profile only the stages you need.
2026-03-24 15:25:52 +08:00
2026-01-06 08:58:00 +08:00
```python
2026-04-10 18:13:12 +08:00
# Profile all stages.
omni . start_profile ()
2026-01-21 09:42:30 +08:00
2026-04-10 18:13:12 +08:00
# Profile selected stages only.
omni . start_profile ( stages = [ 0 , 2 ])
...
omni . stop_profile ( stages = [ 0 , 2 ])
2026-01-06 08:58:00 +08:00
```
2026-04-10 18:13:12 +08:00
Always stop the same stage set that you started. If only some stages have `profiler_config` , pass an explicit `stages=[...]` list instead of relying on the default "all stages" behavior.
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
Examples:
1. [Qwen2.5-Omni end2end ](https://github.com/vllm-project/vllm-omni/blob/main/examples/offline_inference/qwen2_5_omni/end2end.py )
2. [Qwen3-Omni end2end ](https://github.com/vllm-project/vllm-omni/blob/main/examples/offline_inference/qwen3_omni/end2end.py )
## 3. Profiling Single-Stage Diffusion
Single-stage diffusion models use the same `start_profile()` / `stop_profile()` controls, but you must provide `profiler_config` explicitly.
### PyTorch profiler
2026-01-21 09:42:30 +08:00
```python
2026-04-10 18:13:12 +08:00
from vllm_omni import Omni
2026-03-18 17:33:53 +08:00
2026-04-10 18:13:12 +08:00
omni = Omni (
model = "Wan-AI/Wan2.2-I2V-A14B-Diffusers" ,
profiler_config = {
"profiler" : "torch" ,
"torch_profiler_dir" : "./perf" ,
},
)
2026-01-21 09:42:30 +08:00
2026-04-10 18:13:12 +08:00
omni . start_profile ()
...
omni . stop_profile ()
2026-01-21 09:42:30 +08:00
```
2026-04-10 18:13:12 +08:00
### Nsight Systems (`nsys`)
For Nsight Systems, use `profiler: cuda` and wrap the process with `nsys profile` .
2026-01-21 09:42:30 +08:00
2026-03-24 15:25:52 +08:00
```bash
2026-04-10 18:13:12 +08:00
nsys profile \
--trace-fork-before-exec= true \
--cuda-graph-trace= node \
--capture-range= cudaProfilerApi \
--capture-range-end= repeat \
-o diffusion_trace \
python image_to_video.py ...
2026-03-24 15:25:52 +08:00
```
2026-04-10 18:13:12 +08:00
The Python process being profiled must create the diffusion engine with:
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
```python
profiler_config = { "profiler" : "cuda" }
2026-01-21 09:42:30 +08:00
```
2026-04-10 18:13:12 +08:00
Then call `start_profile()` before the requests you want to capture and `stop_profile()` after them. The diffusion worker processes open and close the CUDA capture range themselves, so `nsys` sees the actual GPU work instead of only the parent process.
2026-03-24 15:25:52 +08:00
2026-04-10 18:13:12 +08:00
Examples:
2026-01-21 09:42:30 +08:00
2026-04-10 18:13:12 +08:00
1. [Image edit example ](https://github.com/vllm-project/vllm-omni/blob/main/examples/offline_inference/image_to_image/image_edit.py )
2. [Image to video example ](https://github.com/vllm-project/vllm-omni/tree/main/examples/offline_inference/image_to_video )
2026-01-21 09:42:30 +08:00
2026-04-10 18:13:12 +08:00
## 4. Profiling Online Serving
2026-01-21 09:42:30 +08:00
2026-04-10 18:13:12 +08:00
When any stage has `profiler_config.profiler` set, the server exposes:
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
- `POST /start_profile`
- `POST /stop_profile`
### Start the server
Multi-stage omni serving:
2026-03-24 15:25:52 +08:00
```bash
vllm serve Qwen/Qwen2.5-Omni-7B \
2026-04-10 18:13:12 +08:00
--omni \
--port 8091
```
2026-04-19 10:36:00 +08:00
(The default deploy config at `vllm_omni/deploy/qwen2_5_omni.yaml` is loaded automatically. Pass `--deploy-config /path/to/custom.yaml` to override.)
2026-04-10 18:13:12 +08:00
Single-stage diffusion serving with torch profiler:
```bash
vllm serve Wan-AI/Wan2.2-I2V-A14B-Diffusers \
--omni \
--port 8091 \
2026-04-20 20:58:14 +08:00
--profiler-config '{
"profiler": "torch",
"torch_profiler_dir": "/tmp/vllm_profile_wan22_i2v",
"torch_profiler_with_stack": true,
"torch_profiler_with_flops": false,
"torch_profiler_use_gzip": true,
"torch_profiler_dump_cuda_time_total": true,
"torch_profiler_record_shapes": true,
"torch_profiler_with_memory": true,
"delay_iterations": 0,
"max_iterations": 0
}'
2026-04-10 18:13:12 +08:00
```
2026-04-20 20:58:14 +08:00
Useful optional fields:
- `torch_profiler_with_stack` : export `by_stack` operator views and stack text files.
- `torch_profiler_record_shapes` : export `by_shape` operator views.
- `torch_profiler_with_memory` : dump `memory_snapshot_rank*.pickle` when the backend supports memory history.
- `torch_profiler_use_gzip` : write the trace as `trace_rank*.json.gz` .
2026-04-10 18:13:12 +08:00
Single-stage diffusion serving with Nsight Systems:
```bash
nsys profile \
--trace-fork-before-exec= true \
--cuda-graph-trace= node \
--capture-range= cudaProfilerApi \
--capture-range-end= repeat \
-o serving_trace \
vllm serve Wan-AI/Wan2.2-I2V-A14B-Diffusers \
2026-03-24 15:25:52 +08:00
--omni \
2026-04-10 18:13:12 +08:00
--port 8091 \
--profiler-config '{"profiler": "cuda"}'
2026-03-24 15:25:52 +08:00
```
2026-04-10 18:13:12 +08:00
### Control capture
2026-03-24 15:25:52 +08:00
```bash
2026-04-10 18:13:12 +08:00
# Start profiling on all profiled stages.
2026-03-24 15:25:52 +08:00
curl -X POST http://localhost:8091/start_profile
2026-04-10 18:13:12 +08:00
# Start profiling on selected stages.
2026-03-24 15:25:52 +08:00
curl -X POST http://localhost:8091/start_profile \
2026-04-10 18:13:12 +08:00
-H "Content-Type: application/json" \
-d '{"stages": [0]}'
2026-03-24 15:25:52 +08:00
2026-04-10 18:13:12 +08:00
# Stop profiling.
2026-03-24 15:25:52 +08:00
curl -X POST http://localhost:8091/stop_profile
```
2026-04-10 18:13:12 +08:00
For mixed-stage pipelines, use explicit `stages` and pass the same stage list to both endpoints.
2026-03-24 15:25:52 +08:00
2026-04-10 18:13:12 +08:00
## 5. Analyze Results
2026-03-24 15:25:52 +08:00
2026-04-10 18:13:12 +08:00
Torch profiler output:
2026-03-24 15:25:52 +08:00
2026-04-20 20:58:14 +08:00
- Chrome/Perfetto trace: `trace_rank*.json` or `trace_rank*.json.gz`
- Excel workbook: `ops_rank*.xlsx` with `summary` , and optional `by_shape` / `by_stack` sheets
- Stack exports: `stacks_cpu_rank*.txt` and `stacks_cuda_rank*.txt` when stack capture is enabled
- Memory snapshot: `memory_snapshot_rank*.pickle` when memory capture is enabled and supported by the backend
- Optional aggregated CUDA-time tables under the same session directory
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
CUDA profiler / Nsight Systems output:
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
- `.nsys-rep` report files written by `nsys -o ...`
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
Recommended viewers:
2026-01-06 08:58:00 +08:00
2026-04-10 18:13:12 +08:00
- [Perfetto ](https://ui.perfetto.dev/ ) for torch traces
- `nsys stats <report>.nsys-rep` for CLI summaries
- Nsight Systems GUI for CUDA kernel timelines
vLLM-Omni reuses the vLLM profiling infrastructure where possible. For the upstream reference, see the [vLLM profiling guide ](https://docs.vllm.ai/en/stable/contributing/profiling/ ).