|
| 1 | +# Copied from vLLM: https://github.com/vllm-project/vllm/blob/839ab00/tests/entrypoints/llm/test_accuracy.py |
| 2 | + |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 5 | +""" |
| 6 | +This file test accuracy of the vLLM server via LMEval. |
| 7 | +It uses local-completions, which interacts with vLLM |
| 8 | +through the OAI API with N concurrent connections. |
| 9 | +This simulates real work usage of the API and makes |
| 10 | +sure that the zmq frontend mp RPC message passing and |
| 11 | +AsyncLLMEngine are working correctly. |
| 12 | +""" |
| 13 | + |
| 14 | +import threading |
| 15 | + |
| 16 | +import lm_eval |
| 17 | +import pytest |
| 18 | +from vllm.platforms import current_platform |
| 19 | + |
| 20 | +MODEL_NAMES = [] |
| 21 | +FP8_KV_MODEL_NAMES = [] |
| 22 | +NUM_CONCURRENT = 500 |
| 23 | +TASK = "gsm8k" |
| 24 | +FILTER = "exact_match,strict-match" |
| 25 | +RTOL = 0.03 |
| 26 | +_JSON_WRITE_LOCK = threading.Lock() |
| 27 | + |
| 28 | + |
| 29 | +def run_test(model_name, expected_value, more_args=None): |
| 30 | + """Run the end to end accuracy test.""" |
| 31 | + print(f"Running test for model: {model_name}") |
| 32 | + |
| 33 | + model_args = f"pretrained={model_name},max_model_len=4096" |
| 34 | + if more_args is not None: |
| 35 | + model_args = "{},{}".format(model_args, more_args) |
| 36 | + |
| 37 | + results = lm_eval.simple_evaluate( |
| 38 | + model="vllm", |
| 39 | + model_args=model_args, |
| 40 | + tasks="gsm8k", |
| 41 | + batch_size="auto", |
| 42 | + ) |
| 43 | + |
| 44 | + measured_value = results["results"][TASK][FILTER] |
| 45 | + assert (measured_value - RTOL < expected_value < measured_value + |
| 46 | + RTOL), f"Expected: {expected_value} | Measured: {measured_value}" |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.skipif(not current_platform.is_cuda() |
| 50 | + and not current_platform.is_tpu(), |
| 51 | + reason="V1 is currently only supported on CUDA and TPU") |
| 52 | +def test_lm_eval_accuracy_v1_engine(monkeypatch: pytest.MonkeyPatch, |
| 53 | + request: pytest.FixtureRequest): |
| 54 | + """Run with the V1 Engine.""" |
| 55 | + model = request.config.getoption("--model-name") |
| 56 | + print(f"Testing model: {model}...") |
| 57 | + |
| 58 | + tp_size = request.config.getoption("--tensor-parallel-size") |
| 59 | + expected_value = request.config.getoption("--expected-value") |
| 60 | + |
| 61 | + if expected_value is None: |
| 62 | + raise ValueError |
| 63 | + |
| 64 | + if tp_size is None: |
| 65 | + tp_size = 1 |
| 66 | + elif tp_size < 1 or tp_size > 8: |
| 67 | + raise ValueError |
| 68 | + |
| 69 | + with monkeypatch.context() as m: |
| 70 | + m.setenv("VLLM_USE_V1", "1") |
| 71 | + |
| 72 | + more_args = None |
| 73 | + if current_platform.is_tpu(): |
| 74 | + more_args = "max_model_len=2048,max_num_seqs=64" |
| 75 | + tp_size_str = f"tensor_parallel_size={tp_size}" |
| 76 | + more_args += ",{}".format(tp_size_str) |
| 77 | + |
| 78 | + print(f"common args: {more_args}") |
| 79 | + |
| 80 | + run_test(model, expected_value, more_args) |
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.skipif(not current_platform.is_cuda() |
| 84 | + and not current_platform.is_tpu(), |
| 85 | + reason="V1 is currently only supported on CUDA and TPU") |
| 86 | +def test_lm_eval_accuracy_v1_engine_fp8_kv_cache( |
| 87 | + monkeypatch: pytest.MonkeyPatch, request: pytest.FixtureRequest): |
| 88 | + """Run with the V1 Engine.""" |
| 89 | + fp8_kv_model = request.config.getoption("--fp8-kv-model-name") |
| 90 | + print(f"Testing fp8_kv_model: {fp8_kv_model}...") |
| 91 | + |
| 92 | + tp_size = request.config.getoption("--tensor-parallel-size") |
| 93 | + expected_value = request.config.getoption("--expected-value") |
| 94 | + |
| 95 | + if expected_value is None: |
| 96 | + raise ValueError |
| 97 | + |
| 98 | + if tp_size is None: |
| 99 | + tp_size = 1 |
| 100 | + elif tp_size < 1 or tp_size > 8: |
| 101 | + raise ValueError |
| 102 | + |
| 103 | + with monkeypatch.context() as m: |
| 104 | + m.setenv("VLLM_USE_V1", "1") |
| 105 | + |
| 106 | + more_args = None |
| 107 | + if current_platform.is_tpu(): |
| 108 | + more_args = "max_model_len=2048,max_num_seqs=128,kv_cache_dtype=fp8" |
| 109 | + tp_size_str = f"tensor_parallel_size={tp_size}" |
| 110 | + more_args += ",{}".format(tp_size_str) |
| 111 | + |
| 112 | + print(f"common args: {more_args}") |
| 113 | + |
| 114 | + run_test(fp8_kv_model, expected_value, more_args) |
0 commit comments