Skip to content

Commit d864149

Browse files
authored
Merge branch 'master' into dcgan_fashiongen_example
2 parents b0a7089 + ed15917 commit d864149

28 files changed

+1397
-22
lines changed

.github/workflows/doc-automation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
python3 -m pip install katex
2525
python3 -m pip install sphinxcontrib.katex
2626
python3 -m pip install sphinx_markdown_tables
27+
python3 -m pip install torchserve torch-model-archiver torch-workflow-archiver
2728
- name: Build the docset
2829
run: cd ./docs/sphinx ; export PATH=$PATH:$(python3 -m site --user-base)/bin/ ; make html
2930
id: build

benchmarks/benchmark-ab.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
'docker_runtime': '',
3030
'backend_profiling': False,
3131
'config_properties': 'config.properties',
32-
'inference_model_url': 'predictions/benchmark'
32+
'inference_model_url': 'predictions/benchmark',
33+
'report_location': tempfile.gettempdir()
3334
}
34-
TMP_DIR = tempfile.gettempdir()
35+
36+
TMP_DIR = default_ab_params['report_location']
3537
execution_params = default_ab_params.copy()
3638
result_file = os.path.join(TMP_DIR, "benchmark/result.txt")
3739
metric_log = os.path.join(TMP_DIR, "benchmark/logs/model_metrics.log")
@@ -41,7 +43,6 @@ def json_provider(file_path, cmd_name):
4143
with open(file_path) as config_data:
4244
return json.load(config_data)
4345

