| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | import torch |
| 6 | |
| 7 | from vllm.outputs import ( |
| 8 | ClassificationRequestOutput, |
| 9 | EmbeddingRequestOutput, |
| 10 | PoolingOutput, |
| 11 | PoolingRequestOutput, |
| 12 | RequestError, |
| 13 | RequestOutput, |
| 14 | ScoringRequestOutput, |
| 15 | ) |
| 16 | |
| 17 | pytestmark = pytest.mark.cpu_test |
| 18 | |
| 19 | |
| 20 | def test_request_output_forward_compatible(): |
| 21 | output = RequestOutput( |
| 22 | request_id="test_request_id", |
| 23 | prompt="test prompt", |
| 24 | prompt_token_ids=[1, 2, 3], |
| 25 | prompt_logprobs=None, |
| 26 | outputs=[], |
| 27 | finished=False, |
| 28 | example_arg_added_in_new_version="some_value", |
| 29 | ) |
| 30 | assert output is not None |
| 31 | |
| 32 | |
| 33 | @pytest.mark.parametrize( |
| 34 | ("output_type", "empty_value"), |
| 35 | [ |
| 36 | (EmbeddingRequestOutput, []), |
| 37 | (ClassificationRequestOutput, []), |
| 38 | (ScoringRequestOutput, 0.0), |
| 39 | ], |
| 40 | ) |
| 41 | @pytest.mark.skip_global_cleanup |
| 42 | def test_specialized_pooling_outputs_preserve_request_error(output_type, empty_value): |
| 43 | error = RequestError( |
| 44 | code="multimodal_cache_miss", |
| 45 | message="Multi-modal processor cache miss.", |
| 46 | retryable=True, |
| 47 | ) |
| 48 | base_output = PoolingRequestOutput( |
| 49 | request_id="request", |
| 50 | outputs=PoolingOutput(torch.empty(0)), |
| 51 | prompt_token_ids=[1, 2], |
| 52 | num_cached_tokens=0, |
| 53 | finished=True, |
| 54 | error=error, |
| 55 | ) |
| 56 | |
| 57 | output = output_type.from_base(base_output) |
| 58 | |
| 59 | assert output.error is error |
| 60 | value = getattr(output.outputs, "embedding", None) |
| 61 | value = getattr(output.outputs, "probs", value) |
| 62 | value = getattr(output.outputs, "score", value) |
| 63 | assert value == empty_value |