main
py 112 lines 3.58 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 import os
4
5 import lm_eval
6 import openai
7
8 BASE_URL = "http://localhost:8192/v1"
9 NUM_CONCURRENT = int(os.getenv("NUM_CONCURRENT", "100"))
10 TASK = "gsm8k"
11 FILTER = "exact_match,strict-match"
12 # TODO(#43186): Widened from 0.03 to absorb chunk_scan/SSU numeric jitter
13 # on granite-4.0-h-tiny under NIXL PD; tighten when the kernel divergence
14 # is fixed.
15 RTOL = 0.05
16
17 # Model-specific expected values
18 EXPECTED_VALUES = {
19 "Qwen/Qwen3-0.6B": 0.41,
20 "deepseek-ai/deepseek-vl2-small": 0.59,
21 "deepseek-ai/deepseek-vl2-tiny": 0.19,
22 "deepseek-ai/DeepSeek-V2-Lite-Chat": 0.65,
23 "google/gemma-3-4b-it": 0.74,
24 "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-FP8": 0.84,
25 "ibm-granite/granite-4.0-h-tiny": 0.77,
26 "Qwen/Qwen3.5-0.8B": 0.33,
27 "google/gemma-4-E2B-it": 0.485,
28 "ai21labs/AI21-Jamba2-3B": 0.74,
29 "deepseek-ai/DeepSeek-V4-Flash": 0.95,
30 }
31
32 SIMPLE_PROMPT = (
33 "The best part about working on vLLM is that I got to meet so many people across "
34 "various different organizations like UCB, Google, and Meta which means",
35 )
36
37 # Get model name from environment variable
38 MODEL_NAME = os.environ.get("TEST_MODEL", "Qwen/Qwen3-0.6B")
39
40
41 def _meets_accuracy_threshold(measured_value: float, expected_value: float) -> bool:
42 return measured_value >= expected_value - RTOL
43
44
45 def test_accuracy_threshold_is_one_sided():
46 expected_value = 0.77
47 minimum_value = expected_value - RTOL
48
49 assert _meets_accuracy_threshold(minimum_value, expected_value)
50 assert _meets_accuracy_threshold(expected_value + RTOL + 0.01, expected_value)
51 assert not _meets_accuracy_threshold(minimum_value - 0.01, expected_value)
52
53
54 def run_simple_prompt():
55 client = openai.OpenAI(api_key="EMPTY", base_url=BASE_URL)
56 completion = client.completions.create(model=MODEL_NAME, prompt=SIMPLE_PROMPT)
57
58 print("-" * 50)
59 print(f"Completion results for {MODEL_NAME}:")
60 print(completion)
61 print("-" * 50)
62
63
64 def test_accuracy():
65 """Run the end to end accuracy test."""
66 run_simple_prompt()
67
68 if "gemma-4" in MODEL_NAME:
69 # Gemma4 is quite sensible to having a chat template applied, so we evaluate
70 # on chat completions.
71 model_args = (
72 f"model={MODEL_NAME},"
73 f"base_url={BASE_URL}/chat/completions,"
74 f"num_concurrent={NUM_CONCURRENT},"
75 "tokenizer_backend=huggingface,"
76 "trust_remote_code=True"
77 )
78 results = lm_eval.simple_evaluate(
79 model="local-chat-completions",
80 model_args=model_args,
81 tasks=TASK,
82 num_fewshot=5,
83 apply_chat_template=True,
84 )
85 else:
86 model_args = (
87 f"model={MODEL_NAME},"
88 f"base_url={BASE_URL}/completions,"
89 f"num_concurrent={NUM_CONCURRENT},tokenized_requests=False,"
90 "trust_remote_code=True"
91 )
92 results = lm_eval.simple_evaluate(
93 model="local-completions",
94 model_args=model_args,
95 tasks=TASK,
96 )
97
98 measured_value = results["results"][TASK][FILTER]
99 expected_value = EXPECTED_VALUES.get(MODEL_NAME)
100
101 print(f"Measured accuracy value: {measured_value}\n")
102 if expected_value is None:
103 print(
104 f"Warning: No expected value found for {MODEL_NAME}. "
105 "Skipping accuracy check."
106 )
107 return
108
109 minimum_value = expected_value - RTOL
110 assert _meets_accuracy_threshold(measured_value, expected_value), (
111 f"Expected at least: {minimum_value} | Measured: {measured_value}"
112 )