[MyPy][3/N] Fix MyPy errors in test groups (part 3) (#55939)
Signed-off-by: Taimys <ffy2281693949@gmail.com> Signed-off-by: Luyi Xiao <81631911+luyixiao95@users.noreply.github.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: Luyi Xiao <81631911+luyixiao95@users.noreply.github.com> Co-authored-by: Taimys <ffy2281693949@gmail.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Codex
Luyi Xiao
Taimys
Harry Mellor
Claude Opus 5.5
parent
c4fa6f36a7
commit
5225f1bacb
@@ -24,6 +24,7 @@ from vllm import SamplingParams
|
||||
from vllm.config.model import LogprobsMode
|
||||
from vllm.distributed import cleanup_dist_env_and_memory
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.logprobs import Logprob
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.v1.engine.input_processor import InputProcessor
|
||||
|
||||
@@ -145,7 +146,7 @@ def _repeat_logprob_config(
|
||||
def _run_and_validate(
|
||||
vllm_model: VllmRunner,
|
||||
test_prompts: list[str],
|
||||
vllm_sampling_params: SamplingParams,
|
||||
vllm_sampling_params: SamplingParams | list[SamplingParams],
|
||||
hf_logprobs: list[list[torch.Tensor]],
|
||||
hf_outputs: list[tuple[list[int], str]],
|
||||
logprob_prompt_logprob_list: BatchLogprobsSpecType,
|
||||
@@ -163,11 +164,12 @@ def _run_and_validate(
|
||||
# Extract request-level (prompt)logprobs config
|
||||
num_top_logprobs, num_top_prompt_logprobs = logprob_prompt_logprob
|
||||
|
||||
assert vllm_result.prompt_token_ids is not None
|
||||
# Test whether sampled token output is consistent between vLLM and HF
|
||||
# vLLM prompt+completion should match HF output
|
||||
if temperature == 0.0:
|
||||
assert (
|
||||
vllm_result.prompt_token_ids + vllm_result.outputs[0].token_ids
|
||||
vllm_result.prompt_token_ids + list(vllm_result.outputs[0].token_ids)
|
||||
== hf_output[0]
|
||||
)
|
||||
else:
|
||||
@@ -191,7 +193,9 @@ def _run_and_validate(
|
||||
|
||||
# Confirm that the output token appears among the logprobs
|
||||
assert token_id in logprobs
|
||||
token_in_topk = logprobs[token_id].rank <= num_top_logprobs
|
||||
rank = logprobs[token_id].rank
|
||||
assert rank is not None
|
||||
token_in_topk = rank <= num_top_logprobs
|
||||
|
||||
# If the output token is not included in the top K
|
||||
# logprob, it can return 1 more data
|
||||
@@ -207,8 +211,10 @@ def _run_and_validate(
|
||||
|
||||
output_text = vllm_result.outputs[0].text
|
||||
output_string_from_most_likely_tokens_lst: list[str] = []
|
||||
for top_logprobs in vllm_result.outputs[0].logprobs:
|
||||
top_logprob = next(iter(top_logprobs.values()))
|
||||
for output_logprobs in vllm_result.outputs[0].logprobs:
|
||||
assert output_logprobs is not None
|
||||
top_logprob = next(iter(output_logprobs.values()))
|
||||
assert top_logprob.decoded_token is not None
|
||||
output_string_from_most_likely_tokens_lst.append(
|
||||
top_logprob.decoded_token
|
||||
)
|
||||
@@ -226,8 +232,9 @@ def _run_and_validate(
|
||||
|
||||
# Compare vLLM sample logprobs to HF
|
||||
vllm_sample_logprobs = vllm_result.outputs[0].logprobs
|
||||
for i, top_logprobs in enumerate(vllm_sample_logprobs):
|
||||
for token_id, sample_logprob in top_logprobs.items():
|
||||
for i, sample_logprobs in enumerate(vllm_sample_logprobs):
|
||||
assert sample_logprobs is not None
|
||||
for token_id, sample_logprob in sample_logprobs.items():
|
||||
if temperature == 0.0 or i == 0:
|
||||
logprob = sample_logprob.logprob
|
||||
torch.testing.assert_close(
|
||||
@@ -271,9 +278,9 @@ def _run_and_validate(
|
||||
|
||||
# Confirm that the prompt token appears among the logprobs
|
||||
assert prompt_token_id in prompt_logprobs
|
||||
token_in_topk = (
|
||||
prompt_logprobs[prompt_token_id].rank <= num_top_prompt_logprobs
|
||||
)
|
||||
prompt_rank = prompt_logprobs[prompt_token_id].rank
|
||||
assert prompt_rank is not None
|
||||
token_in_topk = prompt_rank <= num_top_prompt_logprobs
|
||||
|
||||
# If the prompt token is not included in the top K
|
||||
# logprob, it can return 1 more data
|
||||
@@ -294,9 +301,10 @@ def _run_and_validate(
|
||||
# 1:.
|
||||
vllm_prompt_logprobs = vllm_result.prompt_logprobs[1:]
|
||||
for i, vllm_prompt_logprob_dict in enumerate(vllm_prompt_logprobs):
|
||||
for token_id, logprob in vllm_prompt_logprob_dict.items():
|
||||
assert vllm_prompt_logprob_dict is not None
|
||||
for token_id, prompt_lp in vllm_prompt_logprob_dict.items():
|
||||
torch.testing.assert_close(
|
||||
logprob.logprob,
|
||||
prompt_lp.logprob,
|
||||
hf_logprob[0][i][token_id].item(),
|
||||
atol=2e-2,
|
||||
rtol=2e-2,
|
||||
@@ -478,12 +486,12 @@ def test_prompt_logprob_token_ids_require_v2_model_runner():
|
||||
params = SamplingParams(prompt_logprob_token_ids=[1, 2])
|
||||
with patch.object(SamplingParams, "verify"):
|
||||
with pytest.raises(VLLMValidationError, match="V2 model runner"):
|
||||
InputProcessor._validate_params(processor, params, ("generate",))
|
||||
InputProcessor._validate_params(processor, params, ("generate",)) # type: ignore[arg-type]
|
||||
processor.vllm_config.use_v2_model_runner = True
|
||||
InputProcessor._validate_params(processor, params, ("generate",))
|
||||
InputProcessor._validate_params(processor, params, ("generate",)) # type: ignore[arg-type]
|
||||
processor.vllm_config.cache_config.kv_sharing_fast_prefill = True
|
||||
with pytest.raises(VLLMValidationError, match="fast-prefill"):
|
||||
InputProcessor._validate_params(processor, params, ("generate",))
|
||||
InputProcessor._validate_params(processor, params, ("generate",)) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_none_logprobs(vllm_model, example_prompts):
|
||||
@@ -607,7 +615,9 @@ def test_logprobs_mode(logprobs_mode: LogprobsMode):
|
||||
total_token_with_logprobs = 0
|
||||
positive_values = 0
|
||||
for output in results[0].outputs:
|
||||
assert output.logprobs is not None
|
||||
for logprobs in output.logprobs:
|
||||
assert logprobs is not None
|
||||
for token_id in logprobs:
|
||||
logprob = logprobs[token_id]
|
||||
if logprobs_mode in ("raw_logprobs", "processed_logprobs"):
|
||||
@@ -648,6 +658,7 @@ def test_prompt_logprobs_mode():
|
||||
)
|
||||
assert results[0].prompt_logprobs is not None
|
||||
assert results[0].prompt_logprobs[1] is not None
|
||||
assert results[0].prompt_token_ids is not None
|
||||
tok_id = results[0].prompt_token_ids[1]
|
||||
values[mode] = results[0].prompt_logprobs[1][tok_id].logprob
|
||||
finally:
|
||||
@@ -1228,10 +1239,12 @@ def test_spec_decode_logprobs(
|
||||
[prompt, prompt], [sampling_params, penalty_sampling_params]
|
||||
)
|
||||
# Collect logprobs outputs from reference LLM.
|
||||
ref_logprobs = []
|
||||
ref_logprobs: list[Logprob] = []
|
||||
for results in ref_results:
|
||||
for output in results.outputs:
|
||||
assert output.logprobs is not None
|
||||
for logprobs in output.logprobs:
|
||||
assert logprobs is not None
|
||||
ref_logprobs.extend(logprobs.values())
|
||||
del ref_llm
|
||||
torch.accelerator.empty_cache()
|
||||
@@ -1249,10 +1262,12 @@ def test_spec_decode_logprobs(
|
||||
[prompt, prompt], [sampling_params, penalty_sampling_params]
|
||||
)
|
||||
# Collect logprobs outputs from spec decode LLM.
|
||||
spec_logprobs = []
|
||||
spec_logprobs: list[Logprob] = []
|
||||
for results in spec_results:
|
||||
for output in results.outputs:
|
||||
assert output.logprobs is not None
|
||||
for logprobs in output.logprobs:
|
||||
assert logprobs is not None
|
||||
spec_logprobs.extend(logprobs.values())
|
||||
del spec_llm
|
||||
torch.accelerator.empty_cache()
|
||||
@@ -1326,6 +1341,7 @@ def test_prompt_logprobs_with_chunking_and_preemption():
|
||||
"Unexpected number of prompt logprob positions"
|
||||
)
|
||||
|
||||
assert sampling_params.prompt_logprobs is not None
|
||||
# Each position should have the requested number of logprobs
|
||||
for pos, logprobs_dict in enumerate(prompt_logprobs):
|
||||
if logprobs_dict is not None: # First token may be None
|
||||
|
||||
Reference in New Issue
Block a user