Skip to content

Commit d01bad6

Browse files
Isotr0pyamitm02
authored andcommitted
[Bugfix] Fix the failing gte embedding test (vllm-project#18720)
Signed-off-by: Isotr0py <[email protected]> Signed-off-by: amit <[email protected]>
1 parent 4de1fa0 commit d01bad6

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

tests/conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def __init__(
311311
dtype: str = "auto",
312312
*,
313313
model_kwargs: Optional[dict[str, Any]] = None,
314+
trust_remote_code: bool = True,
314315
is_sentence_transformer: bool = False,
315316
is_cross_encoder: bool = False,
316317
skip_tokenizer_init: bool = False,
@@ -320,7 +321,7 @@ def __init__(
320321

321322
self.config = AutoConfig.from_pretrained(
322323
model_name,
323-
trust_remote_code=True,
324+
trust_remote_code=trust_remote_code,
324325
)
325326
self.device = self.get_default_device()
326327
self.dtype = torch_dtype = _get_and_verify_dtype(self.config, dtype)
@@ -336,7 +337,7 @@ def __init__(
336337
model_name,
337338
device=self.device,
338339
model_kwargs=model_kwargs,
339-
trust_remote_code=True,
340+
trust_remote_code=trust_remote_code,
340341
)
341342
elif is_cross_encoder:
342343
# Lazy init required for AMD CI
@@ -346,12 +347,12 @@ def __init__(
346347
model_name,
347348
device=self.device,
348349
automodel_args=model_kwargs,
349-
trust_remote_code=True,
350+
trust_remote_code=trust_remote_code,
350351
)
351352
else:
352353
model = auto_cls.from_pretrained(
353354
model_name,
354-
trust_remote_code=True,
355+
trust_remote_code=trust_remote_code,
355356
**model_kwargs,
356357
)
357358

@@ -372,7 +373,7 @@ def __init__(
372373
self.tokenizer = AutoTokenizer.from_pretrained(
373374
model_name,
374375
torch_dtype=torch_dtype,
375-
trust_remote_code=True,
376+
trust_remote_code=trust_remote_code,
376377
)
377378

378379
# don't put this import at the top level
@@ -381,7 +382,7 @@ def __init__(
381382
self.processor = AutoProcessor.from_pretrained(
382383
model_name,
383384
torch_dtype=torch_dtype,
384-
trust_remote_code=True,
385+
trust_remote_code=trust_remote_code,
385386
)
386387
if skip_tokenizer_init:
387388
self.tokenizer = self.processor.tokenizer

tests/models/language/pooling/test_embedding.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@
1010
@pytest.mark.parametrize(
1111
"model",
1212
[
13-
# [Encoder-only]
14-
pytest.param("BAAI/bge-base-en-v1.5",
15-
marks=[pytest.mark.core_model, pytest.mark.cpu_model]),
16-
pytest.param("sentence-transformers/all-MiniLM-L12-v2"),
17-
pytest.param("intfloat/multilingual-e5-small"),
18-
pytest.param("Alibaba-NLP/gte-Qwen2-1.5B-instruct"),
13+
# Be careful of the order of models, decoder-only models should be
14+
# placed before encoder-only models, otherwise `Qwen2.5-0.5B-Instruct`
15+
# case won't pass because gte-Qwen2-1.5B-instruct will cache custom
16+
# model code with bidirectional attention.
1917
# [Decoder-only]
2018
pytest.param("BAAI/bge-multilingual-gemma2",
2119
marks=[pytest.mark.core_model]),
2220
pytest.param("intfloat/e5-mistral-7b-instruct",
2321
marks=[pytest.mark.core_model, pytest.mark.cpu_model]),
2422
pytest.param("ssmits/Qwen2-7B-Instruct-embed-base"),
23+
# [Encoder-only]
24+
pytest.param("BAAI/bge-base-en-v1.5",
25+
marks=[pytest.mark.core_model, pytest.mark.cpu_model]),
26+
pytest.param("sentence-transformers/all-MiniLM-L12-v2"),
27+
pytest.param("intfloat/multilingual-e5-small"),
28+
pytest.param("Alibaba-NLP/gte-Qwen2-1.5B-instruct"),
2529
# [Cross-Encoder]
2630
pytest.param("sentence-transformers/stsb-roberta-base-v2"),
2731
],
@@ -44,7 +48,7 @@ def test_models(
4448
vllm_extra_kwargs = {}
4549
if model == "ssmits/Qwen2-7B-Instruct-embed-base":
4650
vllm_extra_kwargs["override_pooler_config"] = \
47-
PoolerConfig(pooling_type="MEAN")
51+
PoolerConfig(pooling_type="MEAN", normalize=False)
4852

4953
# The example_prompts has ending "\n", for example:
5054
# "Write a short story about a robot that dreams for the first time.\n"

tests/models/language/pooling/test_gte.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
########### Qwen2ForCausalLM
4646
EmbedModelInfo("Alibaba-NLP/gte-Qwen2-1.5B-instruct",
4747
architecture="Qwen2ForCausalLM",
48+
dtype="float32",
4849
enable_test=True),
4950
########## ModernBertModel
5051
EmbedModelInfo("Alibaba-NLP/gte-modernbert-base",

tests/models/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def check_embeddings_close(
314314
dim=0)
315315

316316
fail_msg = (f"Test{prompt_idx}:"
317+
f"\nCosine similarity: \t{sim:.4f}"
317318
f"\n{name_0}:\t{embeddings_0[:16]!r}"
318319
f"\n{name_1}:\t{embeddings_1[:16]!r}")
319320

0 commit comments

Comments
 (0)