Skip to content

Keras deployer#594

Merged
simon-mo merged 21 commits intoucbrise:developfrom
eavidan:keras_deployer
May 28, 2019
Merged

Keras deployer#594
simon-mo merged 21 commits intoucbrise:developfrom
eavidan:keras_deployer

Conversation

@eavidan
Copy link
Copy Markdown
Contributor

@eavidan eavidan commented Nov 1, 2018

Based on the tensorflow deployer, I have implemented this Keras deployer
Currentlly a docker build command needs to be run to create the keras-container image

docker build -f dockerfiles/KerasDockerfile -t keras-container .

This is until build_docker_images.sh will be updated with the build commands

a working example would be:

from clipper_admin import ClipperConnection, DockerContainerManager
from clipper_admin.deployers import keras as keras_deployer
import keras

# run this first
# docker build -f dockerfiles/KerasDockerfile -t keras-container .

# creating a simple Keras model
inpt = keras.layers.Input(shape=(1,))
out = keras.layers.multiply([inpt, inpt])
model = keras.models.Model(inputs=inpt, outputs=out)

clipper_conn = ClipperConnection(DockerContainerManager())

# Connect to an already-running Clipper cluster
clipper_conn.connect()

def predict(model, inputs):
    return [model.predict(x) for x in inputs]

keras_deployer.deploy_keras_model(clipper_conn=clipper_conn, 
    name="pow", 
    version="1",
    input_type="ints", 
    func=predict, 
    model_path_or_object=model, 
    base_image='keras-container')

# sending an inference request
import requests
import json

req_json = json.dumps({
    "input": [1, 2, 4, 6]
})

headers = {"Content-type": "application/json"}
response = requests.post("http://localhost:1337/keras-pow/predict", headers=headers,
    data=req_json)

currently need to run the docker build before using the deployer
`docker build -f dockerfiles/KerasDockerfile -t keras-container .`
The build commands will be added to the build_docker_images.sh
@AmplabJenkins
Copy link
Copy Markdown

Can one of the admins verify this patch?

@simon-mo
Copy link
Copy Markdown
Contributor

simon-mo commented Nov 7, 2018

- exception is raised when model_path_or_object passed to keras deployer is neither a Model object or an *.h5 file
@eavidan
Copy link
Copy Markdown
Contributor Author

eavidan commented Nov 7, 2018

just pushed an integration test and a small exception for the model validation part
should I add the following lines to build_docker_images?

create_image keras-container KerasDockerfile $public py &
create_image keras35-container KerasDockerfile $public py35 &
create_image keras36-container KerasDockerfile $public py36 &

@simon-mo
Copy link
Copy Markdown
Contributor

Thanks again! Sorry about the late reply. I can take care of that. We are in the midst of integration testing infrastructure refactoring (#595). I will add building container support to this PR once CI is ready.

@ivrt
Copy link
Copy Markdown

ivrt commented Nov 28, 2018

Hi, I'm trying to run this locally and I am running into an issue running the following command:

docker build -f dockerfiles/KerasDockerfile -t keras-container .

The error message I'm getting is:

pull access denied for clipper-base, repository does not exist or may require 'docker login'

It seems like there is no such image as clipper-base on docker hub. Not super familiar with docker but any ideas what I'm doing wrongly?

@eavidan
Copy link
Copy Markdown
Contributor Author

eavidan commented Nov 28, 2018

my bad
I believe I built it locally from Py2RPCDockerfile

docker build -f dockerfiles/Py2RPCDockerfile -t clipper-base .

@simon-mo, sorry about that. should I update the docker file with FROM ${REGISTRY}/${RPC_VERSION}-rpc:${CODE_VERSION} ?

@simon-mo
Copy link
Copy Markdown
Contributor

Yes please that would be great! In the future, building clipper images will be simpler. But for now this is the correct approach.

@harmw
Copy link
Copy Markdown

harmw commented Feb 16, 2019

Just build a model container using this PR, awesome! One problem we ran into was the keras-container expects to find the .h5 model as a file on the local filesystem, but we packaged it inside our pickled function (func.pkl). Would it make sense having the following added to this PR?

diff --git a/containers/python/keras_container.py b/containers/python/keras_container.py
index e2dd47f..cb96bc9 100644
--- a/containers/python/keras_container.py
+++ b/containers/python/keras_container.py
@@ -27,7 +27,12 @@ class KerasContainer(rpc.ModelContainerBase):
             dir=path, predict_fname=predict_fname)
         self.predict_func = load_predict_func(predict_path)

-        self.model = load_model(os.path.join(path, "keras_model.h5"))
+        model_file = os.path.join(path, "keras_model.h5")
+        if os.path.exists(model_file):
+            self.model = load_model(model_file)
+        else:
+            print("keras_model.h5 not found, it's probably pickled")
+            self.model = None

     def predict_ints(self, inputs):
         preds = self.predict_func(self.model, inputs)

One downside of using the stock deployers is that they build&ship in one step, something we split in a two-stage process. Our pickle step is as simple as just save_python_function(None, make_prediction).

@rkooo567
Copy link
Copy Markdown
Collaborator

@simon-mo Will we merge this PR?

