-
Notifications
You must be signed in to change notification settings - Fork 280
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-143] String/JSON Container Output #134
Conversation
Test FAILed. |
Test FAILed. |
Test FAILed. |
@dcrankshaw This is ready for review. Can you make sure that the tutorial still runs properly? I've verified that it works after rebuilding sklearn container, but I haven't tested with tensorflow due to preexisting import issues on my machine. |
Test PASSed. |
Test PASSed. |
…xpect output yhat type string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcrankshaw Merged the latest develop and addressed your comments. Will add the requested unit test later today
// At minimum, the output contains an unsigned | ||
// integer specifying the number of string | ||
// outputs | ||
int outputLenBytes = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// for storing string lengths. Advance past this segment | ||
// for now | ||
responseBuffer.position(baseStringLengthsPosition + (4 * numOutputs)); | ||
for (int i = 0; i < predictions.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* | ||
* @return The number of bytes written to the buffer | ||
*/ | ||
public int toBytes(ByteBuffer buffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - renamed to encodeUTF8ToBuffer
containers/python/noop_container.py
Outdated
def predict_ints(self, inputs): | ||
return np.array([np.sum(x) for x in inputs], dtype='float32') | ||
def predict_ints(self, input_item): | ||
return str(sum(input_item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We UTF-8 encode them before serialization. See PredictionResponse#add_output
in rpc.py
.
containers/python/rpc.py
Outdated
total_string_length * MAXIMUM_UTF_8_CHAR_LENGTH_BYTES) | ||
self.memview = memoryview(self.output_buffer) | ||
struct.pack_into("<I", self.output_buffer, 0, num_outputs) | ||
self.string_content_end_position = 4 + (4 * num_outputs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/frontends/src/query_frontend.hpp
Outdated
// If the string output is not JSON-formatted, include | ||
// it as a raw string in the query response | ||
clipper::json::add_string(json_response, PREDICTION_RESPONSE_KEY_OUTPUT, | ||
query_response.output_.y_hat_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, if I'm not mistaken, the json::add_string
method should take care of this for us. I'll change the documentation to this effect.
Test FAILed. |
Test FAILed. |
Test PASSed. |
Test PASSed. |
Test PASSed. |
Test FAILed. |
Test FAILed. |
That may be true, but this is one place where it's critical to the whole purpose of the system to enable these batch-optimizations. Otherwise Clipper is a non-starter for any models that need to run on the GPU or use BLAS libraries. I also don't think it's a huge added burden on the developer. |
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay this looks good to me. Add a comment about the batch-prediction interface and I'll wait for unit tests to pass then this is good to go.
* @return A JSON-formatted serializable string to be | ||
* returned to Clipper as a prediction result | ||
*/ | ||
public abstract SerializableString predict(I inputVector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Corey-Zumar Note that Model.predict
should actually take the full batch of input vectors at once, rather than having the RPC system call predict
in a for-loop. This allows models to apply batch processing optimizations if they want. E.g. this is particularly critical for the tensorflow model when running on a GPU.
I fixed this in the Python code but I'm leaving it as-is for now in the Java container code. I have a fix for this as part of my re-org of the Java codebase in #133.
List<Float> eventCodes = new ArrayList<>(); | ||
for (int i = 0; i < eventHistory.length; i++) { | ||
// Begin building a JSON array | ||
StringBuilder eventCodeJson = new StringBuilder("["); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, don't manually construct JSON. Use a json serialization library.
@@ -2,7 +2,7 @@ FROM clipper/py-rpc:latest | |||
|
|||
MAINTAINER Dan Crankshaw <dscrankshaw@gmail.com> | |||
|
|||
RUN pip install tensorflow | |||
RUN pip install tensorflow==1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to make sure that the tensorflow version is compatible with our pre-trained model
Test PASSed. |
No description provided.