[Misc] Simplify PoolerOutput and move to v1/outputs (#25629)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -16,9 +16,9 @@ from vllm.config import ModelConfig, PoolerConfig, get_current_vllm_config
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.models.adapters import _load_st_projector
|
||||
from vllm.pooling_params import PoolingParams
|
||||
from vllm.sequence import PoolerOutput, PoolingSequenceGroupOutput
|
||||
from vllm.tasks import PoolingTask
|
||||
from vllm.utils import current_stream, resolve_obj_by_qualname
|
||||
from vllm.utils import resolve_obj_by_qualname
|
||||
from vllm.v1.outputs import PoolerOutput
|
||||
from vllm.v1.pool.metadata import PoolingCursor, PoolingMetadata
|
||||
|
||||
logger = init_logger(__name__)
|
||||
@@ -190,19 +190,6 @@ def get_cross_encoder_activation_function(config: PretrainedConfig):
|
||||
return PoolerClassify()
|
||||
|
||||
|
||||
def build_output(
|
||||
all_data: Union[torch.Tensor, list[torch.Tensor]], ) -> PoolerOutput:
|
||||
# Pooling models D2H & synchronize occurs here
|
||||
if isinstance(all_data, list):
|
||||
all_data = [d.to("cpu", non_blocking=True) for d in all_data]
|
||||
else:
|
||||
all_data = all_data.to("cpu", non_blocking=True)
|
||||
current_stream().synchronize()
|
||||
|
||||
all_outputs = [PoolingSequenceGroupOutput(data) for data in all_data]
|
||||
return PoolerOutput(outputs=all_outputs)
|
||||
|
||||
|
||||
class PoolingMethod(nn.Module, ABC):
|
||||
|
||||
@staticmethod
|
||||
@@ -556,7 +543,7 @@ class SimplePooler(Pooler):
|
||||
) -> PoolerOutput:
|
||||
pooled_data = self.pooling(hidden_states, pooling_metadata)
|
||||
pooled_data = self.head(pooled_data, pooling_metadata)
|
||||
return build_output(pooled_data)
|
||||
return pooled_data
|
||||
|
||||
|
||||
class StepPooler(Pooler):
|
||||
@@ -607,7 +594,7 @@ class StepPooler(Pooler):
|
||||
) -> PoolerOutput:
|
||||
pooled_data = self.extract_states(hidden_states, pooling_metadata)
|
||||
pooled_data = self.head(pooled_data, pooling_metadata)
|
||||
return build_output(pooled_data)
|
||||
return pooled_data
|
||||
|
||||
|
||||
class ClassifierPooler(Pooler):
|
||||
@@ -678,7 +665,7 @@ class ClassifierPooler(Pooler):
|
||||
]
|
||||
|
||||
# scores shape: [batchsize, num_labels]
|
||||
return build_output(scores)
|
||||
return scores
|
||||
|
||||
|
||||
class DispatchPooler(Pooler):
|
||||
@@ -708,7 +695,7 @@ class DispatchPooler(Pooler):
|
||||
) -> PoolerOutput:
|
||||
poolers_by_task = self.poolers_by_task
|
||||
|
||||
outputs = list[PoolingSequenceGroupOutput]()
|
||||
outputs = list[torch.Tensor]()
|
||||
offset = 0
|
||||
for task, group in groupby(get_tasks(pooling_metadata)):
|
||||
if not (pooler := poolers_by_task.get(task)):
|
||||
@@ -722,10 +709,10 @@ class DispatchPooler(Pooler):
|
||||
pooling_metadata[offset:offset + num_items],
|
||||
)
|
||||
|
||||
outputs.extend(group_output.outputs)
|
||||
outputs.extend(group_output)
|
||||
offset += num_items
|
||||
|
||||
return PoolerOutput(outputs)
|
||||
return outputs
|
||||
|
||||
def extra_repr(self) -> str:
|
||||
s = f"supported_task={self.get_supported_tasks()}"
|
||||
|
||||
Reference in New Issue
Block a user