44-
4546
@click.command()
4647
@click.argument('test_plan', default='custom')
4748
@click.option('--url', '-u', default='https://torchserve.pytorch.org/mar_files/resnet-18.mar',
@@ -70,7 +71,7 @@ def json_provider(file_path, cmd_name):
7071
@click_config_file.configuration_option(provider=json_provider, implicit=False,
7172
help="Read configuration from a JSON file")
7273
def benchmark(test_plan, url, gpus, exec_env, concurrency, requests, batch_size, batch_delay, input, workers,
73-
content_type, image, docker_runtime, backend_profiling, config_properties, inference_model_url):
74+
content_type, image, docker_runtime, backend_profiling, config_properties, inference_model_url, report_location):
7475
input_params = {'url': url,
7576
'gpus': gpus,
7677
'exec_env': exec_env,
@@ -85,12 +86,14 @@ def benchmark(test_plan, url, gpus, exec_env, concurrency, requests, batch_size,
8586
'docker_runtime': docker_runtime,
8687
'backend_profiling': backend_profiling,
8788
'config_properties': config_properties,
88-
'inference_model_url': inference_model_url
89+
'inference_model_url': inference_model_url,
90+
'report_location': report_location
8991
}
9092

9193
# set ab params
9294
update_plan_params[test_plan]()
9395
update_exec_params(input_params)
96+
9497
click.secho("Starting AB benchmark suite...", fg='green')
9598
click.secho(f"\n\nConfigured execution parameters are:", fg='green')
9699
click.secho(f"{execution_params}", fg="blue")
@@ -122,7 +125,7 @@ def check_torchserve_health():
122125
except Exception as e:
123126
retry += 1
124127
time.sleep(3)
125-
failure_exit("Could not connect to Tochserve instance at " + execution_params['inference_url'])
128+
failure_exit("Could not connect to Torchserve instance at " + execution_params['inference_url'])
126129

127130
def warm_up():
128131
register_model()
@@ -135,7 +138,7 @@ def warm_up():
135138

136139

137140
def run_benchmark():
138-
click.secho("\n\nExecuting inference perfromance tests ...", fg='green')
141+
click.secho("\n\nExecuting inference performance tests ...", fg='green')
139142
ab_cmd = f"ab -c {execution_params['concurrency']} -n {execution_params['requests']} -k -p {TMP_DIR}/benchmark/input -T " \
140143
f"{execution_params['content_type']} {execution_params['inference_url']}/{execution_params['inference_model_url']} > {result_file}"
141144

@@ -208,8 +211,8 @@ def docker_torchserve_start():
208211
if execution_params['backend_profiling']:
209212
backend_profiling = '-e TS_BENCHMARK=True'
210213

211-
# delete existing ts conatiner instance
212-
click.secho("*Removing existing ts conatiner instance...", fg='green')
214+
# delete existing ts container instance
215+
click.secho("*Removing existing ts container instance...", fg='green')
213216
execute('docker rm -f ts', wait=True)
214217

215218
click.secho(f"*Starting docker container of image {docker_image} ...", fg='green')
@@ -308,10 +311,17 @@ def generate_csv_output():
308311
line50 = int(batched_requests / 2)
309312
line90 = int(batched_requests * 9 / 10)
310313
line99 = int(batched_requests * 99 / 100)
314+
315+
click.secho(f"Saving benchmark results to {execution_params['report_location']}")
316+
311317
artifacts = {}
312-
with open(f'{TMP_DIR}/benchmark/result.txt') as f:
318+
with open(f"{execution_params['report_location']}/benchmark/result.txt") as f:
313319
data = f.readlines()
320+
314321
artifacts['Benchmark'] = "AB"
322+
artifacts['Batch size'] = execution_params['batch_size']
323+
artifacts['Batch delay'] = execution_params['batch_delay']
324+
artifacts['Workers'] = execution_params['workers']
315325
artifacts['Model'] = execution_params['url']
316326
artifacts['Concurrency'] = execution_params['concurrency']
317327
artifacts['Requests'] = execution_params['requests']
@@ -323,18 +333,18 @@ def generate_csv_output():
323333
artifacts['TS latency mean'] = extract_entity(data, 'Time per request:.*mean\)', -3)
324334
artifacts['TS error rate'] = int(artifacts['TS failed requests']) / execution_params['requests'] * 100
325335

326-
with open(os.path.join(TMP_DIR, 'benchmark/predict.txt')) as f:
336+
with open(os.path.join(execution_params['report_location'], 'benchmark/predict.txt')) as f:
327337
lines = f.readlines()
328338
lines.sort(key=float)
329339
artifacts['Model_p50'] = lines[line50].strip()
330340
artifacts['Model_p90'] = lines[line90].strip()
331341
artifacts['Model_p99'] = lines[line99].strip()
332342

333343
for m in metrics:
334-
df = pd.read_csv(f"{TMP_DIR}/benchmark/{m}", header=None, names=['data'])
344+
df = pd.read_csv(f"{execution_params['report_location']}/benchmark/{m}", header=None, names=['data'])
335345
artifacts[m.split('.txt')[0] + "_mean"] = df['data'].values.mean().round(2)
336346

337-
with open(os.path.join(TMP_DIR, 'benchmark/ab_report.csv'), 'w') as csv_file:
347+
with open(os.path.join(execution_params['report_location'], 'benchmark/ab_report.csv'), 'w') as csv_file:
338348
csvwriter = csv.writer(csv_file)
339349
csvwriter.writerow(artifacts.keys())
340350
csvwriter.writerow(artifacts.values())
@@ -351,7 +361,7 @@ def extract_entity(data, pattern, index, delim=" "):
351361

352362
def generate_latency_graph():
353363
click.secho("*Preparing graphs...", fg='green')
354-
df = pd.read_csv(os.path.join(TMP_DIR, 'benchmark/predict.txt'), header=None, names=['latency'])
364+
df = pd.read_csv(os.path.join(execution_params['report_location'], 'benchmark/predict.txt'), header=None, names=['latency'])
355365
iteration = df.index
356366
latency = df.latency
357367
a4_dims = (11.7, 8.27)
@@ -360,15 +370,15 @@ def generate_latency_graph():
360370
plt.ylabel('Prediction time')
361371
plt.title('Prediction latency')
362372
plt.bar(iteration, latency)
363-
plt.savefig(f"{TMP_DIR}/benchmark/predict_latency.png")
373+
plt.savefig(f"{execution_params['report_location']}/benchmark/predict_latency.png")
364374

365375

366376
def generate_profile_graph():
367377
click.secho("*Preparing Profile graphs...", fg='green')
368378

369379
plot_data = {}
370380
for m in metrics:
371-
df = pd.read_csv(f'{TMP_DIR}/benchmark/{m}', header=None)
381+
df = pd.read_csv(f"{execution_params['report_location']}/benchmark/{m}", header=None)
372382
m = m.split('.txt')[0]
373383
plot_data[f"{m}_index"] = df.index
374384
plot_data[f"{m}_values"] = df.values
@@ -434,7 +444,6 @@ def stop_torchserve():
434444
# Test plans (soak, vgg11_1000r_10c, vgg11_10000r_100c,...)
435445
def soak():
436446
execution_params['requests'] = 100000
437-
438447
execution_params['concurrency'] = 10
439448

440449

@@ -464,6 +473,15 @@ def resnet152_batch_docker():
464473
execution_params['batch_size'] = 4
465474
execution_params['exec_env'] = 'docker'
466475

476+
def bert_batch():
477+
execution_params['url'] = 'https://bert-mar-file.s3.us-west-2.amazonaws.com/BERTSeqClassification.mar'
478+
execution_params['requests'] = 1000
479+
execution_params['concurrency'] = 10
480+
execution_params['batch_size'] = 4
481+
execution_params['input'] = '../examples/Huggingface_Transformers/Seq_classification_artifacts/sample_text.txt'
482+
483+
def workflow_nmt():
484+
pass
467485

468486
def custom():
469487
pass
@@ -475,6 +493,8 @@ def custom():
475493
"vgg11_10000r_100c": vgg11_10000r_100c,
476494
"resnet152_batch": resnet152_batch,
477495
"resnet152_batch_docker": resnet152_batch_docker,
496+
"bert_batch": bert_batch,
497+
"workflow_nmt": workflow_nmt,
478498
"custom": custom
479499
}
480500

