Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Model] Dynamic image size support for LLaVA-NeXT #5279

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply input processor
  • Loading branch information
DarkLight1337 committed Jun 3, 2024
commit 653537d99f43c211e69958e7ad536f23aaf5087b
8 changes: 5 additions & 3 deletions vllm/engine/async_llm_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ async def process_model_inputs_async(
else:
prompt_token_ids = inputs["prompt_token_ids"]

return LLMInputs(prompt_token_ids=prompt_token_ids,
prompt=inputs.get("prompt"),
multi_modal_data=inputs.get("multi_modal_data"))
llm_inputs = LLMInputs(prompt_token_ids=prompt_token_ids,
prompt=inputs.get("prompt"),
multi_modal_data=inputs.get("multi_modal_data"))

return self.input_processor(llm_inputs)

async def add_request_async(
self,
Expand Down
13 changes: 9 additions & 4 deletions vllm/engine/llm_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from vllm.engine.output_processor.util import create_output_by_sequence_group
from vllm.executor.executor_base import ExecutorBase
from vllm.executor.ray_utils import initialize_ray_cluster
from vllm.inputs import LLMInputs, PromptInputs
from vllm.inputs import INPUT_REGISTRY, LLMInputs, PromptInputs
from vllm.logger import init_logger
from vllm.lora.request import LoRARequest
from vllm.outputs import (EmbeddingRequestOutput, RequestOutput,
Expand Down Expand Up @@ -219,6 +219,9 @@ def __init__(
self.generation_config_fields = _load_generation_config_dict(
model_config)

self.input_processor = INPUT_REGISTRY.create_input_processor(
self.model_config)

self.model_executor = executor_class(
model_config=model_config,
cache_config=cache_config,
Expand Down Expand Up @@ -484,9 +487,11 @@ def process_model_inputs(
else:
prompt_token_ids = inputs["prompt_token_ids"]

return LLMInputs(prompt_token_ids=prompt_token_ids,
prompt=inputs.get("prompt"),
multi_modal_data=inputs.get("multi_modal_data"))
llm_inputs = LLMInputs(prompt_token_ids=prompt_token_ids,
prompt=inputs.get("prompt"),
multi_modal_data=inputs.get("multi_modal_data"))

return self.input_processor(llm_inputs)

def add_request(
self,
Expand Down
23 changes: 15 additions & 8 deletions vllm/inputs/registry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import functools
from typing import (TYPE_CHECKING, Callable, Dict, Optional, Tuple, Type,
TypeVar)
from typing_extensions import Concatenate, ParamSpec

from torch import nn
from transformers import PretrainedConfig
from typing_extensions import Concatenate, ParamSpec

from vllm.logger import init_logger

Expand Down Expand Up @@ -31,6 +32,7 @@


def _for_hf(hf_config_type: Type[C]):

def wrapper(
fn: Callable[Concatenate[C, P], R],
) -> Callable[Concatenate["ModelConfig", P], R]:
Expand All @@ -54,6 +56,7 @@ def inner(


def _for_multimodal_hf(hf_config_type: Type[C]):

def wrapper(
factory: Callable[Concatenate["VisionLanguageConfig", C, P], R],
) -> Callable[Concatenate["ModelConfig", P], R]:
Expand Down Expand Up @@ -138,8 +141,8 @@ def for_hf(cls, hf_config_type: Type[C]):
"""

def wrapper(
processor: Callable[[C, LLMInputs], LLMInputs],
) -> InputProcessor:
processor: Callable[[C, LLMInputs],
LLMInputs], ) -> InputProcessor:
return _for_hf(hf_config_type)(processor)

return wrapper
Expand Down Expand Up @@ -219,11 +222,8 @@ def wrapper(model_cls: N) -> N:

return wrapper

def dummy_data_for_profiling(
self,
model_config: "ModelConfig",
seq_len: int,
):
def dummy_data_for_profiling(self, model_config: "ModelConfig",
seq_len: int):
"""Create dummy data for memory profiling."""
# Avoid circular import
from vllm.model_executor.model_loader import get_model_architecture
Expand Down Expand Up @@ -279,3 +279,10 @@ def process_input(self, model_config: "ModelConfig",
f"model class {model_cls.__name__}.")

return processor(model_config, inputs)

def create_input_processor(self, model_config: ModelConfig):
"""
Create an input processor (see :meth:`process_input`) for a
specific model.
"""
return functools.partial(self.process_input, model_config=model_config)