[Bugfix] Support Sentence Transformers 5.4+ serialized configs (#54533)
Signed-off-by: maireneu <maireneu@gmail.com> Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
co-authored by
Codex
parent
f1e5fdd7f2
commit
cdefd9d499
@@ -1,9 +1,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from dataclasses import MISSING, Field, asdict, dataclass, field
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import cast
|
||||
from unittest.mock import patch
|
||||
@@ -39,11 +41,20 @@ from vllm.config.speculative import _validate_qwen3_omni_dspark
|
||||
from vllm.config.utils import get_field
|
||||
from vllm.config.vllm import OPTIMIZATION_LEVEL_TO_CONFIG, OptimizationLevel
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.transformers_utils.config import (
|
||||
get_pooling_config,
|
||||
try_get_dense_modules,
|
||||
)
|
||||
from vllm.v1.attention.backend import AttentionCGSupport
|
||||
|
||||
DEVICE_TYPE = current_platform.device_type
|
||||
|
||||
|
||||
def _write_json(path: Path, value: object) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(value), encoding="utf-8")
|
||||
|
||||
|
||||
def test_kda_recoverssm_derivation_is_revalidated():
|
||||
config = SimpleNamespace(
|
||||
cache_config=SimpleNamespace(
|
||||
@@ -1031,6 +1042,103 @@ def test_get_pooling_config():
|
||||
assert model_config.pooler_config.tok_pooling_type == "ALL"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("pooling_module_type", "normalize_module_type", "pooling_config", "expected"),
|
||||
[
|
||||
(
|
||||
"sentence_transformers.models.Pooling",
|
||||
"sentence_transformers.models.Normalize",
|
||||
{"pooling_mode_mean_tokens": True},
|
||||
{"use_activation": True, "seq_pooling_type": "MEAN"},
|
||||
),
|
||||
(
|
||||
"sentence_transformers.sentence_transformer.modules.pooling.Pooling",
|
||||
"sentence_transformers.sentence_transformer.modules.normalize.Normalize",
|
||||
{"pooling_mode": "lasttoken"},
|
||||
{"use_activation": True, "seq_pooling_type": "LAST"},
|
||||
),
|
||||
(
|
||||
"sentence_transformers.sentence_transformer.modules.pooling.Pooling",
|
||||
"sentence_transformers.base.modules.normalize.Normalize",
|
||||
{"pooling_mode": "mean"},
|
||||
{"use_activation": True, "seq_pooling_type": "MEAN"},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_get_pooling_config_supports_sentence_transformers_schemas(
|
||||
tmp_path,
|
||||
caplog,
|
||||
pooling_module_type,
|
||||
normalize_module_type,
|
||||
pooling_config,
|
||||
expected,
|
||||
):
|
||||
modules = [
|
||||
{"idx": 1, "name": "1", "path": "1_Pooling", "type": pooling_module_type},
|
||||
{
|
||||
"idx": 2,
|
||||
"name": "2",
|
||||
"path": "2_Normalize",
|
||||
"type": normalize_module_type,
|
||||
},
|
||||
]
|
||||
_write_json(tmp_path / "modules.json", modules)
|
||||
_write_json(tmp_path / "1_Pooling" / "config.json", pooling_config)
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
config = get_pooling_config(str(tmp_path))
|
||||
|
||||
assert config == expected
|
||||
assert "Unable to determine Sentence Transformers pooling type" not in caplog.text
|
||||
|
||||
|
||||
def test_get_pooling_config_warns_when_pooling_mode_is_unknown(tmp_path, caplog):
|
||||
modules = [
|
||||
{
|
||||
"idx": 1,
|
||||
"name": "1",
|
||||
"path": "1_Pooling",
|
||||
"type": "sentence_transformers.models.Pooling",
|
||||
}
|
||||
]
|
||||
_write_json(tmp_path / "modules.json", modules)
|
||||
_write_json(
|
||||
tmp_path / "1_Pooling" / "config.json",
|
||||
{"pooling_mode": "unsupported"},
|
||||
)
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
config = get_pooling_config(str(tmp_path))
|
||||
|
||||
assert config == {"use_activation": False}
|
||||
assert "Unable to determine Sentence Transformers pooling type" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"dense_module_type",
|
||||
[
|
||||
"sentence_transformers.models.Dense",
|
||||
"sentence_transformers.base.modules.dense.Dense",
|
||||
],
|
||||
)
|
||||
def test_get_dense_modules_supports_sentence_transformers_schemas(
|
||||
tmp_path, dense_module_type
|
||||
):
|
||||
modules = [{"idx": 2, "name": "2", "path": "2_Dense", "type": dense_module_type}]
|
||||
dense_config = {
|
||||
"in_features": 768,
|
||||
"out_features": 3072,
|
||||
"bias": False,
|
||||
"activation_function": "torch.nn.modules.linear.Identity",
|
||||
}
|
||||
_write_json(tmp_path / "modules.json", modules)
|
||||
_write_json(tmp_path / "2_Dense" / "config.json", dense_config)
|
||||
|
||||
assert try_get_dense_modules(str(tmp_path)) == [
|
||||
{**dense_config, "folder": "2_Dense"}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
current_platform.is_rocm(), reason="Xformers backend is not supported on ROCm."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user