8000 Add ability to install packages + xgboost model deployer + example by RehanSD · Pull Request #431 · ucbrise/clipper · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ability to install packages + xgboost model deployer + example #431

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 20 commits into from
Mar 26, 2018
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
26 changes: 21 additions & 5 deletions clipper_admin/clipper_admin/clipper_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def build_and_deploy_model(self,
labels=None,
container_registry=None,
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this pkgs_to_install command arg to the all of the model deployers in clipper_admin/deployers/.

"""Build a new model container Docker image with the provided data and deploy it as
a model to Clipper.

Expand Down Expand Up @@ -289,6 +290,9 @@ def build_and_deploy_model(self,
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
Raises
------
:py:exc:`clipper.UnconnectedException`
Expand All @@ -298,7 +302,7 @@ def build_and_deploy_model(self,
if not self.connected:
raise UnconnectedException()
image = self.build_model(name, version, model_data_path, base_image,
container_registry)
container_registry, pkgs_to_install)
self.deploy_model(name, version, input_type, image, labels,
num_replicas, batch_size)

Expand All @@ -307,7 +311,8 @@ def build_model(self,
version,
model_data_path,
base_image,
container_registry=None):
container_registry=None,
pkgs_to_install=None):
"""Build a new model container Docker image with the provided data"

This method builds a new Docker image from the provided base image with the local directory specified by
Expand Down Expand Up @@ -341,6 +346,9 @@ def build_model(self,
The Docker container registry to push the freshly built model to. Note
that if you are running Clipper on Kubernetes, this registry must be accesible
to the Kubernetes cluster in order to fetch the container from the registry.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
Returns
-------
str :
Expand All @@ -363,6 +371,11 @@ def build_model(self,

_validate_versioned_model_name(name, version)

run_cmd = ''
if pkgs_to_install:
run_as_lst = 'RUN apt-get -y install build-essential && pip install'.split(
' ')
run_cmd = ' '.join(run_as_lst + pkgs_to_install)
with tempfile.NamedTemporaryFile(
mode="w+b", suffix="tar") as context_file:
# Create build context tarfile
Expand All @@ -371,8 +384,11 @@ def build_model(self,
context_tar.add(model_data_path)
# From https://stackoverflow.com/a/740854/814642
df_contents = six.StringIO(
"FROM {container_name}\nCOPY {data_path} /model/\n".format(
container_name=base_image, data_path=model_data_path))
"FROM {container_name}\nCOPY {data_path} /model/\n{run_command}\n".
format(
container_name=base_image,
data_path=model_data_path,
run_command=run_cmd))
df_tarinfo = tarfile.TarInfo('Dockerfile')
df_contents.seek(0, os.SEEK_END)
df_tarinfo.size = df_contents.tell()
Expand Down
20 changes: 14 additions & 6 deletions clipper_admin/clipper_admin/deployers/mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def create_endpoint(
labels=None,
registry=None,
base_image="clipper/mxnet-container:{}".format(__version__),
num_replicas=1):
num_replicas=1,
pkgs_to_install=None):
"""Registers an app and deploys the provided predict function with MXNet model as
a Clipper model.
Parameters
Expand Down Expand Up @@ -83,6 +84,9 @@ def create_endpoint(
The number of replicas of the model to create. The number of replicas
for a model can be changed at any time with
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.

Note
----
Expand All @@ -97,7 +101,7 @@ def create_endpoint(
slo_micros)
deploy_mxnet_model(clipper_conn, name, version, input_type, func,
mxnet_model, mxnet_data_shapes, base_image, labels,
registry, num_replicas)
registry, num_replicas, pkgs_to_install)

clipper_conn.link_model_to_app(name, name)

Expand All @@ -113,7 +117,8 @@ def deploy_mxnet_model(
base_image="clipper/mxnet-container:{}".format(__version__),
labels=None,
registry=None,
num_replicas=1):
num_replicas=1,
pkgs_to_install=None):
"""Deploy a Python function with a MXNet model.
Parameters
----------
Expand Down Expand Up @@ -152,6 +157,9 @@ def deploy_mxnet_model(
The number of replicas of the model to create. The number of replicas
for a model can be changed at any time with
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.

Note
----
Expand Down Expand Up @@ -216,9 +224,9 @@ def deploy_mxnet_model(
json.dump({"data_shapes": mxnet_data_shapes}, f)

# Deploy model
clipper_conn.build_and_deploy_model(name, version, input_type,
serialization_dir, base_image,
labels, registry, num_replicas)
clipper_conn.build_and_deploy_model(
name, version, input_type, serialization_dir, base_image, labels,
registry, num_replicas, pkgs_to_install)

except Exception as e:
logger.error("Error saving MXNet model: %s" % e)
Expand Down
16 changes: 12 additions & 4 deletions clipper_admin/clipper_admin/deployers/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def create_pytorch_endpoint(clipper_conn,
base_image=None,
num_replicas=1,
onnx_backend="caffe2",
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""This function deploys the prediction function with a PyTorch model.
It serializes the PyTorch model in Onnx format and creates a container that loads it as a Caffe2 model.
Parameters
Expand Down Expand Up @@ -87,13 +88,16 @@ def create_pytorch_endpoint(clipper_conn,
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
"""

clipper_conn.register_application(name, input_type, default_output,
slo_micros)
deploy_pytorch_model(clipper_conn, name, version, input_type, inputs, func,
pytorch_model, base_image, labels, registry,
num_replicas, onnx_backend)
num_replicas, onnx_backend, pkgs_to_install)

clipper_conn.link_model_to_app(name, name)

Expand All @@ -110,7 +114,8 @@ def deploy_pytorch_model(clipper_conn,
registry=None,
num_replicas=1,
onnx_backend="caffe2",
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""This function deploys the prediction function with a PyTorch model.
It serializes the PyTorch model in Onnx format and creates a container that loads it as a Caffe2 model.
Parameters
Expand Down Expand Up @@ -155,6 +160,9 @@ def deploy_pytorch_model(clipper_conn,
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
"""
if base_image is None:
if onnx_backend is "caffe2":
Expand All @@ -172,7 +180,7 @@ def deploy_pytorch_model(clipper_conn,
# Deploy model
clipper_conn.build_and_deploy_model(
name, version, input_type, serialization_dir, base_image, labels,
registry, num_replicas, batch_size)
registry, num_replicas, batch_size, pkgs_to_install)

except Exception as e:
logger.error(
Expand Down
20 changes: 14 additions & 6 deletions clipper_admin/clipper_admin/deployers/pyspark.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def create_endpoint(
registry=None,
base_image="clipper/pyspark-container:{}".format(__version__),
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""Registers an app and deploys the provided predict function with PySpark model as
a Clipper model.

Expand Down Expand Up @@ -86,13 +87,16 @@ def create_endpoint(
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
"""

clipper_conn.register_application(name, input_type, default_output,
slo_micros)
deploy_pyspark_model(clipper_conn, name, version, input_type, func,
pyspark_model, sc, base_image, labels, registry,
num_replicas, batch_size)
num_replicas, batch_size, pkgs_to_install)

clipper_conn.link_model_to_app(name, name)

Expand All @@ -109,7 +113,8 @@ def deploy_pyspark_model(
labels=None,
registry=None,
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""Deploy a Python function with a PySpark model.

The function must take 3 arguments (in order): a SparkSession, the PySpark model, and a list of
Expand Down Expand Up @@ -155,6 +160,9 @@ def deploy_pyspark_model(
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.

Example
-------
Expand Down Expand Up @@ -225,9 +233,9 @@ def predict(spark, model, inputs):
logger.info("Spark model saved")

# Deploy model
clipper_conn.build_and_deploy_model(name, version, input_type,
serialization_dir, base_image, labels,
registry, num_replicas, batch_size)
clipper_conn.build_and_deploy_model(
name, version, input_type, serialization_dir, base_image, labels,
registry, num_replicas, batch_size, pkgs_to_install)

# Remove temp files
shutil.rmtree(serialization_dir)
20 changes: 14 additions & 6 deletions clipper_admin/clipper_admin/deployers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def create_endpoint(
registry=None,
base_image="clipper/python-closure-container:{}".format(__version__),
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""Registers an application and deploys the provided predict function as a model.

Parameters
Expand Down Expand Up @@ -77,13 +78,16 @@ def create_endpoint(
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
"""

clipper_conn.register_application(name, input_type, default_output,
slo_micros)
deploy_python_closure(clipper_conn, name, version, input_type, func,
base_image, labels, registry, num_replicas,
batch_size)
batch_size, pkgs_to_install)

clipper_conn.link_model_to_app(name, name)

Expand All @@ -98,7 +102,8 @@ def deploy_python_closure(
labels=None,
registry=None,
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""Deploy an arbitrary Python function to Clipper.

The function should take a list of inputs of the type specified by `input_type` and
Expand Down Expand Up @@ -140,6 +145,9 @@ def deploy_python_closure(
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.

Example
-------
Expand Down Expand Up @@ -183,8 +191,8 @@ def centered_predict(inputs):
serialization_dir = posixpath.join(*os.path.split(serialization_dir))
logger.info("Python closure saved")
# Deploy function
clipper_conn.build_and_deploy_model(name, version, input_type,
serialization_dir, base_image, labels,
registry, num_replicas, batch_size)
clipper_conn.build_and_deploy_model(
name, version, input_type, serialization_dir, base_image, labels,
registry, num_replicas, batch_size, pkgs_to_install)
# Remove temp files
shutil.rmtree(serialization_dir)
20 changes: 14 additions & 6 deletions clipper_admin/clipper_admin/deployers/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def create_endpoint(
registry=None,
base_image="clipper/pytorch-container:{}".format(__version__),
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""Registers an app and deploys the provided predict function with CEB7 PyTorch model as
a Clipper model.
Parameters
Expand Down Expand Up @@ -85,13 +86,16 @@ def create_endpoint(
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.
"""

clipper_conn.register_application(name, input_type, default_output,
slo_micros)
deploy_pytorch_model(clipper_conn, name, version, input_type, func,
pytorch_model, base_image, labels, registry,
num_replicas, batch_size)
num_replicas, batch_size, pkgs_to_install)

clipper_conn.link_model_to_app(name, name)

Expand All @@ -107,7 +111,8 @@ def deploy_pytorch_model(
labels=None,
registry=None,
num_replicas=1,
batch_size=-1):
batch_size=-1,
pkgs_to_install=None):
"""Deploy a Python function with a PyTorch model.
Parameters
----------
Expand Down Expand Up @@ -147,6 +152,9 @@ def deploy_pytorch_model(
batches if `batch_size` queries are not immediately available.
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
replicas of this model.
pkgs_to_install : list (of strings), optional
A list of the names of packages to install, using pip, in the container.
The names must be strings.

Example
-------
Expand Down Expand Up @@ -198,9 +206,9 @@ def predict(model, inputs):
logger.info("Torch model saved")

# Deploy model
clipper_conn.build_and_deploy_model(name, version, input_type,
serialization_dir, base_image, labels,
registry, num_replicas, batch_size)
clipper_conn.build_and_deploy_model(
name, version, input_type, serialization_dir, base_image, labels,
registry, num_replicas, batch_size, pkgs_to_install)

# Remove temp files
shutil.rmtree(serialization_dir)
Loading
0