Skip to content
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

[CLIPPER-107][CLIPPER-109] Return JSON-formatted responses to prediction queries #116

Merged
merged 31 commits into from
Apr 17, 2017

Conversation

Corey-Zumar
Copy link
Contributor

@Corey-Zumar Corey-Zumar commented Apr 9, 2017

Modifies query frontend and dependent infrastructure to return JSON-formatted responses to prediction queries.

From CLIPPER-107 and the functional spec:

The format of the response body is a JSON object with the following fields:

  • Output (JSON key name “output”): The prediction JSON object.
  • Default used (JSON key name “default”): A boolean set to true if the model did not return in time and the default output was used. False otherwise.

If there is a non-recoverable error during query execution, an error JSON object will be returned instead and the HTTP response code will be set to the most appropriate error code (a 400 or 500 error code). The format of the error is a JSON object with the following fields:

  • Error (JSON key name “error”): The name of the error.
  • Cause (JSON key name “cause”): A string describing the source of the error.

Note: This PR is currently based on the branch corresponding to #89. As a result, many changes from #89 are redundantly included here.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/129/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/130/
Test PASSed.

@dcrankshaw dcrankshaw changed the title [CLIPPER-107][CLIPPER-109] [CLIPPER-107][CLIPPER-109] Return JSON-formatted responses to prediction queries Apr 10, 2017
@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/133/
Test PASSed.

Copy link
Contributor

@dcrankshaw dcrankshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. We should wait for #89 to be merged first.

Does this require any changes to clipper_manager.py or the tutorial (beyond those needed for #89)?

const char* PREDICTION_RESPONSE_KEY_OUTPUT = "output";
const char* PREDICTION_RESPONSE_KEY_USED_DEFAULT = "default";
const char* PREDICTION_ERROR_RESPONSE_KEY_ERROR = "error";
const char* PREDICTION_ERROR_RESPONSE_KEY_CAUSE = "cause";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these char* instead of std::string? (I'm guessing there's a good reason)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our utility methods for adding key-value pairs to JSON objects expect char* keys. There is no implicit cast from std::string to char*, so I've defined the constants this way. Alternatively, I could define these with the std::string type and call .data() to get char* pointers, but this seems less readable.

@@ -6,6 +6,7 @@
#include <tuple>
#include <utility>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add #include <stdexcept> (it's better to explicitly include all the headers needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included stdexept in exceptions.hpp

const long query_id_;
const std::string msg_;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define this in a separate exceptions.hpp file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ss << "Explanation: " << msg_ << std::endl;
return ss.str().data();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to exceptions.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -52,7 +52,7 @@ const std::string APPLICATION_JSON_SCHEMA = R"(
{"model_name" := string, "model_version" := int}
],
"input_type" := "integers" | "bytes" | "floats" | "doubles" | "strings",
"selection_policy" := string,
"default_output" := number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/number/float

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/138/
Test FAILed.

Copy link
Contributor Author

@Corey-Zumar Corey-Zumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcrankshaw Addressed your comments - moved PredictError to separate exceptions.hpp and exceptions.cpp files.

@@ -52,7 +52,7 @@ const std::string APPLICATION_JSON_SCHEMA = R"(
{"model_name" := string, "model_version" := int}
],
"input_type" := "integers" | "bytes" | "floats" | "doubles" | "strings",
"selection_policy" := string,
"default_output" := number,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/139/
Test PASSed.

@dcrankshaw
Copy link
Contributor

LGTM. We need to wait on #115 and then #89 before merging this though

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/142/
Test PASSed.

UNREACHABLE();
}
std::pair<Output, bool> final_output =
current_policy->combine_predictions(selection_state, query, outputs);
std::chrono::time_point<std::chrono::high_resolution_clock> end =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Corey-Zumar Can you add a ratio counter here that tracks the fraction of predictions that use the default output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/147/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/148/
Test PASSed.

@Corey-Zumar
Copy link
Contributor Author

@dcrankshaw Rebased on develop. Please take another look over the code and confirm that the tutorial runs properly before merging - it's working well for me.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/149/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/150/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/151/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Clipper-PRB/152/
Test PASSed.

@dcrankshaw
Copy link
Contributor

LGTM. Confirming that the tutorial works for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants