forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
704 lines (643 loc) · 24.9 KB
/
conftest.py
File metadata and controls
704 lines (643 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
import json
from collections.abc import Generator
from typing import Any
import pytest
from kubernetes.dynamic import DynamicClient
from ocp_resources.data_science_cluster import DataScienceCluster
from ocp_resources.deployment import Deployment
from ocp_resources.inference_service import InferenceService
from ocp_resources.lm_eval_job import LMEvalJob
from ocp_resources.namespace import Namespace
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
from ocp_resources.pod import Pod
from ocp_resources.route import Route
from ocp_resources.secret import Secret
from ocp_resources.service import Service
from ocp_resources.serving_runtime import ServingRuntime
from pytest import Config, FixtureRequest
from tests.model_explainability.lm_eval.constants import (
ACCELERATOR_IDENTIFIER,
ARC_EASY_DATASET_IMAGE,
FLAN_T5_IMAGE,
LMEVAL_OCI_REPO,
LMEVAL_OCI_TAG,
)
from tests.model_explainability.lm_eval.utils import get_lmevaljob_pod
from utilities.constants import ApiGroups, KServeDeploymentType, Labels, MinIo, Protocols, RuntimeTemplates, Timeout
from utilities.exceptions import MissingParameter
from utilities.general import b64_encoded_string
from utilities.inference_utils import create_isvc
from utilities.serving_runtime import ServingRuntimeFromTemplate
VLLM_EMULATOR: str = "vllm-emulator"
VLLM_EMULATOR_PORT: int = 8000
LMEVALJOB_NAME: str = "lmeval-test-job"
@pytest.fixture(scope="function")
def lmevaljob_hf(
request: FixtureRequest,
admin_client: DynamicClient,
model_namespace: Namespace,
patched_dsc_lmeval_allow_all: DataScienceCluster,
lmeval_hf_access_token: Secret,
) -> Generator[LMEvalJob]:
with LMEvalJob(
client=admin_client,
name=LMEVALJOB_NAME,
namespace=model_namespace.name,
model="hf",
model_args=[{"name": "pretrained", "value": "rgeada/tiny-untrained-granite"}],
task_list=request.param.get("task_list"),
log_samples=True,
allow_online=True,
allow_code_execution=True,
system_instruction="Be concise. At every point give the shortest acceptable answer.",
chat_template={
"enabled": True,
},
limit="0.01",
pod={
"container": {
"resources": {
"limits": {"cpu": "1", "memory": "8Gi"},
"requests": {"cpu": "1", "memory": "8Gi"},
},
"env": [
{
"name": "HF_TOKEN",
"valueFrom": {
"secretKeyRef": {
"name": "hf-secret",
"key": "HF_ACCESS_TOKEN",
},
},
},
{"name": "HF_ALLOW_CODE_EVAL", "value": "1"},
],
},
},
) as job:
yield job
@pytest.fixture(scope="function")
def lmevaljob_local_offline(
request: FixtureRequest,
admin_client: DynamicClient,
model_namespace: Namespace,
patched_dsc_lmeval_allow_all: DataScienceCluster,
lmeval_data_downloader_pod: Pod,
) -> Generator[LMEvalJob, Any, Any]:
with LMEvalJob(
client=admin_client,
name=LMEVALJOB_NAME,
namespace=model_namespace.name,
model="hf",
model_args=[{"name": "pretrained", "value": "/opt/app-root/src/hf_home/flan"}],
task_list=request.param.get("task_list"),
limit="0.01",
log_samples=True,
offline={"storage": {"pvcName": "lmeval-data"}},
pod={
"container": {
"env": [
{"name": "HF_HUB_VERBOSITY", "value": "debug"},
{"name": "UNITXT_DEFAULT_VERBOSITY", "value": "debug"},
]
}
},
label={Labels.OpenDataHub.DASHBOARD: "true", "lmevaltests": "vllm"},
) as job:
yield job
@pytest.fixture(scope="class")
def oci_credentials_secret(
admin_client: DynamicClient,
oci_registry_host: str,
model_namespace: Namespace,
) -> Generator[Secret, Any, Any]:
"""Create OCI registry data connection for async upload job"""
# Create anonymous dockerconfig for OCI registry (no authentication)
dockerconfig = {
"auths": {
f"{oci_registry_host}": {
"auth": "",
"email": "user@example.com",
}
}
}
data_dict = {
".dockerconfigjson": b64_encoded_string(json.dumps(dockerconfig)),
"ACCESS_TYPE": b64_encoded_string(json.dumps(["Push", "Pull"])),
"OCI_HOST": b64_encoded_string(oci_registry_host),
}
with Secret(
client=admin_client,
name="my-oci-credentials",
namespace=model_namespace.name,
data_dict=data_dict,
label={
Labels.OpenDataHub.DASHBOARD: "true",
Labels.OpenDataHubIo.MANAGED: "true",
},
annotations={
f"{ApiGroups.OPENDATAHUB_IO}/connection-type-ref": "oci-v1",
"openshift.io/display-name": "My OCI Credentials",
},
type="kubernetes.io/dockerconfigjson",
) as secret:
yield secret
@pytest.fixture(scope="function")
def lmevaljob_local_offline_oci(
request: FixtureRequest,
admin_client: DynamicClient,
model_namespace: Namespace,
patched_dsc_lmeval_allow_all: DataScienceCluster,
oci_credentials_secret: Secret,
oci_registry_pod_with_minio: Pod,
lmeval_data_downloader_pod: Pod,
) -> Generator[LMEvalJob, Any, Any]:
with LMEvalJob(
client=admin_client,
name=LMEVALJOB_NAME,
namespace=model_namespace.name,
model="hf",
model_args=[{"name": "pretrained", "value": "/opt/app-root/src/hf_home/flan"}],
task_list=request.param.get("task_list"),
limit="0.01",
log_samples=True,
offline={"storage": {"pvcName": "lmeval-data"}},
pod={
"container": {
"env": [
{"name": "HF_HUB_VERBOSITY", "value": "debug"},
{"name": "UNITXT_DEFAULT_VERBOSITY", "value": "debug"},
]
}
},
label={Labels.OpenDataHub.DASHBOARD: "true", "lmevaltests": "vllm"},
outputs={
"pvcManaged": {"size": "5Gi"},
"oci": {
"registry": {"name": oci_credentials_secret.name, "key": "OCI_HOST"},
"repository": LMEVAL_OCI_REPO,
"tag": LMEVAL_OCI_TAG,
"dockerConfigJson": {"name": oci_credentials_secret.name, "key": ".dockerconfigjson"},
"verifySSL": False,
},
},
) as job:
yield job
@pytest.fixture(scope="function")
def lmevaljob_vllm_emulator(
admin_client: DynamicClient,
model_namespace: Namespace,
patched_dsc_lmeval_allow_all: DataScienceCluster,
vllm_emulator_deployment: Deployment,
vllm_emulator_service: Service,
vllm_emulator_route: Route,
) -> Generator[LMEvalJob, Any, Any]:
with LMEvalJob(
client=admin_client,
namespace=model_namespace.name,
name=LMEVALJOB_NAME,
model="local-completions",
task_list={"taskNames": ["arc_easy"]},
log_samples=True,
batch_size="1",
allow_online=True,
allow_code_execution=False,
outputs={"pvcManaged": {"size": "5Gi"}},
model_args=[
{"name": "model", "value": "emulatedModel"},
{
"name": "base_url",
"value": f"http://{vllm_emulator_service.name}:{VLLM_EMULATOR_PORT!s}/v1/completions",
},
{"name": "num_concurrent", "value": "1"},
{"name": "max_retries", "value": "3"},
{"name": "tokenized_requests", "value": "False"},
{"name": "tokenizer", "value": "ibm-granite/granite-guardian-3.1-8b"},
],
) as job:
yield job
@pytest.fixture(scope="function")
def lmeval_data_pvc(
admin_client: DynamicClient, model_namespace: Namespace
) -> Generator[PersistentVolumeClaim, Any, Any]:
with PersistentVolumeClaim(
client=admin_client,
name="lmeval-data",
namespace=model_namespace.name,
label={"lmevaltests": "vllm"},
accessmodes=PersistentVolumeClaim.AccessMode.RWO,
size="20Gi",
) as pvc:
yield pvc
@pytest.fixture(scope="function")
def lmeval_data_downloader_pod(
request: FixtureRequest,
admin_client: DynamicClient,
model_namespace: Namespace,
lmeval_data_pvc: PersistentVolumeClaim,
) -> Generator[Pod, Any, Any]:
with Pod(
client=admin_client,
namespace=model_namespace.name,
name="lmeval-downloader",
label={"lmevaltests": "vllm"},
security_context={"fsGroup": 1000, "seccompProfile": {"type": "RuntimeDefault"}},
init_containers=[
{
"name": "flan-data-copy-to-pvc",
"image": FLAN_T5_IMAGE,
"command": ["/bin/sh", "-c", "cp --verbose -r /mnt/data/flan /mnt/pvc/flan"],
"securityContext": {
"runAsUser": 1000,
"runAsNonRoot": True,
"allowPrivilegeEscalation": False,
"capabilities": {"drop": ["ALL"]},
},
"volumeMounts": [{"mountPath": "/mnt/pvc", "name": "pvc-volume"}],
}
],
containers=[
{
"name": "dataset-copy-to-pvc",
"image": request.param.get("dataset_image"),
"command": [
"/bin/sh",
"-c",
"cp --verbose -r /mnt/data/datasets /mnt/pvc/datasets && chmod -R g+w /mnt/pvc/datasets",
],
"securityContext": {
"runAsUser": 1000,
"runAsNonRoot": True,
"allowPrivilegeEscalation": False,
"capabilities": {"drop": ["ALL"]},
},
"volumeMounts": [{"mountPath": "/mnt/pvc", "name": "pvc-volume"}],
},
],
restart_policy="Never",
volumes=[{"name": "pvc-volume", "persistentVolumeClaim": {"claimName": "lmeval-data"}}],
) as pod:
pod.wait_for_status(status=Pod.Status.SUCCEEDED, timeout=Timeout.TIMEOUT_20MIN)
yield pod
@pytest.fixture(scope="function")
def vllm_emulator_deployment(
admin_client: DynamicClient, model_namespace: Namespace
) -> Generator[Deployment, Any, Any]:
label = {Labels.Openshift.APP: VLLM_EMULATOR}
with Deployment(
client=admin_client,
namespace=model_namespace.name,
name=VLLM_EMULATOR,
label=label,
selector={"matchLabels": label},
template={
"metadata": {
"labels": {
Labels.Openshift.APP: VLLM_EMULATOR,
"maistra.io/expose-route": "true",
},
"name": VLLM_EMULATOR,
},
"spec": {
"containers": [
{
"image": "quay.io/trustyai_testing/vllm_emulator"
"@sha256:c4bdd5bb93171dee5b4c8454f36d7c42b58b2a4ceb74f29dba5760ac53b5c12d",
"name": "vllm-emulator",
"securityContext": {
"allowPrivilegeEscalation": False,
"capabilities": {"drop": ["ALL"]},
"seccompProfile": {"type": "RuntimeDefault"},
},
}
]
},
},
replicas=1,
) as deployment:
yield deployment
@pytest.fixture(scope="function")
def vllm_emulator_service(
admin_client: DynamicClient, model_namespace: Namespace, vllm_emulator_deployment: Deployment
) -> Generator[Service, Any, Any]:
with Service(
client=admin_client,
namespace=vllm_emulator_deployment.namespace,
name=f"{VLLM_EMULATOR}-service",
ports=[
{
"name": f"{VLLM_EMULATOR}-endpoint",
"port": VLLM_EMULATOR_PORT,
"protocol": Protocols.TCP,
"targetPort": VLLM_EMULATOR_PORT,
}
],
selector={Labels.Openshift.APP: VLLM_EMULATOR},
) as service:
yield service
@pytest.fixture(scope="function")
def vllm_emulator_route(
admin_client: DynamicClient, model_namespace: Namespace, vllm_emulator_service: Service
) -> Generator[Route, Any, Any]:
with Route(
client=admin_client,
namespace=vllm_emulator_service.namespace,
name=VLLM_EMULATOR,
service=vllm_emulator_service.name,
) as route:
yield route
@pytest.fixture(scope="function")
def lmeval_minio_deployment(
admin_client: DynamicClient, minio_namespace: Namespace, pvc_minio_namespace: PersistentVolumeClaim
) -> Generator[Deployment, Any, Any]:
minio_app_label = {"app": MinIo.Metadata.NAME}
# TODO: Unify with minio_llm_deployment fixture once datasets and models are in new model image
with Deployment(
client=admin_client,
name=MinIo.Metadata.NAME,
namespace=minio_namespace.name,
replicas=1,
selector={"matchLabels": minio_app_label},
template={
"metadata": {"labels": minio_app_label},
"spec": {
"volumes": [
{"name": "minio-storage", "persistentVolumeClaim": {"claimName": pvc_minio_namespace.name}}
],
"containers": [
{
"name": MinIo.Metadata.NAME,
"image": "quay.io/minio/minio"
"@sha256:46b3009bf7041eefbd90bd0d2b38c6ddc24d20a35d609551a1802c558c1c958f",
"args": ["server", "/data", "--console-address", ":9001"],
"env": [
{"name": "MINIO_ROOT_USER", "value": MinIo.Credentials.ACCESS_KEY_VALUE},
{"name": "MINIO_ROOT_PASSWORD", "value": MinIo.Credentials.SECRET_KEY_VALUE},
],
"ports": [{"containerPort": MinIo.Metadata.DEFAULT_PORT}, {"containerPort": 9001}],
"volumeMounts": [{"name": "minio-storage", "mountPath": "/data"}],
}
],
},
},
label=minio_app_label,
wait_for_resource=True,
) as deployment:
deployment.wait_for_replicas(timeout=Timeout.TIMEOUT_20MIN)
yield deployment
@pytest.fixture(scope="function")
def lmeval_minio_copy_pod(
admin_client: DynamicClient, minio_namespace: Namespace, lmeval_minio_deployment: Deployment, minio_service: Service
) -> Generator[Pod, Any, Any]:
with Pod(
client=admin_client,
name="copy-to-minio",
namespace=minio_namespace.name,
restart_policy="Never",
volumes=[{"name": "shared-data", "emptyDir": {}}],
init_containers=[
{
"name": "copy-dataset-data",
"image": ARC_EASY_DATASET_IMAGE,
"command": ["/bin/sh", "-c"],
"args": ["cp --verbose -r /mnt/data/datasets /shared/datasets"],
"volumeMounts": [{"name": "shared-data", "mountPath": "/shared"}],
"securityContext": {
"allowPrivilegeEscalation": False,
"capabilities": {"drop": ["ALL"]},
"runAsNonRoot": True,
"seccompProfile": {"type": "RuntimeDefault"},
},
},
{
"name": "copy-flan-model-data",
"image": FLAN_T5_IMAGE,
"command": ["/bin/sh", "-c"],
"args": ["cp --verbose -r /mnt/data/flan /shared/flan"],
"volumeMounts": [{"name": "shared-data", "mountPath": "/shared"}],
"securityContext": {
"allowPrivilegeEscalation": False,
"capabilities": {"drop": ["ALL"]},
"runAsNonRoot": True,
"seccompProfile": {"type": "RuntimeDefault"},
},
},
],
containers=[
{
"name": "minio-uploader",
"image": "quay.io/minio/mc@sha256:470f5546b596e16c7816b9c3fa7a78ce4076bb73c2c73f7faeec0c8043923123",
"command": ["/bin/sh", "-c"],
"args": [
f"export MC_CONFIG_DIR=/shared/.mc && "
f"mc alias set myminio http://{minio_service.name}:{MinIo.Metadata.DEFAULT_PORT} "
f"{MinIo.Credentials.ACCESS_KEY_VALUE} {MinIo.Credentials.SECRET_KEY_VALUE} && "
"mc mb --ignore-existing myminio/models && "
"mc cp --recursive /shared/datasets/ myminio/models/datasets/ && "
"mc cp --recursive /shared/flan/ myminio/models/flan/"
],
"volumeMounts": [{"name": "shared-data", "mountPath": "/shared"}],
"securityContext": {
"allowPrivilegeEscalation": False,
"capabilities": {"drop": ["ALL"]},
"runAsNonRoot": True,
"seccompProfile": {"type": "RuntimeDefault"},
},
}
],
wait_for_resource=True,
) as pod:
pod.wait_for_status(status=Pod.Status.SUCCEEDED, timeout=600)
yield pod
@pytest.fixture(scope="function")
def lmevaljob_s3_offline(
admin_client: DynamicClient,
model_namespace: Namespace,
lmeval_minio_deployment: Deployment,
minio_service: Service,
lmeval_minio_copy_pod: Pod,
minio_data_connection: Secret,
) -> Generator[LMEvalJob, Any, Any]:
with LMEvalJob(
client=admin_client,
name="evaljob-sample",
namespace=model_namespace.name,
model="hf",
model_args=[{"name": "pretrained", "value": "/opt/app-root/src/hf_home/flan"}],
task_list={"taskNames": ["arc_easy"]},
log_samples=True,
allow_online=False,
offline={
"storage": {
"s3": {
"accessKeyId": {"name": minio_data_connection.name, "key": "AWS_ACCESS_KEY_ID"},
"secretAccessKey": {"name": minio_data_connection.name, "key": "AWS_SECRET_ACCESS_KEY"},
"bucket": {"name": minio_data_connection.name, "key": "AWS_S3_BUCKET"},
"endpoint": {"name": minio_data_connection.name, "key": "AWS_S3_ENDPOINT"},
"region": {"name": minio_data_connection.name, "key": "AWS_DEFAULT_REGION"},
"path": "",
"verifySSL": False,
}
}
},
) as job:
yield job
@pytest.fixture(scope="function")
def lmevaljob_hf_pod(admin_client: DynamicClient, lmevaljob_hf: LMEvalJob) -> Generator[Pod, Any, Any]:
yield get_lmevaljob_pod(client=admin_client, lmevaljob=lmevaljob_hf)
@pytest.fixture(scope="function")
def lmevaljob_local_offline_pod(
admin_client: DynamicClient, lmevaljob_local_offline: LMEvalJob
) -> Generator[Pod, Any, Any]:
yield get_lmevaljob_pod(client=admin_client, lmevaljob=lmevaljob_local_offline)
@pytest.fixture(scope="function")
def lmevaljob_local_offline_pod_oci(
admin_client: DynamicClient, lmevaljob_local_offline_oci: LMEvalJob
) -> Generator[Pod, Any, Any]:
yield get_lmevaljob_pod(client=admin_client, lmevaljob=lmevaljob_local_offline_oci)
@pytest.fixture(scope="function")
def lmevaljob_vllm_emulator_pod(
admin_client: DynamicClient, lmevaljob_vllm_emulator: LMEvalJob
) -> Generator[Pod, Any, Any]:
yield get_lmevaljob_pod(client=admin_client, lmevaljob=lmevaljob_vllm_emulator)
@pytest.fixture(scope="function")
def lmevaljob_s3_offline_pod(admin_client: DynamicClient, lmevaljob_s3_offline: LMEvalJob) -> Generator[Pod, Any, Any]:
yield get_lmevaljob_pod(client=admin_client, lmevaljob=lmevaljob_s3_offline)
@pytest.fixture(scope="function")
def lmevaljob_gpu_pod(admin_client: DynamicClient, lmevaljob_gpu: LMEvalJob) -> Generator[Pod, Any, Any]:
yield get_lmevaljob_pod(client=admin_client, lmevaljob=lmevaljob_gpu)
@pytest.fixture(scope="function")
def lmeval_hf_access_token(
admin_client: DynamicClient,
model_namespace: Namespace,
pytestconfig: Config,
) -> Secret:
hf_access_token = pytestconfig.option.hf_access_token
if not hf_access_token:
raise MissingParameter(
"HF access token is not set. "
"Either pass with `--hf-access-token` or set `HF_ACCESS_TOKEN` environment variable"
)
with Secret(
client=admin_client,
name="hf-secret",
namespace=model_namespace.name,
string_data={
"HF_ACCESS_TOKEN": hf_access_token,
},
wait_for_resource=True,
) as secret:
yield secret
# GPU-based vLLM fixtures for SmolLM-1.7B
@pytest.fixture(scope="function")
def lmeval_vllm_serving_runtime(
admin_client: DynamicClient,
model_namespace: Namespace,
vllm_runtime_image: str,
supported_accelerator_type: str | None,
) -> Generator[ServingRuntime]:
"""vLLM ServingRuntime for GPU-based model deployment in LMEval tests."""
# Map accelerator type to runtime template
accelerator_to_template = {
"nvidia": RuntimeTemplates.VLLM_CUDA,
"amd": RuntimeTemplates.VLLM_ROCM,
"gaudi": RuntimeTemplates.VLLM_GAUDI,
}
accelerator_type = supported_accelerator_type.lower() if supported_accelerator_type else "nvidia"
template_name = accelerator_to_template.get(accelerator_type)
if not template_name:
pytest.skip(f"Unsupported accelerator type for vLLM: {supported_accelerator_type}")
with ServingRuntimeFromTemplate(
client=admin_client,
name="lmeval-vllm-runtime",
namespace=model_namespace.name,
template_name=template_name,
deployment_type=KServeDeploymentType.RAW_DEPLOYMENT,
runtime_image=vllm_runtime_image,
support_tgis_open_ai_endpoints=True,
) as serving_runtime:
yield serving_runtime
@pytest.fixture(scope="function")
def lmeval_vllm_inference_service(
admin_client: DynamicClient,
model_namespace: Namespace,
lmeval_vllm_serving_runtime: ServingRuntime,
supported_accelerator_type: str | None,
) -> Generator[InferenceService]:
"""InferenceService for GPU-based model deployment in LMEval tests."""
model_path = "HuggingFaceTB/SmolLM-1.7B"
model_name = "lmeval-model"
# Get the correct GPU identifier based on accelerator type
accelerator_type = supported_accelerator_type.lower() if supported_accelerator_type else "nvidia"
gpu_identifier = ACCELERATOR_IDENTIFIER.get(accelerator_type, Labels.Nvidia.NVIDIA_COM_GPU)
resources = {
"requests": {
"cpu": "2",
"memory": "8Gi",
gpu_identifier: "1",
},
"limits": {
"cpu": "3",
"memory": "8Gi",
gpu_identifier: "1",
},
}
runtime_args = [
f"--model={model_path}",
"--dtype=float16",
"--max-model-len=2048",
]
env_vars = [
{"name": "HF_HUB_OFFLINE", "value": "0"},
{"name": "HF_HUB_ENABLE_HF_TRANSFER", "value": "0"},
]
with create_isvc(
client=admin_client,
name=model_name,
namespace=model_namespace.name,
runtime=lmeval_vllm_serving_runtime.name,
model_format=lmeval_vllm_serving_runtime.instance.spec.supportedModelFormats[0].name,
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
resources=resources,
argument=runtime_args,
model_env_variables=env_vars,
min_replicas=1,
) as inference_service:
yield inference_service
@pytest.fixture(scope="function")
def lmevaljob_gpu(
admin_client: DynamicClient,
model_namespace: Namespace,
lmeval_vllm_inference_service: InferenceService,
) -> Generator[LMEvalJob]:
"""LMEvalJob for evaluating a GPU-deployed model via vLLM."""
model_path = "HuggingFaceTB/SmolLM-1.7B"
model_service = Service(
name=f"{lmeval_vllm_inference_service.name}-predictor",
namespace=lmeval_vllm_inference_service.namespace,
)
with LMEvalJob(
client=admin_client,
namespace=model_namespace.name,
name=LMEVALJOB_NAME,
model="local-completions",
task_list={"taskNames": ["arc_easy"]},
log_samples=True,
batch_size="1",
allow_online=True,
allow_code_execution=False,
outputs={"pvcManaged": {"size": "5Gi"}},
limit="0.01",
model_args=[
{"name": "model", "value": lmeval_vllm_inference_service.name},
{
"name": "base_url",
"value": f"http://{model_service.name}.{model_namespace.name}.svc.cluster.local:80/v1/completions",
},
{"name": "num_concurrent", "value": "1"},
{"name": "max_retries", "value": "3"},
{"name": "tokenized_requests", "value": "False"},
{"name": "tokenizer", "value": model_path},
],
) as lmevaljob:
yield lmevaljob