main
py 41 lines 1.3 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Shared BF16 baselines for the quantization comparison tests.
4
5 Several tests here quantize the same model and compare against an
6 unquantized run of it. Computing that reference once per session avoids
7 booting an identical engine for every quantization scheme under test.
8
9 Only the outputs are cached; each engine is still torn down as usual, so
10 tests keep the isolation ``VllmRunner.__exit__`` provides.
11 """
12
13 import pytest
14
15
16 @pytest.fixture(scope="session")
17 def quant_baseline_logprobs(vllm_runner):
18 """Greedy logprobs for an unquantized model, computed once per config."""
19 cache: dict = {}
20
21 def baseline(
22 model: str,
23 prompts: list[str],
24 *,
25 max_model_len: int,
26 max_tokens: int,
27 num_logprobs: int,
28 ):
29 key = (model, max_model_len, max_tokens, num_logprobs, tuple(prompts))
30 if key not in cache:
31 with vllm_runner(
32 model,
33 max_model_len=max_model_len,
34 enforce_eager=True,
35 ) as vllm_model:
36 cache[key] = vllm_model.generate_greedy_logprobs(
37 prompts, max_tokens, num_logprobs
38 )
39 return cache[key]
40
41 return baseline