common.py 1.7 KB
Newer Older
1
2
3
4
5
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Common base classes and utilities for engine tests (vLLM, TRT-LLM, etc.)"""

6
import os
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from dataclasses import dataclass
from typing import Any, Callable, List

from tests.utils.deployment_graph import Payload

# Common text prompt used across tests
TEXT_PROMPT = "Tell me a short joke about AI."


@dataclass
class EngineConfig:
    """Base configuration for engine test scenarios"""

    name: str
    directory: str
    script_name: str
    marks: List[Any]
    endpoints: List[str]
    response_handlers: List[Callable[[Any], str]]
    model: str
27
    timeout: int = 600
28
29
30
31
32
33
34
35
    delayed_start: int = 0


def create_payload_for_config(config: EngineConfig) -> Payload:
    """Create a standard payload using the model from the engine config.

    This provides the default implementation for text-only models.
    """
36
37
38
39
40
    expected_response = (
        ["Hello world"]
        if os.getenv("DYNAMO_ENABLE_TEST_LOGITS_PROCESSOR") == "1"
        else ["AI"]
    )
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    return Payload(
        payload_chat={
            "model": config.model,
            "messages": [
                {
                    "role": "user",
                    "content": TEXT_PROMPT,
                }
            ],
            "max_tokens": 150,
            "temperature": 0.1,
            "stream": False,
        },
        payload_completions={
            "model": config.model,
            "prompt": TEXT_PROMPT,
            "max_tokens": 150,
            "temperature": 0.1,
            "stream": False,
        },
        repeat_count=3,
        expected_log=[],
63
        expected_response=expected_response,
64
    )