[Model][2/N] Improve all pooling task | Support multi-vector retrieval (#25370)
Signed-off-by: wang.yuqi <noooop@126.com>
This commit is contained in:
+34
-27
@@ -10,7 +10,7 @@ from vllm.sampling_params import RequestOutputKind
|
||||
from vllm.tasks import PoolingTask
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.config import ModelConfig, PoolerConfig
|
||||
|
||||
|
||||
class PoolingParams(
|
||||
@@ -30,7 +30,6 @@ class PoolingParams(
|
||||
if model support matryoshka representation.
|
||||
activation: Whether to apply activation function to
|
||||
the classification outputs.
|
||||
softmax: Whether to apply softmax to the reward outputs.
|
||||
"""
|
||||
|
||||
# --8<-- [start:common-pooling-params]
|
||||
@@ -48,32 +47,19 @@ class PoolingParams(
|
||||
activation: bool | None = None
|
||||
# --8<-- [end:classification-pooling-params]
|
||||
|
||||
## for reward models
|
||||
softmax: bool | None = None
|
||||
## for step pooling models
|
||||
step_tag_id: int | None = None
|
||||
returned_token_ids: list[int] | None = None
|
||||
|
||||
## Internal use only
|
||||
task: PoolingTask | None = None
|
||||
"""Internal use only."""
|
||||
|
||||
requires_token_ids: bool = False
|
||||
"""Internal use only."""
|
||||
|
||||
extra_kwargs: dict[str, Any] | None = None
|
||||
"""Internal use only."""
|
||||
|
||||
output_kind: RequestOutputKind = RequestOutputKind.FINAL_ONLY
|
||||
|
||||
@property
|
||||
def all_parameters(self) -> list[str]:
|
||||
return [
|
||||
"dimensions",
|
||||
"normalize",
|
||||
"activation",
|
||||
"softmax",
|
||||
"step_tag_id",
|
||||
"returned_token_ids",
|
||||
]
|
||||
return ["dimensions", "normalize", "activation"]
|
||||
|
||||
@property
|
||||
def valid_parameters(self):
|
||||
@@ -81,7 +67,8 @@ class PoolingParams(
|
||||
"embed": ["dimensions", "normalize"],
|
||||
"classify": ["activation"],
|
||||
"score": ["activation"],
|
||||
"encode": ["softmax", "step_tag_id", "returned_token_ids"],
|
||||
"token_embed": ["dimensions", "normalize"],
|
||||
"token_classify": ["activation"],
|
||||
}
|
||||
|
||||
def clone(self) -> "PoolingParams":
|
||||
@@ -100,7 +87,6 @@ class PoolingParams(
|
||||
# NOTE: Task validation needs to done against the model instance,
|
||||
# which is not available in model config. So, it's not included
|
||||
# in this method
|
||||
|
||||
self._merge_default_parameters(model_config)
|
||||
self._set_default_parameters(model_config)
|
||||
self._verify_valid_parameters()
|
||||
@@ -125,8 +111,34 @@ class PoolingParams(
|
||||
if getattr(self, k, None) is None:
|
||||
setattr(self, k, getattr(pooler_config, k))
|
||||
|
||||
self._verify_step_pooling(pooler_config, valid_parameters)
|
||||
|
||||
def _verify_step_pooling(
|
||||
self, pooler_config: "PoolerConfig", valid_parameters: list[str]
|
||||
):
|
||||
step_pooling_parameters = ["step_tag_id", "returned_token_ids"]
|
||||
if pooler_config.pooling_type != "STEP":
|
||||
invalid_parameters = []
|
||||
for k in step_pooling_parameters:
|
||||
if getattr(self, k, None) is not None:
|
||||
invalid_parameters.append(k)
|
||||
|
||||
if invalid_parameters:
|
||||
raise ValueError(
|
||||
f"Task {self.task} only supports {valid_parameters} "
|
||||
f"parameters, does not support "
|
||||
f"{invalid_parameters} parameters"
|
||||
)
|
||||
else:
|
||||
for k in step_pooling_parameters:
|
||||
if getattr(pooler_config, k, None) is None:
|
||||
continue
|
||||
|
||||
if getattr(self, k, None) is None:
|
||||
setattr(self, k, getattr(pooler_config, k))
|
||||
|
||||
def _set_default_parameters(self, model_config: Optional["ModelConfig"]):
|
||||
if self.task == "embed":
|
||||
if self.task in ["embed", "token_embed"]:
|
||||
if self.normalize is None:
|
||||
self.normalize = True
|
||||
|
||||
@@ -150,13 +162,9 @@ class PoolingParams(
|
||||
elif self.dimensions < 1:
|
||||
raise ValueError("Dimensions must be greater than 0")
|
||||
|
||||
elif self.task in ["classify", "score"]:
|
||||
elif self.task in ["classify", "score", "token_classify"]:
|
||||
if self.activation is None:
|
||||
self.activation = True
|
||||
|
||||
elif self.task == "encode":
|
||||
if self.softmax is None:
|
||||
self.softmax = True
|
||||
else:
|
||||
raise ValueError(f"Unknown pooling task: {self.task}")
|
||||
|
||||
@@ -185,7 +193,6 @@ class PoolingParams(
|
||||
f"normalize={self.normalize}, "
|
||||
f"dimensions={self.dimensions}, "
|
||||
f"activation={self.activation}, "
|
||||
f"softmax={self.softmax}, "
|
||||
f"step_tag_id={self.step_tag_id}, "
|
||||
f"returned_token_ids={self.returned_token_ids}, "
|
||||
f"requires_token_ids={self.requires_token_ids}, "
|
||||
|
||||
Reference in New Issue
Block a user