|
| 1 | +""" |
| 2 | +Test module for Python model served by Triton via KServe. |
| 3 | +
|
| 4 | +Validates inference using REST and gRPC protocols with both raw and serverless deployment modes. |
| 5 | +""" |
| 6 | + |
| 7 | +from typing import Any |
| 8 | + |
| 9 | +import pytest |
| 10 | +from ocp_resources.inference_service import InferenceService |
| 11 | +from ocp_resources.pod import Pod |
| 12 | +from simple_logger.logger import get_logger |
| 13 | + |
| 14 | +from utilities.constants import Protocols |
| 15 | +from tests.model_serving.model_runtime.triton.basic_model_deployment.utils import validate_inference_request, load_json |
| 16 | +from tests.model_serving.model_runtime.triton.constant import ( |
| 17 | + BASE_RAW_DEPLOYMENT_CONFIG, |
| 18 | + BASE_SERVERLESS_DEPLOYMENT_CONFIG, |
| 19 | + MODEL_PATH_PREFIX, |
| 20 | + TRITON_GRPC_PYTHON_INPUT_PATH, |
| 21 | + TRITON_REST_PYTHON_INPUT_PATH, |
| 22 | +) |
| 23 | + |
| 24 | +LOGGER = get_logger(name=__name__) |
| 25 | + |
| 26 | +PYTHON_MODEL_NAME = "python" |
| 27 | + |
| 28 | +MODEL_STORAGE_URI_DICT = {"model-dir": f"{MODEL_PATH_PREFIX}"} |
| 29 | + |
| 30 | +pytestmark = pytest.mark.usefixtures( |
| 31 | + "root_dir", "valid_aws_config", "triton_rest_serving_runtime_template", "triton_grpc_serving_runtime_template" |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize( |
| 36 | + ("protocol", "model_namespace", "s3_models_storage_uri", "triton_serving_runtime", "triton_inference_service"), |
| 37 | + [ |
| 38 | + pytest.param( |
| 39 | + {"protocol_type": Protocols.REST}, |
| 40 | + {"name": "python-raw"}, |
| 41 | + MODEL_STORAGE_URI_DICT, |
| 42 | + {**BASE_RAW_DEPLOYMENT_CONFIG}, |
| 43 | + { |
| 44 | + "name": "python-raw-rest", |
| 45 | + **BASE_RAW_DEPLOYMENT_CONFIG, |
| 46 | + }, |
| 47 | + id="python-raw-rest-deployment", |
| 48 | + ), |
| 49 | + pytest.param( |
| 50 | + {"protocol_type": Protocols.GRPC}, |
| 51 | + {"name": "python-raw"}, |
| 52 | + MODEL_STORAGE_URI_DICT, |
| 53 | + {**BASE_RAW_DEPLOYMENT_CONFIG}, |
| 54 | + { |
| 55 | + "name": "python-raw-grpc", |
| 56 | + **BASE_RAW_DEPLOYMENT_CONFIG, |
| 57 | + }, |
| 58 | + id="python-raw-grpc-deployment", |
| 59 | + ), |
| 60 | + pytest.param( |
| 61 | + {"protocol_type": Protocols.REST}, |
| 62 | + {"name": "python-serverless"}, |
| 63 | + MODEL_STORAGE_URI_DICT, |
| 64 | + {**BASE_SERVERLESS_DEPLOYMENT_CONFIG}, |
| 65 | + { |
| 66 | + "name": "python-serverless-rest", |
| 67 | + **BASE_SERVERLESS_DEPLOYMENT_CONFIG, |
| 68 | + }, |
| 69 | + id="python-serverless-rest-deployment", |
| 70 | + ), |
| 71 | + pytest.param( |
| 72 | + {"protocol_type": Protocols.GRPC}, |
| 73 | + {"name": "python-serverless"}, |
| 74 | + MODEL_STORAGE_URI_DICT, |
| 75 | + {**BASE_SERVERLESS_DEPLOYMENT_CONFIG}, |
| 76 | + { |
| 77 | + "name": "python-serverless-grpc", |
| 78 | + **BASE_SERVERLESS_DEPLOYMENT_CONFIG, |
| 79 | + }, |
| 80 | + id="python-serverless-grpc-deployment", |
| 81 | + ), |
| 82 | + ], |
| 83 | + indirect=True, |
| 84 | +) |
| 85 | +class TestPythonModel: |
| 86 | + """ |
| 87 | + Test class for python inference using Triton on KServe. |
| 88 | +
|
| 89 | + Covers: |
| 90 | + - REST and gRPC protocols |
| 91 | + - Raw and serverless modes |
| 92 | + - Snapshot validation of inference results |
| 93 | + """ |
| 94 | + |
| 95 | + def test_python_inference( |
| 96 | + self, |
| 97 | + triton_inference_service: InferenceService, |
| 98 | + triton_pod_resource: Pod, |
| 99 | + triton_response_snapshot: Any, |
| 100 | + protocol: str, |
| 101 | + root_dir: str, |
| 102 | + ) -> None: |
| 103 | + """ |
| 104 | + Run inference and validate against snapshot. |
| 105 | +
|
| 106 | + Args: |
| 107 | + triton_inference_service: The deployed InferenceService object |
| 108 | + triton_pod_resource: The pod running the model server |
| 109 | + triton_response_snapshot: Expected response snapshot |
| 110 | + protocol: REST or gRPC |
| 111 | + root_dir: Root directory for test execution |
| 112 | + """ |
| 113 | + input_path = TRITON_GRPC_PYTHON_INPUT_PATH if protocol == Protocols.GRPC else TRITON_REST_PYTHON_INPUT_PATH |
| 114 | + input_query = load_json(path=input_path) |
| 115 | + |
| 116 | + validate_inference_request( |
| 117 | + pod_name=triton_pod_resource.name, |
| 118 | + isvc=triton_inference_service, |
| 119 | + response_snapshot=triton_response_snapshot, |
| 120 | + input_query=input_query, |
| 121 | + model_name=PYTHON_MODEL_NAME, |
| 122 | + protocol=protocol, |
| 123 | + root_dir=root_dir, |
| 124 | + ) |
0 commit comments