You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code.md
+5-6
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,8 @@ The TurnkeyML source code has a few major top-level directories:
11
11
-`models`: the corpora of models that makes up the TurnkeyML models (see [the models readme](https://github.com/onnx/turnkeyml/blob/main/models/readme.md)).
12
12
- Each subdirectory under `models` represents a corpus of models pulled from somewhere on the internet. For example, `models/torch_hub` is a corpus of models from [Torch Hub](https://github.com/pytorch/hub).
13
13
-`src/turnkey`: source code for the TurnkeyML tools (see [Benchmarking Tools](#benchmarking-tools) for a description of how the code is used).
14
-
-`src/turnkeyml/analyze`: functions for profiling a model script, discovering model instances, and invoking `benchmark_model()` on those instances.
15
-
-`src/turnkeyml/run`: implements the runtime and device plugin APIs and the built-in runtimes and devices.
14
+
-`src/turnkeyml/analyze`: functions for profiling a model script, discovering model instances, and invoking `build_model()` and/or `BaseRT.benchmark()` on those instances.
15
+
-`src/turnkeyml/run`: implements `BaseRT`, an abstract base class that defines TurnkeyML's vendor-agnostic benchmarking functionality. This module also includes the runtime and device plugin APIs and the built-in runtimes and devices.
16
16
-`src/turnkeyml/cli`: implements the `turnkey` CLI and reporting tool.
17
17
-`src/turnkeyml/common`: functions common to the other modules.
18
18
-`src/turnkeyml/version.py`: defines the package version number.
@@ -29,10 +29,9 @@ TurnkeyML provides two main tools, the `turnkey` CLI and benchmarking APIs. Inst
29
29
1. The default command for `turnkey` CLI runs the `benchmark_files()` API, which is implemented in [files_api.py](https://github.com/onnx/turnkeyml/blob/main/src/turnkeyml/files_api.py).
30
30
- Other CLI commands are also implemented in `cli/`, for example the `report` command is implemented in `cli/report.py`.
31
31
1. The `benchmark_files()` API takes in a set of scripts, each of which should invoke at least one model instance, to evaluate and passes each into the `evaluate_script()` function for analysis, which is implemented in [analyze/script.py](https://github.com/onnx/turnkeyml/blob/main/src/turnkeyml/analyze/script.py).
32
-
1.`evaluate_script()` uses a profiler to discover the model instances in the script, and passes each into the `benchmark_model()` API, which is defined in [model_api.py](https://github.com/onnx/turnkeyml/blob/main/src/turnkeyml/model_api.py).
33
-
1. The `benchmark_model()` API prepares the model for benchmarking (e.g., exporting and optimizing an ONNX file), which creates an instance of a `*Model` class, where `*` can be CPU, GPU, etc. The `*Model` classes are defined in [run/](https://github.com/onnx/turnkeyml/blob/main/src/turnkeyml/run/).
34
-
1. The `*Model` classes provide a `.benchmark()` method that benchmarks the model on the device and returns an instance of the `MeasuredPerformance` class, which includes the performance statistics acquired during benchmarking.
35
-
1.`benchmark_model()` and the `*Model` classes are built using [`build_model()`](#model-build-tool)
32
+
1.`evaluate_script()` uses a profiler to discover the model instances in the script, and passes each into the `build_model()` API, which is defined in [build_api.py](https://github.com/onnx/turnkeyml/blob/main/src/turnkeyml/build_api.py).
33
+
1. The `build_model()` API prepares the model for benchmarking (e.g., exporting and optimizing an ONNX file).
34
+
1.`evaluate_script()` passes the build into `BaseRT.benchmark()` to benchmarks the model on the device and returns an instance of the `MeasuredPerformance` class, which includes the performance statistics acquired during benchmarking.
Copy file name to clipboardExpand all lines: docs/readme.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
This directory contains documentation for the TurnkeyML project:
4
4
-[code.md](https://github.com/onnx/turnkeyml/blob/main/docs/code.md): Code organization for the benchmark and tools.
5
5
-[install.md](https://github.com/onnx/turnkeyml/blob/main/docs/install.md): Installation instructions for the tools.
6
-
-[tools_user_guide.md](https://github.com/onnx/turnkeyml/blob/main/docs/tools_user_guide.md): User guide for the tools: `turnkey` CLI, `benchmark_files()`, and `benchmark_model()`.
6
+
-[tools_user_guide.md](https://github.com/onnx/turnkeyml/blob/main/docs/tools_user_guide.md): User guide for the tools: the `turnkey` CLI and the `benchmark_files()` and `build_model()` APIs.
7
7
-[versioning.md](https://github.com/onnx/turnkeyml/blob/main/docs/versioning.md): Defines the semantic versioning rules for the `turnkey` package.
Copy file name to clipboardExpand all lines: docs/tools_user_guide.md
+15-43
Original file line number
Diff line number
Diff line change
@@ -51,8 +51,8 @@ Where `your_script.py` is a Python script that instantiates and executes a PyTor
51
51
52
52
The `turnkey` CLI performs the following steps:
53
53
1.[Analysis](#analysis): profile the Python script to identify the PyTorch models within
54
-
2.[Build](#build): call the `benchmark_files()`[API](#the-turnkey-api) to prepare each model for benchmarking
55
-
3.[Benchmark](#benchmark): call the `benchmark_model()`[API](#the-turnkey-api) on each model to gather performance statistics
54
+
2.[Build](#build): call the `build_models()`[API](#the-turnkey-api) to prepare each model for benchmarking
55
+
3.[Benchmark](#benchmark): call the `BaseRT.benchmark()`method on each model to gather performance statistics
56
56
57
57
_Note_: The benchmarking methodology is defined [here](#benchmark). If you are looking for more detailed instructions on how to install turnkey, you can find that [here](https://github.com/onnx/turnkeyml/blob/main/docs/install.md).
58
58
@@ -64,31 +64,11 @@ _Note_: The benchmarking methodology is defined [here](#benchmark). If you are l
64
64
65
65
Most of the functionality provided by the `turnkey` CLI is also available in the the API:
66
66
-`turnkey.benchmark_files()` provides the same benchmarking functionality as the `turnkey` CLI: it takes a list of files and target device, and returns performance results.
67
-
-`turnkey.benchmark_model()` provides a subset of this functionality: it takes a model and its inputs, and returns performance results.
68
-
- The main difference is that `benchmark_model()` does not include the [Analysis](#analysis) feature, and `benchmark_files()` does.
69
67
-`turnkey.build_model(model, inputs)` is used to programmatically [build](#build) a model instance through a sequence of model-to-model transformations (e.g., starting with an fp32 PyTorch model and ending with an fp16 ONNX model).
70
68
71
-
Generally speaking, the `turnkey` CLI is a command line interface for the `benchmark_files()` API, which internally calls `benchmark_model()`, which in turn calls `build_model()`. You can read more about this code organization [here](https://github.com/onnx/turnkeyml/blob/main/docs/code.md).
69
+
Generally speaking, the `turnkey` CLI is a command line interface for the `benchmark_files()` API which in turn calls `build_model()` and then performs benchmarking using `BaseRT.benchmark()`. You can read more about this code organization [here](https://github.com/onnx/turnkeyml/blob/main/docs/code.md).
72
70
73
-
For an example of `benchmark_model()`, the following script:
74
-
75
-
```python
76
-
from turnkeyml import benchmark_model
77
-
78
-
model = YourModel() # Instantiate a torch.nn.module
79
-
results = model(**inputs)
80
-
perf = benchmark_model(model, inputs)
81
-
```
82
-
83
-
Will print an output like this:
84
-
85
-
```
86
-
> Performance of YourModel on device Intel® Xeon® Platinum 8380 is:
87
-
> latency: 0.033 ms
88
-
> throughput: 21784.8 ips
89
-
```
90
-
91
-
`benchmark_model()` returns a `MeasuredPerformance` object that includes members:
71
+
`BaseRT.benchmark()` returns a `MeasuredPerformance` object that includes members:
92
72
-`latency_units`: unit of time used for measuring latency, which is set to `milliseconds (ms)`.
93
73
-`mean_latency`: average benchmarking latency, measured in `latency_units`.
94
74
-`throughput_units`: unit used for measuring throughput, which is set to `inferences per second (IPS)`.
@@ -135,7 +115,7 @@ A **runtime** is a piece of software that executes a model on a device.
135
115
136
116
**Analysis** is the process by which `benchmark_files()` inspects a Python script or ONNX file and identifies the models within.
137
117
138
-
`benchmark_files()` performs analysis by running and profiling your file(s). When a model object (see [Model](#model) is encountered, it is inspected to gather statistics (such as the number of parameters in the model) and/or pass it to the `benchmark_model()` API for benchmarking.
118
+
`benchmark_files()` performs analysis by running and profiling your file(s). When a model object (see [Model](#model) is encountered, it is inspected to gather statistics (such as the number of parameters in the model) and/or passed to the build and benchmark APIs.
139
119
140
120
> _Note_: the `turnkey` CLI and `benchmark_files()` API both run your entire python script(s) whenever python script(s) are passed as input files. Please ensure that these scripts are safe to run, especially if you got them from the internet.
141
121
@@ -205,12 +185,14 @@ The *build cache* is a location on disk that holds all of the artifacts from you
205
185
206
186
## Benchmark
207
187
208
-
*Benchmark* is the process by which the `benchmark_model()` API collects performance statistics about a [model](#model). Specifically, `benchmark_model()` takes a [build](#build) of a model and executes it on a target device using target runtime software (see [Devices and Runtimes](#devices-and-runtimes)).
188
+
*Benchmark* is the process by which `BaseRT.benchmark()` collects performance statistics about a [model](#model). `BaseRT` is an abstract base class that defines the common benchmarking infrastructure that TurnkeyML provides across devices and runtimes.
189
+
190
+
Specifically, `BaseRT.benchmark()` takes a [build](#build) of a model and executes it on a target device using target runtime software (see [Devices and Runtimes](#devices-and-runtimes)).
209
191
210
-
By default, `benchmark_model()` will run the model 100 times to collect the following statistics:
192
+
By default, `BaseRT.benchmark()` will run the model 100 times to collect the following statistics:
211
193
1. Mean Latency, in milliseconds (ms): the average time it takes the runtime/device combination to execute the model/inputs combination once. This includes the time spent invoking the device and transferring the model's inputs and outputs between host memory and the device (when applicable).
212
194
1. Throughput, in inferences per second (IPS): the number of times the model/inputs combination can be executed on the runtime/device combination per second.
213
-
> -_Note_: `benchmark_model()` is not aware of whether `inputs` is a single input or a batch of inputs. If your `inputs` is actually a batch of inputs, you should multiply `benchmark_model()`'s reported IPS by the batch size.
195
+
> -_Note_: `BaseRT.benchmark()` is not aware of whether `inputs` is a single input or a batch of inputs. If your `inputs` is actually a batch of inputs, you should multiply `BaseRT.benchmark()`'s reported IPS by the batch size.
214
196
215
197
# Devices and Runtimes
216
198
@@ -226,7 +208,7 @@ If you are using a remote machine, it must:
226
208
- include the target device
227
209
- have `miniconda`, `python>=3.8`, and `docker>=20.10` installed
228
210
229
-
When you call `turnkey` CLI or `benchmark_model()`, the following actions are performed on your behalf:
211
+
When you call `turnkey` CLI or `benchmark_files()`, the following actions are performed on your behalf:
230
212
1. Perform a `build`, which exports all models from the script to ONNX and prepares for benchmarking.
231
213
1. Set up the benchmarking environment by loading a container and/or setting up a conda environment.
232
214
1. Run the benchmarks.
@@ -253,7 +235,6 @@ Valid values of `TYPE` include:
253
235
254
236
Also available as API arguments:
255
237
-`benchmark_files(device=...)`
256
-
-`benchmark_model(device=...)`.
257
238
258
239
> For a detailed example, see the [CLI Nvidia tutorial](https://github.com/onnx/turnkeyml/blob/main/examples/cli/readme.md#nvidia-benchmarking).
259
240
@@ -274,9 +255,8 @@ Each device type has its own default runtime, as indicated below.
274
255
275
256
This feature is also be available as an API argument:
276
257
-`benchmark_files(runtime=[...])`
277
-
-`benchmark_model(runtime=...)`
278
258
279
-
> _Note_: Inputs to `torch-eager` and `torch-compiled` are not downcasted to FP16 by default. Downcast inputs before benchmarking for a fair comparison between runtimes.
259
+
> _Note_: Inputs to `torch-eager` and `torch-compiled` are not downcasted to FP16 by default. You must perform your own downcast or quantization of inputs if needed for apples-to-apples comparisons with other runtimes.
280
260
281
261
# Additional Commands and Options
282
262
@@ -381,7 +361,6 @@ Process isolation mode applies a timeout to each subprocess. The default timeout
381
361
382
362
Also available as API arguments:
383
363
-`benchmark_files(cache_dir=...)`
384
-
-`benchmark_model(cache_dir=...)`
385
364
-`build_model(cache_dir=...)`
386
365
387
366
> See the [Cache Directory tutorial](https://github.com/onnx/turnkeyml/blob/main/examples/cli/cache.md#cache-directory) for a detailed example.
@@ -392,7 +371,6 @@ Also available as API arguments:
> _Note_: useful for benchmarking many models, since the `build` artifacts from the models can take up a significant amount of hard drive space.
398
376
@@ -409,7 +387,6 @@ Takes one of the following values:
409
387
410
388
Also available as API arguments:
411
389
-`benchmark_files(rebuild=...)`
412
-
-`benchmark_model(rebuild=...)`
413
390
-`build_model(rebuild=...)`
414
391
415
392
### Sequence
@@ -421,7 +398,6 @@ Usage:
421
398
422
399
Also available as API arguments:
423
400
-`benchmark_files(sequence=...)`
424
-
-`benchmark_model(sequence=...)`
425
401
-`build_model(sequence=...)`
426
402
427
403
### Set Script Arguments
@@ -460,7 +436,6 @@ Usage:
460
436
461
437
Also available as API arguments:
462
438
-`benchmark_files(onnx_opset=...)`
463
-
-`benchmark_model(onnx_opset=...)`
464
439
-`build_model(onnx_opset=...)`
465
440
466
441
> _Note_: ONNX opset can also be set by an environment variable. The --onnx-opset argument takes precedence over the environment variable. See [TURNKEY_ONNX_OPSET](#set-the-onnx-opset).
@@ -474,11 +449,10 @@ Usage:
474
449
475
450
Also available as API arguments:
476
451
-`benchmark_files(iterations=...)`
477
-
-`benchmark_model(iterations=...)`
478
452
479
453
### Analyze Only
480
454
481
-
Instruct `turnkey` or `benchmark_model()` to only run the [Analysis](#analysis) phase of the `benchmark` command.
455
+
Instruct `turnkey` or `benchmark_files()` to only run the [Analysis](#analysis) phase of the `benchmark` command.
482
456
483
457
Usage:
484
458
-`turnkey benchmark INPUT_FILES --analyze-only`
@@ -493,7 +467,7 @@ Also available as an API argument:
493
467
494
468
### Build Only
495
469
496
-
Instruct `turnkey`, `benchmark_files()`, or `benchmark_model()` to only run the [Analysis](#analysis) and [Build](#build) phases of the `benchmark` command.
470
+
Instruct `turnkey`or `benchmark_files()` to only run the [Analysis](#analysis) and [Build](#build) phases of the `benchmark` command.
> See the [Build Only tutorial](https://github.com/onnx/turnkeyml/blob/main/examples/cli/build.md#build-only) for a detailed example.
509
482
@@ -515,7 +488,6 @@ None of the built-in runtimes support such arguments, however plugin contributor
515
488
516
489
Also available as API arguments:
517
490
-`benchmark_files(rt_args=Dict)` (default None)
518
-
-`benchmark_model(rt_args=Dict)` (default None)
519
491
520
492
## Cache Commands
521
493
@@ -635,7 +607,7 @@ export TURNKEY_DEBUG=True
635
607
636
608
### Set the ONNX Opset
637
609
638
-
By default, `turnkey`, `benchmark_files()`, and `benchmark_model()` will use the default ONNX opset defined in `turnkey.common.build.DEFAULT_ONNX_OPSET`. You can set a different default ONNX opset by setting the `TURNKEY_ONNX_OPSET` environment variable.
610
+
By default, `turnkey`, `benchmark_files()`, and `build_model()` will use the default ONNX opset defined in `turnkey.common.build.DEFAULT_ONNX_OPSET`. You can set a different default ONNX opset by setting the `TURNKEY_ONNX_OPSET` environment variable.
0 commit comments