@withsmilo
Copy link
Copy Markdown
Collaborator

@simon-mo @rkooo567
How about try to merge this PR? I think that the Keras deployer is too awesome and many people wait for this.

@simon-mo
Copy link
Copy Markdown
Contributor

We are still missing

  1. Keras integration test
  2. Keras docker container

@rkooo567 do you want to handle that?

@rkooo567
Copy link
Copy Markdown
Collaborator

@simon-mo Sure. I can work on it from 18th.

Btw, I can see the integration test as well as KerasContainer + Dockerfile. Are there any missing parts from those two?

@simon-mo
Copy link
Copy Markdown
Contributor

sorry I mean we need to add them to the CI. So add a line here:

####################
# Model Containers #
####################
models = [
("mxnet{version}", "MXNetContainer"),
("pytorch{version}", "PyTorchContainer"),
("tf{version}", "TensorFlow"),
("pyspark{version}", "PySparkContainer"),
("python{version}-closure", "PyClosureContainer"),
]
py_version = [("", "py"), ("35", "py35"), ("36", "py36")]

and here:

DOCKER_INTEGRATION_TESTS = {
"admin_unit_test": "python /clipper/integration-tests/clipper_admin_tests.py",
"many_apps_many_models": "python /clipper/integration-tests/many_apps_many_models.py",
"pyspark": "python /clipper/integration-tests/deploy_pyspark_models.py",
"pyspark_pipeline": "python /clipper/integration-tests/deploy_pyspark_pipeline_models.py",
"pysparkml": "python /clipper/integration-tests/deploy_pyspark_sparkml_models.py",
"tensorflow": "python /clipper/integration-tests/deploy_tensorflow_models.py",
"mxnet": "python /clipper/integration-tests/deploy_mxnet_models.py",
"pytorch": "python /clipper/integration-tests/deploy_pytorch_models.py",
"multi_tenancy": "python /clipper/integration-tests/multi_tenancy_test.py",
# "rclipper": "/clipper/integration-tests/r_integration_test/rclipper_test.sh",
"docker_metric": "python /clipper/integration-tests/clipper_metric_docker.py",
"fluentd": "python /clipper/integration-tests/clipper_fluentd_logging_docker.py",
}

@rkooo567
Copy link
Copy Markdown
Collaborator

@simon-mo Gotcha! That sounds simple. Let's wait for @eavidan, and see if he can add one more commit first. If he wouldn't appear, I will add them within a few days.

@rkooo567
Copy link
Copy Markdown
Collaborator

Jenkins test this please

@rkooo567 rkooo567 self-assigned this May 14, 2019
@rkooo567 rkooo567 requested review from simon-mo and withsmilo May 14, 2019 09:25
@AmplabJenkins
Copy link
Copy Markdown

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

@rkooo567
Copy link
Copy Markdown
Collaborator

Jenkins test this please

@AmplabJenkins
Copy link
Copy Markdown

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

@rkooo567
Copy link
Copy Markdown
Collaborator

jenkins test this please

@AmplabJenkins
Copy link
Copy Markdown

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

@rkooo567
Copy link
Copy Markdown
Collaborator

jenkins test this please

@AmplabJenkins
Copy link
Copy Markdown

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

@rkooo567
Copy link
Copy Markdown
Collaborator

jenkins test this please

@AmplabJenkins
Copy link
Copy Markdown

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

@AmplabJenkins
Copy link
Copy Markdown

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

@rkooo567
Copy link
Copy Markdown
Collaborator

rkooo567 commented May 26, 2019

@simon-mo So, there are 2 things.

  1. I got this error log.
BuildError: pull access denied for keras-container, repository does not exist or may require 'docker login'

Do I need any additional setup for pulling an image?
EDIT -> I think we should create a repo at https://hub.docker.com/u/clipper/?page=2

  1. Keras log is not organized at http://clipper-jenkins-viewer.herokuapp.com/. Do you need any steps to take to enable it?

Also, it looks like http://clipper-jenkins-viewer.herokuapp.com/ is broken for now?

@rkooo567
Copy link
Copy Markdown
Collaborator

jenkins ok to test

@AmplabJenkins
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

@simon-mo simon-mo left a comment

Choose a reason for hiding this comment

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

lgtm

Comment thread bin/shipyard/clipper_test.cfg.py Outdated
Comment thread dockerfiles/ClipperDevDockerfile Outdated
Comment thread dockerfiles/ClipperPy35DevDockerfile Outdated
Comment thread dockerfiles/KerasContainerDockerfile Outdated
@AmplabJenkins
Copy link
Copy Markdown

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

@rkooo567
Copy link
Copy Markdown
Collaborator

@simon-mo @withsmilo I think it is ready to go. @simon-mo Please add a keras-container repo at dockerhub, so that people can pull the image outside CI environment.

@AmplabJenkins
Copy link
Copy Markdown

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

@simon-mo
Copy link
Copy Markdown
Contributor

@rkooo567 the docker repo will be automatically created when we push to master. I restarted travis.

@simon-mo simon-mo merged commit 03a5178 into ucbrise:develop May 28, 2019
jacekwachowiak added a commit to jacekwachowiak/clipper that referenced this pull request May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants