forked from wanghualei/kfserving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplainer_alibi_test.go
166 lines (154 loc) · 3.99 KB
/
explainer_alibi_test.go
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
package v1alpha2
import (
"fmt"
"github.com/kubeflow/kfserving/pkg/constants"
"github.com/onsi/gomega"
"github.com/onsi/gomega/types"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"strings"
"testing"
)
func TestAlibiExplainer(t *testing.T) {
g := gomega.NewGomegaWithT(t)
allowedAlibiImageVersionsArray := []string{
DefaultAlibiExplainerRuntimeVersion,
}
allowedAlibiImageVersions := strings.Join(allowedAlibiImageVersionsArray, ", ")
scenarios := map[string]struct {
spec AlibiExplainerSpec
matcher types.GomegaMatcher
}{
"AcceptGoodRuntimeVersion": {
spec: AlibiExplainerSpec{
RuntimeVersion: DefaultAlibiExplainerRuntimeVersion,
},
matcher: gomega.Succeed(),
},
"RejectBadRuntimeVersion": {
spec: AlibiExplainerSpec{
RuntimeVersion: "",
},
matcher: gomega.MatchError(fmt.Sprintf(InvalidAlibiRuntimeVersionError, allowedAlibiImageVersions)),
},
}
for name, scenario := range scenarios {
config := &InferenceServicesConfig{
Explainers: &ExplainersConfig{
AlibiExplainer: ExplainerConfig{
ContainerImage: "seldon.io/alibi",
DefaultImageVersion: "latest",
AllowedImageVersions: allowedAlibiImageVersionsArray,
},
},
}
g.Expect(scenario.spec.Validate(config)).Should(scenario.matcher, fmt.Sprintf("Testing %s", name))
}
}
func TestCreateAlibiExplainerContainer(t *testing.T) {
var requestedResource = v1.ResourceRequirements{
Limits: v1.ResourceList{
"cpu": resource.Quantity{
Format: "100",
},
},
Requests: v1.ResourceList{
"cpu": resource.Quantity{
Format: "90",
},
},
}
config := &InferenceServicesConfig{
Explainers: &ExplainersConfig{
AlibiExplainer: ExplainerConfig{
ContainerImage: "seldon.io/alibi",
DefaultImageVersion: "latest",
},
},
}
var spec = AlibiExplainerSpec{
Type: "Anchor",
StorageURI: "gs://someUri",
Resources: requestedResource,
RuntimeVersion: "0.1.0",
}
g := gomega.NewGomegaWithT(t)
expectedContainer := &v1.Container{
Image: "seldon.io/alibi:0.1.0",
Name: constants.InferenceServiceContainerName,
Resources: requestedResource,
Args: []string{
constants.ArgumentModelName,
"someName",
constants.ArgumentPredictorHost,
"predictor.svc.cluster.local",
constants.ArgumentHttpPort,
constants.GetInferenceServiceHttpPort(false),
"--storage_uri",
"/mnt/models",
"Anchor",
},
}
// Test Create with config
container := spec.CreateExplainerContainer("someName", "predictor.svc.cluster.local", false, config)
g.Expect(container).To(gomega.Equal(expectedContainer))
}
func TestCreateAlibiExplainerContainerWithConfig(t *testing.T) {
var requestedResource = v1.ResourceRequirements{
Limits: v1.ResourceList{
"cpu": resource.Quantity{
Format: "100",
},
},
Requests: v1.ResourceList{
"cpu": resource.Quantity{
Format: "90",
},
},
}
config := &InferenceServicesConfig{
Explainers: &ExplainersConfig{
AlibiExplainer: ExplainerConfig{
ContainerImage: "seldon.io/alibi",
DefaultImageVersion: "latest",
},
},
}
var spec = AlibiExplainerSpec{
Type: "AnchorText",
StorageURI: "gs://someUri",
Resources: requestedResource,
RuntimeVersion: "0.1.0",
Config: map[string]string{
"threshold": "0.95",
"use_unk": "False",
"sample_proba": "0.5",
},
}
g := gomega.NewGomegaWithT(t)
expectedContainer := &v1.Container{
Image: "seldon.io/alibi:0.1.0",
Name: constants.InferenceServiceContainerName,
Resources: requestedResource,
Args: []string{
"--model_name",
"someName",
"--predictor_host",
"predictor.svc.cluster.local",
"--http_port",
"8081",
"--storage_uri",
"/mnt/models",
"AnchorText",
"--sample_proba",
"0.5",
"--threshold",
"0.95",
"--use_unk",
"False",
},
}
// Test Create with config
container := spec.CreateExplainerContainer("someName", "predictor.svc.cluster.local", true, config)
g.Expect(container).To(gomega.Equal(expectedContainer))
}