[Misc] Improve Matryoshka pooling dimensions validation (#48057)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
26587f9519
commit
62286308c9
+17
-16
@@ -164,28 +164,29 @@ class PoolingParams(
|
||||
self.use_activation = True
|
||||
|
||||
if self.dimensions is not None:
|
||||
dimensions = self.dimensions
|
||||
model_name = model_config.served_model_name
|
||||
embedding_size = model_config.embedding_size
|
||||
valid_range = f"[1, {embedding_size}]"
|
||||
dimensions_in_range = 1 <= dimensions <= embedding_size
|
||||
if not model_config.is_matryoshka:
|
||||
raise ValueError(
|
||||
f'Model "{model_config.served_model_name}" does not '
|
||||
f"support matryoshka representation, "
|
||||
f"changing output dimensions will lead to poor results."
|
||||
f"Model {model_name!r} does not support Matryoshka "
|
||||
f"embeddings; dimensions must be unset "
|
||||
f"(received dimensions={dimensions})."
|
||||
)
|
||||
|
||||
if not dimensions_in_range:
|
||||
raise ValueError(
|
||||
f"Model {model_name!r} only supports dimensions in "
|
||||
f"range {valid_range}, got {dimensions}."
|
||||
)
|
||||
|
||||
mds = model_config.matryoshka_dimensions
|
||||
if mds is not None:
|
||||
if self.dimensions not in mds:
|
||||
raise ValueError(
|
||||
f"Model {model_config.served_model_name!r} "
|
||||
f"only supports {str(mds)} matryoshka dimensions, "
|
||||
f"use other output dimensions will "
|
||||
f"lead to poor results."
|
||||
)
|
||||
elif self.dimensions < 1:
|
||||
raise ValueError("Dimensions must be greater than 0")
|
||||
elif self.dimensions > model_config.embedding_size:
|
||||
if mds is not None and dimensions not in mds:
|
||||
raise ValueError(
|
||||
"Dimensions must be less than or equal to the model's "
|
||||
f"embedding size ({model_config.embedding_size})"
|
||||
f"Model {model_name!r} only supports Matryoshka "
|
||||
f"dimensions {str(mds)}, got {dimensions}."
|
||||
)
|
||||
|
||||
elif self.task in ["classify", "token_classify"]:
|
||||
|
||||
Reference in New Issue
Block a user