1- from typing import Generator
1+ from typing import Generator , Any
22
33import pytest
4+ from ocp_resources .route import Route
5+ from ocp_resources .service import Service
46from pytest import FixtureRequest
57from kubernetes .dynamic import DynamicClient
68from ocp_resources .config_map import ConfigMap
1517from utilities .constants import Labels , Timeout , Annotations
1618
1719
20+ VLLM_EMULATOR : str = "vllm-emulator"
21+ LMEVALJOB_NAME : str = "lmeval-test-job"
22+
23+
1824@pytest .fixture (scope = "function" )
1925def lmevaljob_hf (
2026 admin_client : DynamicClient , model_namespace : Namespace , patched_trustyai_operator_configmap_allow_online : ConfigMap
21- ) -> Generator [LMEvalJob , None , None ]:
27+ ) -> Generator [LMEvalJob , Any , Any ]:
2228 with LMEvalJob (
2329 client = admin_client ,
24- name = "test-job" ,
30+ name = LMEVALJOB_NAME ,
2531 namespace = model_namespace .name ,
2632 model = "hf" ,
2733 model_args = [{"name" : "pretrained" , "value" : "google/flan-t5-base" }],
@@ -44,10 +50,10 @@ def lmevaljob_local_offline(
4450 model_namespace : Namespace ,
4551 patched_trustyai_operator_configmap_allow_online : ConfigMap ,
4652 lmeval_data_downloader_pod : Pod ,
47- ) -> Generator [LMEvalJob , None , None ]:
53+ ) -> Generator [LMEvalJob , Any , Any ]:
4854 with LMEvalJob (
4955 client = admin_client ,
50- name = "lmeval-test" ,
56+ name = LMEVALJOB_NAME ,
5157 namespace = model_namespace .name ,
5258 model = "hf" ,
5359 model_args = [{"name" : "pretrained" , "value" : "/opt/app-root/src/hf_home/flan" }],
@@ -68,7 +74,39 @@ def lmevaljob_local_offline(
6874
6975
7076@pytest .fixture (scope = "function" )
71- def patched_trustyai_operator_configmap_allow_online (admin_client : DynamicClient ) -> Generator [ConfigMap , None , None ]:
77+ def lmevaljob_vllm_emulator (
78+ admin_client : DynamicClient ,
79+ model_namespace : Namespace ,
80+ patched_trustyai_operator_configmap_allow_online : ConfigMap ,
81+ vllm_emulator_deployment : Deployment ,
82+ vllm_emulator_service : Service ,
83+ vllm_emulator_route : Route ,
84+ ) -> Generator [LMEvalJob , Any , Any ]:
85+ with LMEvalJob (
86+ client = admin_client ,
87+ namespace = model_namespace .name ,
88+ name = LMEVALJOB_NAME ,
89+ model = "local-completions" ,
90+ task_list = {"taskNames" : ["arc_easy" ]},
91+ log_samples = True ,
92+ batch_size = "1" ,
93+ allow_online = True ,
94+ allow_code_execution = False ,
95+ outputs = {"pvcManaged" : {"size" : "5Gi" }},
96+ model_args = [
97+ {"name" : "model" , "value" : "emulatedModel" },
98+ {"name" : "base_url" , "value" : f"http://{ vllm_emulator_service .name } :8000/v1/completions" },
99+ {"name" : "num_concurrent" , "value" : "1" },
100+ {"name" : "max_retries" , "value" : "3" },
101+ {"name" : "tokenized_requests" , "value" : "False" },
102+ {"name" : "tokenizer" , "value" : "ibm-granite/granite-guardian-3.1-8b" },
103+ ],
104+ ) as job :
105+ yield job
106+
107+
108+ @pytest .fixture (scope = "function" )
109+ def patched_trustyai_operator_configmap_allow_online (admin_client : DynamicClient ) -> Generator [ConfigMap , Any , Any ]:
72110 namespace : str = py_config ["applications_namespace" ]
73111 trustyai_service_operator : str = "trustyai-service-operator"
74112
@@ -99,7 +137,7 @@ def patched_trustyai_operator_configmap_allow_online(admin_client: DynamicClient
99137@pytest .fixture (scope = "function" )
100138def lmeval_data_pvc (
101139 admin_client : DynamicClient , model_namespace : Namespace
102- ) -> Generator [PersistentVolumeClaim , None , None ]:
140+ ) -> Generator [PersistentVolumeClaim , Any , Any ]:
103141 with PersistentVolumeClaim (
104142 client = admin_client ,
105143 name = "lmeval-data" ,
@@ -117,7 +155,7 @@ def lmeval_data_downloader_pod(
117155 admin_client : DynamicClient ,
118156 model_namespace : Namespace ,
119157 lmeval_data_pvc : PersistentVolumeClaim ,
120- ) -> Generator [Pod , None , None ]:
158+ ) -> Generator [Pod , Any , Any ]:
121159 with Pod (
122160 client = admin_client ,
123161 namespace = model_namespace .name ,
@@ -143,3 +181,76 @@ def lmeval_data_downloader_pod(
143181 ) as pod :
144182 pod .wait_for_status (status = Pod .Status .SUCCEEDED , timeout = Timeout .TIMEOUT_10MIN )
145183 yield pod
184+
185+
186+ @pytest .fixture (scope = "function" )
187+ def vllm_emulator_deployment (
188+ admin_client : DynamicClient , model_namespace : Namespace
189+ ) -> Generator [Deployment , Any , Any ]:
190+ label = {"app" : VLLM_EMULATOR }
191+ with Deployment (
192+ client = admin_client ,
193+ namespace = model_namespace .name ,
194+ name = VLLM_EMULATOR ,
195+ label = label ,
196+ selector = {"matchLabels" : label },
197+ template = {
198+ "metadata" : {
199+ "labels" : {
200+ "app" : VLLM_EMULATOR ,
201+ "maistra.io/expose-route" : "true" ,
202+ },
203+ "name" : VLLM_EMULATOR ,
204+ },
205+ "spec" : {
206+ "containers" : [
207+ {
208+ "image" : "quay.io/trustyai_testing/vllm_emulator"
209+ "@sha256:4214f31bff9de6cc723da23324fb8974cea8abadcab621d85a97a3503cabbdc6" ,
210+ "name" : "vllm-emulator" ,
211+ "securityContext" : {
212+ "allowPrivilegeEscalation" : False ,
213+ "capabilities" : {"drop" : ["ALL" ]},
214+ "seccompProfile" : {"type" : "RuntimeDefault" },
215+ },
216+ }
217+ ]
218+ },
219+ },
220+ replicas = 1 ,
221+ ) as deployment :
222+ yield deployment
223+
224+
225+ @pytest .fixture (scope = "function" )
226+ def vllm_emulator_service (
227+ admin_client : DynamicClient , model_namespace : Namespace , vllm_emulator_deployment : Deployment
228+ ) -> Generator [Service , Any , Any ]:
229+ with Service (
230+ client = admin_client ,
231+ namespace = model_namespace .name ,
232+ name = f"{ VLLM_EMULATOR } -service" ,
233+ ports = [
234+ {
235+ "name" : f"{ VLLM_EMULATOR } -endpoint" ,
236+ "port" : 8000 ,
237+ "protocol" : "TCP" ,
238+ "targetPort" : 8000 ,
239+ }
240+ ],
241+ selector = {"app" : VLLM_EMULATOR },
242+ ) as service :
243+ yield service
244+
245+
246+ @pytest .fixture (scope = "function" )
247+ def vllm_emulator_route (
248+ admin_client : DynamicClient , model_namespace : Namespace , vllm_emulator_service : Service
249+ ) -> Generator [Route , Any , Any ]:
250+ with Route (
251+ client = admin_client ,
252+ namespace = model_namespace .name ,
253+ name = VLLM_EMULATOR ,
254+ service = vllm_emulator_service .name ,
255+ ) as route :
256+ yield route
0 commit comments