A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 08:30 UTC
[CI/Build] Replace `math.isclose` with `pytest.approx` (#18703)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Cyrus Leung committed
May 26, 2025 at 17:05 UTC
38b13dfe78412aacfd9bf99e4f78bad5a43df9e6
6 files changed
+22
-31
tests/entrypoints/openai/correctness/test_mteb.py
+1
-2
@@ -1,5 +1,4 @@
1
# SPDX-License-Identifier: Apache-2.0
2
-import math
2
import os
3
4
import pytest
@@ -39,4 +38,4 @@ def test_mteb(server):
38
print("SentenceTransformer main score: ", st_main_score)
39
print("Difference: ", st_main_score - vllm_main_score)
40
42
- assert math.isclose(st_main_score, vllm_main_score, rel_tol=1e-4)
41
+ assert st_main_score == pytest.approx(vllm_main_score, rel=1e-4)
tests/entrypoints/openai/test_score.py
+3
-5
@@ -1,6 +1,4 @@
1
# SPDX-License-Identifier: Apache-2.0
2
-
3
-import math
2
from typing import Any
3
4
import pytest
@@ -92,7 +90,7 @@ class TestModel:
90
hf_outputs = run_transformers(runner, model, text_pairs)
91
92
for i in range(len(vllm_outputs)):
95
- assert math.isclose(hf_outputs[i], vllm_outputs[i], rel_tol=0.01)
93
+ assert hf_outputs[i] == pytest.approx(vllm_outputs[i], rel=0.01)
94
95
def test_text_1_list_text_2_list(self, server: RemoteOpenAIServer,
96
model: dict[str, Any], runner):
@@ -124,7 +122,7 @@ class TestModel:
122
hf_outputs = run_transformers(runner, model, text_pairs)
123
124
for i in range(len(vllm_outputs)):
127
- assert math.isclose(hf_outputs[i], vllm_outputs[i], rel_tol=0.01)
125
+ assert hf_outputs[i] == pytest.approx(vllm_outputs[i], rel=0.01)
126
127
def test_text_1_str_text_2_str(self, server: RemoteOpenAIServer,
128
model: dict[str, Any], runner):
@@ -150,7 +148,7 @@ class TestModel:
148
hf_outputs = run_transformers(runner, model, text_pairs)
149
150
for i in range(len(vllm_outputs)):
153
- assert math.isclose(hf_outputs[i], vllm_outputs[i], rel_tol=0.01)
151
+ assert hf_outputs[i] == pytest.approx(vllm_outputs[i], rel=0.01)
152
153
def test_score_max_model_len(self, server: RemoteOpenAIServer,
154
model: dict[str, Any]):
tests/models/language/pooling/mteb_utils.py
+1
-2
@@ -1,5 +1,4 @@
1
# SPDX-License-Identifier: Apache-2.0
2
-import math
2
from collections.abc import Sequence
3
4
import mteb
@@ -115,4 +114,4 @@ def mteb_test_embed_models(hf_runner,
114
print("SentenceTransformer:", model_dtype, st_main_score)
115
print("Difference:", st_main_score - vllm_main_score)
116
118
- assert math.isclose(st_main_score, vllm_main_score, rel_tol=MTEB_EMBED_TOL)
117
+ assert st_main_score == pytest.approx(vllm_main_score, rel=MTEB_EMBED_TOL)
tests/models/language/pooling/test_gritlm.py
+4
-5
@@ -2,7 +2,6 @@
2
from __future__ import annotations
3
4
import importlib.util
5
-import math
5
from array import array
6
7
import openai
@@ -104,16 +103,16 @@ def get_test_data():
103
104
def validate_embed_output(q_rep: list[list[float]], d_rep: list[list[float]]):
105
cosine_sim_q0_d0 = 1 - cosine(q_rep[0], d_rep[0])
107
- assert math.isclose(cosine_sim_q0_d0, 0.609, abs_tol=0.001)
106
+ assert cosine_sim_q0_d0 == pytest.approx(0.609, abs=0.001)
107
108
cosine_sim_q0_d1 = 1 - cosine(q_rep[0], d_rep[1])
110
- assert math.isclose(cosine_sim_q0_d1, 0.101, abs_tol=0.001)
109
+ assert cosine_sim_q0_d1 == pytest.approx(0.101, abs=0.001)
110
111
cosine_sim_q1_d0 = 1 - cosine(q_rep[1], d_rep[0])
113
- assert math.isclose(cosine_sim_q1_d0, 0.120, abs_tol=0.001)
112
+ assert cosine_sim_q1_d0 == pytest.approx(0.120, abs=0.001)
113
114
cosine_sim_q1_d1 = 1 - cosine(q_rep[1], d_rep[1])
116
- assert math.isclose(cosine_sim_q1_d1, 0.534, abs_tol=0.001)
115
+ assert cosine_sim_q1_d1 == pytest.approx(0.534, abs=0.001)
116
117
118
def test_gritlm_offline_embedding(vllm_runner):
tests/models/language/pooling/test_jina.py
+3
-5
@@ -1,6 +1,4 @@
1
# SPDX-License-Identifier: Apache-2.0
2
-import math
3
-
2
import pytest
3
4
from vllm import PoolingParams
@@ -60,7 +58,7 @@ def test_llm_1_to_1(vllm_runner, hf_runner, model_name, dtype: str):
58
assert len(vllm_outputs) == 1
59
assert len(hf_outputs) == 1
60
63
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
61
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
62
63
64
@pytest.mark.parametrize("dtype", ["half"])
@@ -78,8 +76,8 @@ def test_llm_1_to_N(vllm_runner, hf_runner, model_name, dtype: str):
76
assert len(vllm_outputs) == 10
77
assert len(hf_outputs) == 10
78
81
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
82
- assert math.isclose(hf_outputs[1], vllm_outputs[1], rel_tol=0.01)
79
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
80
+ assert hf_outputs[1] == pytest.approx(vllm_outputs[1], rel=0.01)
81
82
83
@pytest.fixture(scope="module", params=EMBEDDING_MODELS)
tests/models/language/pooling/test_scoring.py
+10
-12
@@ -1,6 +1,4 @@
1
# SPDX-License-Identifier: Apache-2.0
2
-import math
3
-
2
import pytest
3
import torch
4
import torch.nn.functional as F
@@ -45,7 +43,7 @@ def test_cross_encoder_1_to_1(vllm_runner, hf_runner, model_name):
43
assert len(vllm_outputs) == 1
44
assert len(hf_outputs) == 1
45
48
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
46
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
47
48
49
def test_cross_encoder_1_to_N(vllm_runner, hf_runner, model_name):
@@ -64,8 +62,8 @@ def test_cross_encoder_1_to_N(vllm_runner, hf_runner, model_name):
62
assert len(vllm_outputs) == 2
63
assert len(hf_outputs) == 2
64
67
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
68
- assert math.isclose(hf_outputs[1], vllm_outputs[1], rel_tol=0.01)
65
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
66
+ assert hf_outputs[1] == pytest.approx(vllm_outputs[1], rel=0.01)
67
68
69
def test_cross_encoder_N_to_N(vllm_runner, hf_runner, model_name):
@@ -84,8 +82,8 @@ def test_cross_encoder_N_to_N(vllm_runner, hf_runner, model_name):
82
assert len(vllm_outputs) == 2
83
assert len(hf_outputs) == 2
84
87
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
88
- assert math.isclose(hf_outputs[1], vllm_outputs[1], rel_tol=0.01)
85
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
86
+ assert hf_outputs[1] == pytest.approx(vllm_outputs[1], rel=0.01)
87
88
89
@pytest.fixture(scope="module", params=EMBEDDING_MODELS)
@@ -112,7 +110,7 @@ def test_embedding_1_to_1(vllm_runner, hf_runner, emb_model_name):
110
assert len(vllm_outputs) == 1
111
assert len(hf_outputs) == 1
112
115
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
113
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
114
115
116
def test_embedding_1_to_N(vllm_runner, hf_runner, emb_model_name):
@@ -140,8 +138,8 @@ def test_embedding_1_to_N(vllm_runner, hf_runner, emb_model_name):
138
assert len(vllm_outputs) == 2
139
assert len(hf_outputs) == 2
140
143
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
144
- assert math.isclose(hf_outputs[1], vllm_outputs[1], rel_tol=0.01)
141
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
142
+ assert hf_outputs[1] == pytest.approx(vllm_outputs[1], rel=0.01)
143
144
145
def test_embedding_N_to_N(vllm_runner, hf_runner, emb_model_name):
@@ -169,5 +167,5 @@ def test_embedding_N_to_N(vllm_runner, hf_runner, emb_model_name):
167
assert len(vllm_outputs) == 2
168
assert len(hf_outputs) == 2
169
172
- assert math.isclose(hf_outputs[0], vllm_outputs[0], rel_tol=0.01)
173
- assert math.isclose(hf_outputs[1], vllm_outputs[1], rel_tol=0.01)
170
+ assert hf_outputs[0] == pytest.approx(vllm_outputs[0], rel=0.01)
171
+ assert hf_outputs[1] == pytest.approx(vllm_outputs[1], rel=0.01)