Skip to content

Commit 1da4542

Browse files
authored
Merge branch 'develop' into develop
2 parents ff91f8b + 498ac6a commit 1da4542

34 files changed

Lines changed: 5830 additions & 157 deletions

clipper_admin/clipper_admin/clipper_admin.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ def build_and_deploy_model(self,
281281
for a model can be changed at any time with
282282
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
283283
batch_size : int, optional
284-
The user-defined batch size.
284+
The user-defined query batch size for the model. Replicas of the model will attempt
285+
to process at most `batch_size` queries simultaneously. They may process smaller
286+
batches if `batch_size` queries are not immediately available.
285287
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
286288
replicas of this model.
287289
Raises
@@ -443,7 +445,9 @@ def deploy_model(self,
443445
for a model can be changed at any time with
444446
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
445447
batch_size : int, optional
446-
The user-defined batch size.
448+
The user-defined query batch size for the model. Replicas of the model will attempt
449+
to process at most `batch_size` queries simultaneously. They may process smaller
450+
batches if `batch_size` queries are not immediately available.
447451
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
448452
replicas of this model.
449453
@@ -516,7 +520,9 @@ def register_model(self,
516520
A list of strings annotating the model. These are ignored by Clipper
517521
and used purely for user annotations.
518522
batch_size : int, optional
519-
The user-defined batch size.
523+
The user-defined query batch size for the model. Replicas of the model will attempt
524+
to process at most `batch_size` queries simultaneously. They may process smaller
525+
batches if `batch_size` queries are not immediately available.
520526
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
521527
replicas of this model.
522528

clipper_admin/clipper_admin/deployers/check_and_write_deps.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from conda.api import get_index
33
from conda.base.context import context
44
from conda.exceptions import UnsatisfiableError, NoPackagesFoundError
5+
from requests.exceptions import ChunkedEncodingError
56
import conda.resolve
67
import conda_env.specs as specs
78
import sys
@@ -66,7 +67,15 @@ def check_solvability_write_deps(env_path, directory, platform,
6667
on the container os. Otherwise returns False.
6768
"""
6869

69-
index = get_index(platform=platform)
70+
def get_packages_index(tries=5):
71+
for n in range(tries):
72+
try:
73+
return get_index(platform=platform)
74+
except ChunkedEncodingError as e:
75+
if n == tries - 1:
76+
raise e
77+
78+
index = get_packages_index()
7079
r = conda.resolve.Resolve(index)
7180
spec = specs.detect(filename=env_path)
7281
env = spec.environment

clipper_admin/clipper_admin/deployers/pyspark.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def create_endpoint(
2626
labels=None,
2727
registry=None,
2828
base_image="clipper/pyspark-container:{}".format(__version__),
29-
num_replicas=1):
29+
num_replicas=1,
30+
batch_size=-1):
3031
"""Registers an app and deploys the provided predict function with PySpark model as
3132
a Clipper model.
3233
@@ -79,13 +80,19 @@ def create_endpoint(
7980
The number of replicas of the model to create. The number of replicas
8081
for a model can be changed at any time with
8182
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
83+
batch_size : int, optional
84+
The user-defined query batch size for the model. Replicas of the model will attempt
85+
to process at most `batch_size` queries simultaneously. They may process smaller
86+
batches if `batch_size` queries are not immediately available.
87+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
88+
replicas of this model.
8289
"""
8390

8491
clipper_conn.register_application(name, input_type, default_output,
8592
slo_micros)
8693
deploy_pyspark_model(clipper_conn, name, version, input_type, func,
8794
pyspark_model, sc, base_image, labels, registry,
88-
num_replicas)
95+
num_replicas, batch_size)
8996

9097
clipper_conn.link_model_to_app(name, name)
9198

@@ -101,7 +108,8 @@ def deploy_pyspark_model(
101108
base_image="clipper/pyspark-container:{}".format(__version__),
102109
labels=None,
103110
registry=None,
104-
num_replicas=1):
111+
num_replicas=1,
112+
batch_size=-1):
105113
"""Deploy a Python function with a PySpark model.
106114
107115
The function must take 3 arguments (in order): a SparkSession, the PySpark model, and a list of
@@ -141,7 +149,12 @@ def deploy_pyspark_model(
141149
The number of replicas of the model to create. The number of replicas
142150
for a model can be changed at any time with
143151
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
144-
152+
batch_size : int, optional
153+
The user-defined query batch size for the model. Replicas of the model will attempt
154+
to process at most `batch_size` queries simultaneously. They may process smaller
155+
batches if `batch_size` queries are not immediately available.
156+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
157+
replicas of this model.
145158
146159
Example
147160
-------
@@ -214,7 +227,7 @@ def predict(spark, model, inputs):
214227
# Deploy model
215228
clipper_conn.build_and_deploy_model(name, version, input_type,
216229
serialization_dir, base_image, labels,
217-
registry, num_replicas)
230+
registry, num_replicas, batch_size)
218231

219232
# Remove temp files
220233
shutil.rmtree(serialization_dir)

clipper_admin/clipper_admin/deployers/python.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def create_endpoint(
2222
labels=None,
2323
registry=None,
2424
base_image="clipper/python-closure-container:{}".format(__version__),
25-
num_replicas=1):
25+
num_replicas=1,
26+
batch_size=-1):
2627
"""Registers an application and deploys the provided predict function as a model.
2728
2829
Parameters
@@ -70,12 +71,19 @@ def create_endpoint(
7071
The number of replicas of the model to create. The number of replicas
7172
for a model can be changed at any time with
7273
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
74+
batch_size : int, optional
75+
The user-defined query batch size for the model. Replicas of the model will attempt
76+
to process at most `batch_size` queries simultaneously. They may process smaller
77+
batches if `batch_size` queries are not immediately available.
78+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
79+
replicas of this model.
7380
"""
7481

7582
clipper_conn.register_application(name, input_type, default_output,
7683
slo_micros)
7784
deploy_python_closure(clipper_conn, name, version, input_type, func,
78-
base_image, labels, registry, num_replicas)
85+
base_image, labels, registry, num_replicas,
86+
batch_size)
7987

8088
clipper_conn.link_model_to_app(name, name)
8189

@@ -89,7 +97,8 @@ def deploy_python_closure(
8997
base_image="clipper/python-closure-container:{}".format(__version__),
9098
labels=None,
9199
registry=None,
92-
num_replicas=1):
100+
num_replicas=1,
101+
batch_size=-1):
93102
"""Deploy an arbitrary Python function to Clipper.
94103
95104
The function should take a list of inputs of the type specified by `input_type` and
@@ -125,7 +134,12 @@ def deploy_python_closure(
125134
The number of replicas of the model to create. The number of replicas
126135
for a model can be changed at any time with
127136
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
128-
137+
batch_size : int, optional
138+
The user-defined query batch size for the model. Replicas of the model will attempt
139+
to process at most `batch_size` queries simultaneously. They may process smaller
140+
batches if `batch_size` queries are not immediately available.
141+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
142+
replicas of this model.
129143
130144
Example
131145
-------
@@ -171,6 +185,6 @@ def centered_predict(inputs):
171185
# Deploy function
172186
clipper_conn.build_and_deploy_model(name, version, input_type,
173187
serialization_dir, base_image, labels,
174-
registry, num_replicas)
188+
registry, num_replicas, batch_size)
175189
# Remove temp files
176190
shutil.rmtree(serialization_dir)

clipper_admin/clipper_admin/deployers/pytorch.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def create_endpoint(
2828
labels=None,
2929
registry=None,
3030
base_image="clipper/pytorch-container:{}".format(__version__),
31-
num_replicas=1):
31+
num_replicas=1,
32+
batch_size=-1):
3233
"""Registers an app and deploys the provided predict function with PyTorch model as
3334
a Clipper model.
3435
Parameters
@@ -78,13 +79,19 @@ def create_endpoint(
7879
The number of replicas of the model to create. The number of replicas
7980
for a model can be changed at any time with
8081
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
82+
batch_size : int, optional
83+
The user-defined query batch size for the model. Replicas of the model will attempt
84+
to process at most `batch_size` queries simultaneously. They may process smaller
85+
batches if `batch_size` queries are not immediately available.
86+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
87+
replicas of this model.
8188
"""
8289

8390
clipper_conn.register_application(name, input_type, default_output,
8491
slo_micros)
8592
deploy_pytorch_model(clipper_conn, name, version, input_type, func,
8693
pytorch_model, base_image, labels, registry,
87-
num_replicas)
94+
num_replicas, batch_size)
8895

8996
clipper_conn.link_model_to_app(name, name)
9097

@@ -99,7 +106,8 @@ def deploy_pytorch_model(
99106
base_image="clipper/pytorch-container:{}".format(__version__),
100107
labels=None,
101108
registry=None,
102-
num_replicas=1):
109+
num_replicas=1,
110+
batch_size=-1):
103111
"""Deploy a Python function with a PyTorch model.
104112
Parameters
105113
----------
@@ -133,6 +141,13 @@ def deploy_pytorch_model(
133141
The number of replicas of the model to create. The number of replicas
134142
for a model can be changed at any time with
135143
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
144+
batch_size : int, optional
145+
The user-defined query batch size for the model. Replicas of the model will attempt
146+
to process at most `batch_size` queries simultaneously. They may process smaller
147+
batches if `batch_size` queries are not immediately available.
148+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
149+
replicas of this model.
150+
136151
Example
137152
-------
138153
@@ -185,7 +200,7 @@ def predict(model, inputs):
185200
# Deploy model
186201
clipper_conn.build_and_deploy_model(name, version, input_type,
187202
serialization_dir, base_image, labels,
188-
registry, num_replicas)
203+
registry, num_replicas, batch_size)
189204

190205
# Remove temp files
191206
shutil.rmtree(serialization_dir)

clipper_admin/clipper_admin/deployers/tensorflow.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def create_endpoint(clipper_conn,
2626
labels=None,
2727
registry=None,
2828
base_image="clipper/tf-container:{}".format(__version__),
29-
num_replicas=1):
29+
num_replicas=1,
30+
batch_size=-1):
3031
"""Registers an app and deploys the provided predict function with TensorFlow model as
3132
a Clipper model.
3233
@@ -76,13 +77,19 @@ def create_endpoint(clipper_conn,
7677
The number of replicas of the model to create. The number of replicas
7778
for a model can be changed at any time with
7879
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
80+
batch_size : int, optional
81+
The user-defined query batch size for the model. Replicas of the model will attempt
82+
to process at most `batch_size` queries simultaneously. They may process smaller
83+
batches if `batch_size` queries are not immediately available.
84+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
85+
replicas of this model.
7986
"""
8087

8188
clipper_conn.register_application(name, input_type, default_output,
8289
slo_micros)
8390
deploy_tensorflow_model(clipper_conn, name, version, input_type, func,
8491
tf_sess_or_saved_model_path, base_image, labels,
85-
registry, num_replicas)
92+
registry, num_replicas, batch_size)
8693

8794
clipper_conn.link_model_to_app(name, name)
8895

@@ -97,7 +104,8 @@ def deploy_tensorflow_model(
97104
base_image="clipper/tf-container:{}".format(__version__),
98105
labels=None,
99106
registry=None,
100-
num_replicas=1):
107+
num_replicas=1,
108+
batch_size=-1):
101109
"""Deploy a Python prediction function with a Tensorflow session or saved Tensorflow model.
102110
Parameters
103111
----------
@@ -131,7 +139,12 @@ def deploy_tensorflow_model(
131139
The number of replicas of the model to create. The number of replicas
132140
for a model can be changed at any time with
133141
:py:meth:`clipper.ClipperConnection.set_num_replicas`.
134-
142+
batch_size : int, optional
143+
The user-defined query batch size for the model. Replicas of the model will attempt
144+
to process at most `batch_size` queries simultaneously. They may process smaller
145+
batches if `batch_size` queries are not immediately available.
146+
If the default value of -1 is used, Clipper will adaptively calculate the batch size for individual
147+
replicas of this model.
135148
136149
Example
137150
-------
@@ -239,7 +252,7 @@ def predict(sess, inputs):
239252
# Deploy model
240253
clipper_conn.build_and_deploy_model(name, version, input_type,
241254
serialization_dir, base_image, labels,
242-
registry, num_replicas)
255+
registry, num_replicas, batch_size)
243256

244257
# Remove temp files
245258
shutil.rmtree(serialization_dir)

clipper_admin/clipper_admin/docker/docker_container_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self,
2525
clipper_rpc_port=7000,
2626
redis_ip=None,
2727
redis_port=6379,
28+
prometheus_port=9090,
2829
docker_network="clipper_network",
2930
extra_container_kwargs={}):
3031
"""
@@ -63,6 +64,7 @@ def __init__(self,
6364
else:
6465
self.external_redis = True
6566
self.redis_port = redis_port
67+
self.prometheus_port = prometheus_port
6668
if docker_network is "host":
6769
raise ClipperException(
6870
"DockerContainerManager does not support running Clipper on the "
@@ -156,7 +158,7 @@ def start_clipper(self, query_frontend_image, mgmt_frontend_image,
156158
setup_metric_config(query_frontend_metric_name,
157159
CLIPPER_INTERNAL_METRIC_PORT)
158160
run_metric_image(self.docker_client, self.common_labels,
159-
self.extra_container_kwargs)
161+
self.prometheus_port, self.extra_container_kwargs)
160162

161163
self.connect()
162164

clipper_admin/clipper_admin/docker/docker_metric_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
from ..version import __version__
66

7+
PROM_VERSION = "v2.1.0"
8+
79

810
def ensure_clipper_tmp():
911
"""
@@ -80,15 +82,15 @@ def setup_metric_config(query_frontend_metric_name,
8082
yaml.dump(prom_config, f)
8183

8284

83-
def run_metric_image(docker_client, common_labels, extra_container_kwargs):
85+
def run_metric_image(docker_client, common_labels, prometheus_port,
86+
extra_container_kwargs):
8487
"""
8588
Run the prometheus image.
8689
:param docker_client: The docker client object
8790
:param common_labels: Labels to pass in
8891
:param extra_container_kwargs: Kwargs to pass in.
8992
:return: None
9093
"""
91-
9294
metric_cmd = [
9395
"--config.file=/etc/prometheus/prometheus.yml",
9496
"--storage.tsdb.path=/prometheus",
@@ -98,10 +100,10 @@ def run_metric_image(docker_client, common_labels, extra_container_kwargs):
98100
]
99101
metric_labels = common_labels.copy()
100102
docker_client.containers.run(
101-
"prom/prometheus",
103+
"prom/prometheus:{}".format(PROM_VERSION),
102104
metric_cmd,
103105
name="metric_frontend-{}".format(random.randint(0, 100000)),
104-
ports={'9090/tcp': 9090},
106+
ports={'9090/tcp': prometheus_port},
105107
volumes={
106108
'/tmp/clipper/prometheus.yml': {
107109
'bind': '/etc/prometheus/prometheus.yml',

0 commit comments

Comments
 (0)