ci/launcher/launch_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def main():
181181

182182
parser.add_argument(
183183
"--ami-id",
184-
default="ami-0e6d6921c639b58c3",
184+
default="ami-0bc4efd197db7d3ad",
185185
help="Specify an Ubuntu Base DLAMI only. This AMI type ships with nvidia drivers already setup. Using other AMIs might"
186186
"need non-trivial installations on the AMI. AMI-ids differ per aws region.",
187187
)

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RUN TORCH_VER=$(curl --silent --location https://pypi.org/pypi/torch/json | pyth
6363
else \
6464
pip install --no-cache-dir torch==$TORCH_VER+cpu torchvision==$TORCH_VISION_VER+cpu -f https://download.pytorch.org/whl/torch_stable.html; \
6565
fi
66-
RUN pip install --no-cache-dir captum torchtext torchserve torch-model-archiver
66+
RUN pip install -U setuptools && pip install --no-cache-dir captum torchtext torchserve torch-model-archiver
6767

6868
# Final image for production
6969
FROM ${BASE_IMAGE} AS runtime-image

docs/api/dev_api.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. toctree::
2+
:caption: Developer APIs:
3+
4+
ts.rst
5+
ts.torch_handler.request_envelope.rst
6+
ts.torch_handler.rst
7+
ts.metrics.rst
8+
ts.model_service.rst
9+
ts.protocol.rst
10+
modules.rst
11+
12+
13+

docs/api/modules.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
serve
2+
=====
3+
4+
.. toctree::
5+
:maxdepth: 4
6+
7+
run_circleci_tests
8+
setup
9+
test
10+
torchserve_sanity
11+
ts
12+
ts_scripts

docs/api/run_circleci_tests.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
run\_circleci\_tests module
2+
===========================
3+
4+
.. automodule:: run_circleci_tests
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/api/setup.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
setup module
2+
============
3+
4+
.. automodule:: setup
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/api/test.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test package
2+
============
3+
4+
Submodules
5+
----------
6+
7+
test.regression\_tests module
8+
-----------------------------
9+
10+
.. automodule:: test.regression_tests
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
16+
Module contents
17+
---------------
18+
19+
.. automodule:: test
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:

docs/api/torchserve_sanity.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
torchserve\_sanity module
2+
=========================
3+
4+
.. automodule:: torchserve_sanity
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/api/ts.metrics.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
ts.metrics package
2+
==================
3+
4+
Submodules
5+
----------
6+
7+
ts.metrics.dimension module
8+
---------------------------
9+
10+
.. automodule:: ts.metrics.dimension
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
ts.metrics.metric module
16+
------------------------
17+
18+
.. automodule:: ts.metrics.metric
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
ts.metrics.metric\_collector module
24+
-----------------------------------
25+
26+
.. automodule:: ts.metrics.metric_collector
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
ts.metrics.metric\_encoder module
32+
---------------------------------
33+
34+
.. automodule:: ts.metrics.metric_encoder
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
39+
ts.metrics.metrics\_store module
40+
--------------------------------
41+
42+
.. automodule:: ts.metrics.metrics_store
43+
:members:
44+
:undoc-members:
45+
:show-inheritance:
46+
47+
ts.metrics.process\_memory\_metric module
48+
-----------------------------------------
49+
50+
.. automodule:: ts.metrics.process_memory_metric
51+
:members:
52+
:undoc-members:
53+
:show-inheritance:
54+
55+
ts.metrics.system\_metrics module
56+
---------------------------------
57+
58+
.. automodule:: ts.metrics.system_metrics
59+
:members:
60+
:undoc-members:
61+
:show-inheritance:
62+
63+
ts.metrics.unit module
64+
----------------------
65+
66+
.. automodule:: ts.metrics.unit
67+
:members:
68+
:undoc-members:
69+
:show-inheritance:
70+
71+
72+
Module contents
73+
---------------
74+
75+
.. automodule:: ts.metrics
76+
:members:
77+
:undoc-members:
78+
:show-inheritance:

docs/api/ts.model_service.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ts.model\_service package
2+
=========================
3+
4+
Submodules
5+
----------
6+
7+
ts.model\_service.model\_service module
8+
---------------------------------------
9+
10+
.. automodule:: ts.model_service.model_service
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
16+
Module contents
17+
---------------
18+
19+
.. automodule:: ts.model_service
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:

0 commit comments

Comments
 (0)