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
135 lines (119 loc) · 4.43 KB
/
conftest.py
File metadata and controls
135 lines (119 loc) · 4.43 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
from typing import Generator, Any
import pytest
from kubernetes.dynamic import DynamicClient
from ocp_resources.inference_service import InferenceService
from ocp_resources.namespace import Namespace
from ocp_resources.route import Route
from ocp_resources.secret import Secret
from ocp_resources.serving_runtime import ServingRuntime
from tests.model_explainability.guardrails.constants import AUTOCONFIG_DETECTOR_LABEL
from utilities.certificates_utils import create_ca_bundle_file
from utilities.constants import KServeDeploymentType, RuntimeTemplates
from utilities.inference_utils import create_isvc
from utilities.serving_runtime import ServingRuntimeFromTemplate
GUARDRAILS_ORCHESTRATOR_NAME = "guardrails-orchestrator"
# ServingRuntimes, InferenceServices, and related resources
# for generation and detection models
@pytest.fixture(scope="class")
def huggingface_sr(
admin_client: DynamicClient,
model_namespace: Namespace,
) -> Generator[ServingRuntime, Any, Any]:
with ServingRuntimeFromTemplate(
client=admin_client,
name="guardrails-detector-runtime-prompt-injection",
template_name=RuntimeTemplates.GUARDRAILS_DETECTOR_HUGGINGFACE,
namespace=model_namespace.name,
supported_model_formats=[{"name": "guardrails-detector-huggingface", "autoSelect": True}],
) as serving_runtime:
yield serving_runtime
@pytest.fixture(scope="class")
def prompt_injection_detector_isvc(
admin_client: DynamicClient,
model_namespace: Namespace,
minio_data_connection: Secret,
huggingface_sr: ServingRuntime,
) -> Generator[InferenceService, Any, Any]:
with create_isvc(
client=admin_client,
name="prompt-injection-detector",
namespace=model_namespace.name,
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
model_format="guardrails-detector-huggingface",
runtime=huggingface_sr.name,
storage_key=minio_data_connection.name,
storage_path="deberta-v3-base-prompt-injection-v2",
wait_for_predictor_pods=False,
enable_auth=False,
resources={
"requests": {"cpu": "1", "memory": "2Gi", "nvidia.com/gpu": "0"},
"limits": {"cpu": "1", "memory": "2Gi", "nvidia.com/gpu": "0"},
},
max_replicas=1,
min_replicas=1,
labels={
"opendatahub.io/dashboard": "true",
AUTOCONFIG_DETECTOR_LABEL: "true",
},
) as isvc:
yield isvc
@pytest.fixture(scope="class")
def prompt_injection_detector_route(
admin_client: DynamicClient,
model_namespace: Namespace,
prompt_injection_detector_isvc: InferenceService,
) -> Generator[Route, Any, Any]:
yield Route(
name="prompt-injection-detector-route",
namespace=model_namespace.name,
service=prompt_injection_detector_isvc.name,
wait_for_resource=True,
)
# Other "helper" fixtures
@pytest.fixture(scope="class")
def openshift_ca_bundle_file(
admin_client: DynamicClient,
) -> str:
return create_ca_bundle_file(client=admin_client, ca_type="openshift")
@pytest.fixture(scope="class")
def hap_detector_isvc(
admin_client: DynamicClient,
model_namespace: Namespace,
minio_data_connection: Secret,
huggingface_sr: ServingRuntime,
) -> Generator[InferenceService, Any, Any]:
with create_isvc(
client=admin_client,
name="hap-detector",
namespace=model_namespace.name,
deployment_mode=KServeDeploymentType.RAW_DEPLOYMENT,
model_format="guardrails-detector-huggingface",
runtime=huggingface_sr.name,
storage_key=minio_data_connection.name,
storage_path="granite-guardian-hap-38m",
wait_for_predictor_pods=False,
enable_auth=False,
resources={
"requests": {"cpu": "1", "memory": "4Gi", "nvidia.com/gpu": "0"},
"limits": {"cpu": "1", "memory": "4Gi", "nvidia.com/gpu": "0"},
},
max_replicas=1,
min_replicas=1,
labels={
"opendatahub.io/dashboard": "true",
AUTOCONFIG_DETECTOR_LABEL: "true",
},
) as isvc:
yield isvc
@pytest.fixture(scope="class")
def hap_detector_route(
admin_client: DynamicClient,
model_namespace: Namespace,
hap_detector_isvc: InferenceService,
) -> Generator[Route, Any, Any]:
yield Route(
name="hap-detector-route",
namespace=model_namespace.name,
service=hap_detector_isvc.name,
wait_for_resource=True,
)