[MRV2][Multimodal] Enable encoder cuda graph for model runner v2 (#49852)

Signed-off-by: Isotr0py <Isotr0py@outlook.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Isotr0py
2026-08-14 09:33:21 +00:00
committed by GitHub
co-authored by OpenAI Codex
parent b8165e5e58
commit 66728feb1f
4 changed files with 101 additions and 26 deletions
+23 -1
View File
@@ -1,17 +1,22 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, cast
import torch
import torch.nn as nn
from vllm.config import VllmConfig
from vllm.config.compilation import CUDAGraphMode
from vllm.model_executor.models.interfaces import (
SupportsEncoderCudaGraph,
supports_encoder_cudagraph,
)
from vllm.tasks import GenerationTask
from vllm.v1.attention.backend import AttentionCGSupport
from vllm.v1.core.sched.output import NewRequestData
from vllm.v1.kv_cache_interface import KVCacheConfig
from vllm.v1.worker.encoder_cudagraph import EncoderCudaGraphManager
from vllm.v1.worker.gpu.input_batch import InputBatch
from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
from vllm.v1.worker.gpu.mm.encoder_runner import EncoderRunner
@@ -59,6 +64,22 @@ class ModelState(ABC):
self.supports_mm_inputs = encoder_cache is not None
if encoder_cache is not None:
enable_encoder_cuda_graph = (
not self.model_config.enforce_eager
and vllm_config.compilation_config.cudagraph_mm_encoder
and supports_encoder_cudagraph(model)
)
cudagraph_manager = (
EncoderCudaGraphManager(
vllm_config=vllm_config,
device=device,
dtype=self.dtype,
model=cast(SupportsEncoderCudaGraph, model),
)
if enable_encoder_cuda_graph
else None
)
self.encoder_cache = encoder_cache
observability_config = vllm_config.observability_config
self.encoder_runner = EncoderRunner(
@@ -68,6 +89,7 @@ class ModelState(ABC):
encoder_cache=encoder_cache,
dtype=self.dtype,
device=self.device,
cudagraph_manager=cudagraph_manager,
enable_timing=bool(
observability_config
and observability_config.enable_mm_processor_stats