Skip to content

Fix tracker key bug #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/deployments/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Serve models at scale.
model_format: <string> # model format, must be "tensorflow" or "onnx" (default: "onnx" if model path ends with .onnx, "tensorflow" if model path ends with .zip)
request_handler: <string> # path to the request handler implementation file, relative to the cortex root
tracker:
key: <string> # json key to track in the response payload
key: <string> # json key to track if the response payload is a dictionary
model_type: <string> # model type, must be "classification" or "regression"
compute:
min_replicas: <int> # minimum number of replicas (default: 1)
Expand Down
8 changes: 3 additions & 5 deletions pkg/operator/api/userconfig/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type API struct {
}

type Tracker struct {
Key string `json:"key" yaml:"key"`
Key *string `json:"key" yaml:"key"`
ModelType ModelType `json:"model_type" yaml:"model_type"`
}

Expand Down Expand Up @@ -72,10 +72,8 @@ var apiValidation = &cr.StructValidation{
DefaultNil: true,
StructFieldValidations: []*cr.StructFieldValidation{
{
StructField: "Key",
StringValidation: &cr.StringValidation{
Required: true,
},
StructField: "Key",
StringPtrValidation: &cr.StringPtrValidation{},
},
{
StructField: "ModelType",
Expand Down
29 changes: 20 additions & 9 deletions pkg/workloads/cortex/lib/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,34 @@ def extract_predicted_values(api, predictions):

tracker = api.get("tracker")
for prediction in predictions:
predicted_value = prediction.get(tracker["key"])
if predicted_value is None:
raise ValueError(
"failed to track key '{}': not found in response payload".format(tracker["key"])
)
if tracker.get("key") is not None:
key = tracker["key"]
if type(prediction) != dict:
raise ValueError(
"failed to track key '{}': expected prediction to be of type dict but found '{}'".format(
key, type(prediction)
)
)
if prediction.get(key) is None:
raise ValueError(
"failed to track key '{}': not found in prediction".format(tracker["key"])
)
predicted_value = prediction[key]
else:
predicted_value = prediction

if tracker["model_type"] == "classification":
if type(predicted_value) != str and type(predicted_value) != int:
raise ValueError(
"failed to track key '{}': expected type 'str' or 'int' but encountered '{}'".format(
tracker["key"], type(predicted_value)
"failed to track classification prediction: expected type 'str' or 'int' but encountered '{}'".format(
type(predicted_value)
)
)
else:
if type(predicted_value) != float and type(predicted_value) != int: # allow ints
raise ValueError(
"failed to track key '{}': expected type 'float' or 'int' but encountered '{}'".format(
tracker["key"], type(predicted_value)
"failed to track regression prediction: expected type 'float' or 'int' but encountered '{}'".format(
type(predicted_value)
)
)
predicted_values.append(predicted_value)
Expand Down