mirror of
https://github.com/deepseek-ai/DeepInfer.git
synced 2026-10-29 23:37:28 +08:00
add_request() returns None when it drops a request with invalid token ids, but LLM._add_request() ignored the return value, so generate() could return fewer results than the input prompts — silently misaligning results[i] with prompts[i]. Fail loudly with a clear error instead. Co-Authored-By: Kscc <noreply@owtffssent.com>
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import itertools
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from deepinfer.entrypoints.llm import LLM
|
|
from deepinfer.sampling_params import SamplingParams
|
|
|
|
SENTINEL_SEQUENCE = object()
|
|
|
|
|
|
def _llm(add_request_result: object) -> LLM:
|
|
"""A bare LLM whose engine add_request always returns the given result."""
|
|
llm = object.__new__(LLM)
|
|
llm.request_counter = itertools.count()
|
|
llm.llm_engine = SimpleNamespace(
|
|
multi_modal_processor=None,
|
|
add_request=lambda **kwargs: add_request_result,
|
|
)
|
|
return llm
|
|
|
|
|
|
def test_add_request_returns_engine_sequence() -> None:
|
|
llm = _llm(SENTINEL_SEQUENCE)
|
|
|
|
sequence = llm._add_request(prompt=None, sampling_params=SamplingParams(), prompt_token_ids=[1, 2, 3])
|
|
|
|
assert sequence is SENTINEL_SEQUENCE
|
|
|
|
|
|
def test_add_request_raises_when_engine_rejects_request() -> None:
|
|
# add_request returns None when the engine drops the request (e.g. out-of-range
|
|
# prompt token ids). generate() must fail loudly instead of silently returning
|
|
# fewer outputs than input prompts, which would misalign results with prompts.
|
|
llm = _llm(None)
|
|
|
|
with pytest.raises(ValueError, match="rejected by the engine"):
|
|
llm._add_request(prompt=None, sampling_params=SamplingParams(), prompt_token_ids=[1, 2, 3])
|