Skip to content

Commit 483ab7e

Browse files
committed
Fix displaying custom predictors (#7)
* Handle custom predictors Signed-off-by: Mark Winter <[email protected]> * Change return type to PredictorType Signed-off-by: Mark Winter <[email protected]>
1 parent c756bfd commit 483ab7e

File tree

5 files changed

+52
-71
lines changed

5 files changed

+52
-71
lines changed

frontend/src/app/pages/index/index.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { MWABackendService } from 'src/app/services/backend.service';
33
import { Clipboard } from '@angular/cdk-experimental/clipboard';
44
import {
5-
PredictorSpec,
65
InferenceServiceK8s,
76
InferenceServiceIR,
87
} from 'src/app/types/kfserving/v1beta1';
@@ -186,9 +185,10 @@ export class IndexComponent implements OnInit, OnDestroy {
186185
svc.ui.actions.copy = this.getCopyActionStatus(svc);
187186
svc.ui.actions.delete = this.getDeletionActionStatus(svc);
188187

188+
const predictorType = getPredictorType(svc.spec.predictor);
189189
const predictor = getPredictorExtensionSpec(svc.spec.predictor);
190190

191-
svc.ui.predictorType = getPredictorType(svc.spec.predictor);
191+
svc.ui.predictorType = predictorType;
192192
svc.ui.runtimeVersion = predictor.runtimeVersion;
193193
svc.ui.storageUri = predictor.storageUri;
194194
svc.ui.protocolVersion = predictor.protocolVersion;

frontend/src/app/pages/server-info/details/predictor/predictor.component.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
{{ basePredictor?.storageUri }}
33
</lib-details-list-item>
44

5-
<lib-details-list-item key="Runtime">
6-
{{ predictorType }} {{ basePredictor.runtimeVersion }}
5+
<lib-details-list-item key="Predictor">
6+
{{ predictorType }}
77
</lib-details-list-item>
88

9-
<lib-details-list-item
10-
key="Protocol version"
11-
*ngIf="basePredictor.protocolVersion"
12-
>
9+
<lib-details-list-item key="Runtime" *ngIf="basePredictor?.runtimeVersion">
10+
{{ basePredictor.runtimeVersion }}
11+
</lib-details-list-item>
12+
13+
<lib-details-list-item key="Protocol Version" *ngIf="basePredictor?.protocolVersion">
1314
{{ basePredictor.protocolVersion }}
1415
</lib-details-list-item>
1516

frontend/src/app/pages/server-info/overview/overview.component.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
{{ basePredictor?.storageUri }}
2222
</lib-details-list-item>
2323

24-
<lib-details-list-item key="Runtime">
25-
{{ predictorType }} {{ basePredictor.runtimeVersion }}
24+
<lib-details-list-item key="Predictor">
25+
{{ predictorType }}
2626
</lib-details-list-item>
2727

28-
<lib-details-list-item key="Protocol Version">
28+
<lib-details-list-item key="Runtime" *ngIf="basePredictor?.runtimeVersion">
29+
{{ basePredictor.runtimeVersion }}
30+
</lib-details-list-item>
31+
32+
<lib-details-list-item key="Protocol Version" *ngIf="basePredictor?.protocolVersion">
2933
{{ basePredictor.protocolVersion }}
3034
</lib-details-list-item>
3135

frontend/src/app/shared/utils.ts

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { V1Container } from '@kubernetes/client-node';
33
import {
44
InferenceServiceK8s,
55
PredictorSpec,
6+
PredictorType,
67
PredictorExtensionSpec,
78
ExplainerSpec,
89
} from '../types/kfserving/v1beta1';
@@ -107,78 +108,41 @@ export function getK8sObjectStatus(obj: K8sObject): [string, string] {
107108
}
108109

109110
// functions for processing the InferenceService spec
110-
export function getPredictorType(predictor: PredictorSpec): string {
111-
if ('tensorflow' in predictor) {
112-
return 'Tensorflow';
113-
}
114-
115-
if ('triton' in predictor) {
116-
return 'Triton';
117-
}
118-
119-
if ('sklearn' in predictor) {
120-
return 'SKLearn';
121-
}
122-
123-
if ('onnx' in predictor) {
124-
return 'Onnx';
125-
}
126-
127-
if ('pytorch' in predictor) {
128-
return 'PyTorch';
129-
}
130-
131-
if ('xgboost' in predictor) {
132-
return 'XGBoost';
133-
}
134-
135-
if ('pmml' in predictor) {
136-
return 'PMML';
137-
}
138-
139-
if ('lightgbm' in predictor) {
140-
return 'LightGBM';
111+
export function getPredictorType(predictor: PredictorSpec): PredictorType {
112+
for (const predictorType of Object.values(PredictorType)) {
113+
if (predictorType in predictor) {
114+
return predictorType;
115+
}
141116
}
142117

143-
return 'Custom';
118+
return PredictorType.Custom;
144119
}
145120

146121
export function getPredictorExtensionSpec(
147122
predictor: PredictorSpec,
148123
): PredictorExtensionSpec {
149-
if ('tensorflow' in predictor) {
150-
return predictor.tensorflow;
151-
}
152-
153-
if ('triton' in predictor) {
154-
return predictor.triton;
155-
}
156-
157-
if ('sklearn' in predictor) {
158-
return predictor.sklearn;
159-
}
160-
161-
if ('onnx' in predictor) {
162-
return predictor.onnx;
163-
}
164-
165-
if ('pytorch' in predictor) {
166-
return predictor.pytorch;
124+
for (const predictorType of Object.values(PredictorType)) {
125+
if (predictorType in predictor) {
126+
return predictor[predictorType];
127+
}
167128
}
168129

169-
if ('xgboost' in predictor) {
170-
return predictor.xgboost;
171-
}
130+
// In the case of Custom predictors, set the additional PredictorExtensionSpec fields
131+
// manually here
132+
const spec = predictor.containers[0] as PredictorExtensionSpec;
133+
spec.runtimeVersion = '';
134+
spec.protocolVersion = '';
172135

173-
if ('pmml' in predictor) {
174-
return predictor.pmml;
175-
}
176-
177-
if ('lightgbm' in predictor) {
178-
return predictor.lightgbm;
136+
if (predictor.containers[0].env) {
137+
const storageUri = predictor.containers[0].env.find(
138+
envVar => envVar.name.toLowerCase() === 'storage_uri'
139+
);
140+
if (storageUri) {
141+
spec.storageUri = storageUri.value;
142+
}
179143
}
180144

181-
return null;
145+
return spec;
182146
}
183147

184148
export function getExplainerContainer(explainer: ExplainerSpec): V1Container {

frontend/src/app/types/kfserving/v1beta1.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ export interface InferenceServiceSpec {
3232
transformer: TransformerSpec;
3333
}
3434

35+
export enum PredictorType {
36+
Tensorflow = 'tensorflow',
37+
Triton = 'triton',
38+
Sklean = 'sklearn',
39+
Onnx = 'onnx',
40+
Pytorch = 'pytorch',
41+
Xgboost = 'xgboost',
42+
Pmml = 'pmml',
43+
Lightgbm = 'lightgbm',
44+
Custom = 'custom',
45+
}
46+
3547
export interface PredictorSpec extends V1PodSpec, ComponentExtensionSpec {
3648
sklearn?: PredictorExtensionSpec;
3749
xgboost?: PredictorExtensionSpec;

0 commit comments

Comments
 (0)