Skip to content

Commit f6ffbc3

Browse files
xiegetestxiegegege
andauthored
add precision check for ci (#2732)
* add precision check for ci * add precision check for ci * add precision check for ci * add precision check for ci --------- Co-authored-by: xiegegege <xiege01@baidu.com>
1 parent e8bbe72 commit f6ffbc3

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

test/ci_use/EB_VL_Lite/test_EB_VL_Lite_serving.py

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -176,58 +176,31 @@ def consistent_payload():
176176
"seed": 13 # fixed random seed
177177
}
178178

179-
# ==========================
180-
# Helper function to calculate difference rate between two texts
181-
# ==========================
182-
def calculate_diff_rate(text1, text2):
183-
"""
184-
Calculate the difference rate between two strings
185-
based on the normalized Levenshtein edit distance.
186-
Returns a float in [0,1], where 0 means identical.
187-
"""
188-
if text1 == text2:
189-
return 0.0
190-
191-
len1, len2 = len(text1), len(text2)
192-
dp = [[0] * (len2 + 1) for _ in range(len1 + 1)]
193-
194-
for i in range(len1 + 1):
195-
for j in range(len2 + 1):
196-
if i == 0 or j == 0:
197-
dp[i][j] = i + j
198-
elif text1[i - 1] == text2[j - 1]:
199-
dp[i][j] = dp[i - 1][j - 1]
200-
else:
201-
dp[i][j] = 1 + min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1])
202-
203-
edit_distance = dp[len1][len2]
204-
max_len = max(len1, len2)
205-
return edit_distance / max_len if max_len > 0 else 0.0
206179

207180
# ==========================
208181
# Consistency test for repeated runs with fixed payload
209182
# ==========================
210183
def test_consistency_between_runs(api_url, headers, consistent_payload):
211184
"""
212-
Test that two runs with the same fixed input produce similar outputs.
185+
Test that result is same as the base result.
213186
"""
214-
# First request
187+
# request
215188
resp1 = requests.post(api_url, headers=headers, json=consistent_payload)
216189
assert resp1.status_code == 200
217190
result1 = resp1.json()
218191
content1 = result1["choices"][0]["message"]["content"]
219192

220-
# Second request
221-
resp2 = requests.post(api_url, headers=headers, json=consistent_payload)
222-
assert resp2.status_code == 200
223-
result2 = resp2.json()
224-
content2 = result2["choices"][0]["message"]["content"]
225-
226-
# Calculate difference rate
227-
diff_rate = calculate_diff_rate(content1, content2)
193+
# base result
194+
base_path = os.getenv("MODEL_PATH")
195+
if base_path:
196+
base_file = os.path.join(base_path, "ernie-4_5-vl-base")
197+
else:
198+
base_file = "ernie-4_5-vl-base"
199+
with open(base_file, "r") as f:
200+
content2 = f.read()
228201

229-
# Verify that the difference rate is below the threshold
230-
assert diff_rate < 0.05, "Output difference too large ({:.4%})".format(diff_rate)
202+
# Verify that result is same as the base result
203+
assert content1 == content2
231204

232205
# ==========================
233206
# OpenAI Client Chat Completion Test
@@ -322,4 +295,4 @@ def test_streaming_chat(openai_client, capsys):
322295
for chunk in response:
323296
if hasattr(chunk.choices[0], 'delta') and hasattr(chunk.choices[0].delta, 'content'):
324297
output.append(chunk.choices[0].delta.content)
325-
assert len(output) > 2
298+
assert len(output) > 2

0 commit comments

Comments
 (0)