[Model Runner V2] Enable encoder token classification (#50293)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
@@ -291,7 +291,9 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
# Do not rely on pooling_runner here, since this information is needed
|
||||
# on the first PP rank, while pooling_runner is only initialized
|
||||
# on the last PP rank.
|
||||
tasks.extend(PoolingRunner.get_supported_tasks(self.model))
|
||||
tasks.extend(
|
||||
PoolingRunner.get_supported_tasks(self.model, self.model_config)
|
||||
)
|
||||
return tuple(tasks)
|
||||
|
||||
def load_model(self, load_dummy_weights: bool = False, *args, **kwargs) -> None:
|
||||
|
||||
@@ -6,7 +6,7 @@ import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.config import ModelConfig, VllmConfig
|
||||
from vllm.model_executor.models import VllmModelForPooling, is_pooling_model
|
||||
from vllm.pooling_params import PoolingParams
|
||||
from vllm.tasks import PoolingTask
|
||||
@@ -16,7 +16,9 @@ from vllm.v1.pool.metadata import PoolingMetadata, PoolingStates
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch
|
||||
from vllm.v1.worker.gpu.states import RequestState
|
||||
|
||||
_SUPPORTED_TASKS: frozenset[PoolingTask] = frozenset({"embed", "classify"})
|
||||
_SUPPORTED_TASKS: frozenset[PoolingTask] = frozenset(
|
||||
{"embed", "classify", "token_classify"}
|
||||
)
|
||||
|
||||
|
||||
class PoolingRunner:
|
||||
@@ -25,19 +27,26 @@ class PoolingRunner:
|
||||
self.model_config = vllm_config.model_config
|
||||
self.max_num_reqs = vllm_config.scheduler_config.max_num_seqs
|
||||
model_tasks = tuple(sorted(self.model.pooler.get_supported_tasks()))
|
||||
enabled_tasks = self._get_enabled_tasks(self.model_config)
|
||||
selected_task = self.model_config.get_pooling_task(model_tasks)
|
||||
if selected_task not in _SUPPORTED_TASKS:
|
||||
raise ValueError(
|
||||
"Model Runner V2 supports only sequence-level pooling tasks "
|
||||
f"{sorted(_SUPPORTED_TASKS)}, but this model selects "
|
||||
f"{selected_task!r} from {list(model_tasks)}. Set an explicitly "
|
||||
"supported task or VLLM_USE_V2_MODEL_RUNNER=0."
|
||||
if selected_task not in enabled_tasks:
|
||||
hint = (
|
||||
"Set an explicitly supported task or VLLM_USE_V2_MODEL_RUNNER=0."
|
||||
if enabled_tasks.intersection(model_tasks)
|
||||
else "Set VLLM_USE_V2_MODEL_RUNNER=0 to use this model."
|
||||
)
|
||||
self.supported_tasks = frozenset(self.get_supported_tasks(model))
|
||||
raise ValueError(
|
||||
"Model Runner V2 supports pooling tasks "
|
||||
f"{sorted(enabled_tasks)}, but this model selects "
|
||||
f"{selected_task!r} from {list(model_tasks)}. {hint}"
|
||||
)
|
||||
self.supported_tasks = frozenset(
|
||||
self.get_supported_tasks(model, self.model_config)
|
||||
)
|
||||
if not self.supported_tasks:
|
||||
raise ValueError(
|
||||
"Model Runner V2 supports only sequence-level pooling tasks "
|
||||
f"{sorted(_SUPPORTED_TASKS)}, but this model supports "
|
||||
"Model Runner V2 supports pooling tasks "
|
||||
f"{sorted(enabled_tasks)}, but this model supports "
|
||||
f"{list(model_tasks)}. "
|
||||
"Set VLLM_USE_V2_MODEL_RUNNER=0 to use this model."
|
||||
)
|
||||
@@ -46,10 +55,20 @@ class PoolingRunner:
|
||||
self.prompt_token_ids: dict[int, torch.Tensor] = {}
|
||||
|
||||
@staticmethod
|
||||
def get_supported_tasks(model: nn.Module) -> list[PoolingTask]:
|
||||
def _get_enabled_tasks(model_config: ModelConfig) -> frozenset[PoolingTask]:
|
||||
# Token classification is validated only for unchunked encoder-only prefill.
|
||||
if model_config.attn_type == "encoder_only":
|
||||
return _SUPPORTED_TASKS
|
||||
return _SUPPORTED_TASKS - {"token_classify"}
|
||||
|
||||
@staticmethod
|
||||
def get_supported_tasks(
|
||||
model: nn.Module, model_config: ModelConfig
|
||||
) -> list[PoolingTask]:
|
||||
if not is_pooling_model(model):
|
||||
return []
|
||||
return sorted(model.pooler.get_supported_tasks() & _SUPPORTED_TASKS)
|
||||
enabled_tasks = PoolingRunner._get_enabled_tasks(model_config)
|
||||
return sorted(model.pooler.get_supported_tasks() & enabled_tasks)
|
||||
|
||||
def add_request(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user