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
469 lines (431 loc) · 17.1 KB
/
conftest.py
File metadata and controls
469 lines (431 loc) · 17.1 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
from typing import Any, Generator
import pytest
from kubernetes.dynamic import DynamicClient
from ocp_resources.config_map import ConfigMap
from ocp_resources.deployment import Deployment
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.resource import ResourceEditor
from ocp_resources.route import Route
from ocp_resources.secret import Secret
from ocp_resources.service import Service
from pytest import Config, FixtureRequest
from pytest_testconfig import py_config
from tests.model_explainability.lm_eval.utils import get_lmevaljob_pod
from utilities.constants import Annotations, Labels, MinIo, Protocols, Timeout
from utilities.exceptions import MissingParameter
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_trustyai_operator_configmap_allow_online: ConfigMap,
lmeval_hf_access_token: Secret,
) -> Generator[LMEvalJob, None, None]:
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_trustyai_operator_configmap_allow_online: ConfigMap,
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="function")
def lmevaljob_vllm_emulator(
admin_client: DynamicClient,
model_namespace: Namespace,
patched_trustyai_operator_configmap_allow_online: ConfigMap,
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}:{str(VLLM_EMULATOR_PORT)}/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 patched_trustyai_operator_configmap_allow_online(admin_client: DynamicClient) -> Generator[ConfigMap, Any, Any]:
namespace: str = py_config["applications_namespace"]
trustyai_service_operator: str = "trustyai-service-operator"
configmap: ConfigMap = ConfigMap(
client=admin_client, name=f"{trustyai_service_operator}-config", namespace=namespace, ensure_exists=True
)
with ResourceEditor(
patches={
configmap: {
"metadata": {"annotations": {Annotations.OpenDataHubIo.MANAGED: "false"}},
"data": {
"lmes-allow-online": "true",
"lmes-allow-code-execution": "true",
},
}
}
):
deployment: Deployment = Deployment(
client=admin_client,
name=f"{trustyai_service_operator}-controller-manager",
namespace=namespace,
ensure_exists=True,
)
num_replicas: int = deployment.replicas
deployment.scale_replicas(replica_count=0)
deployment.scale_replicas(replica_count=num_replicas)
deployment.wait_for_replicas()
yield configmap
@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"}},
containers=[
{
"name": "data",
"image": request.param.get("image"),
"command": ["/bin/sh", "-c", "cp -r /mnt/data/. /mnt/pvc/ && 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-data",
"image": "quay.io/trustyai_testing/lmeval-assets-flan-arceasy"
"@sha256:11cc9c2f38ac9cc26c4fab1a01a8c02db81c8f4801b5d2b2b90f90f91b97ac98",
"command": ["/bin/sh", "-c"],
"args": ["cp -r /mnt/data /shared"],
"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": [
# Set a writable config dir to avoid permission errors when running as non-root
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/data/ myminio/models"
],
"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)
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_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 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