Benchmark your DL model

dll-bench is a command line tool that makes it easy for you to benchmark the model on different platforms.

With djl-bench, you can easily compare your model’s behavior in different use cases, such as:

djl-bench currently support benchmark the following type of models:

You can build djl-bench from source if you need to benchmark fastText/BlazingText/Sentencepiece models.


For macOS

brew install cask djl-bench

For Ubuntu

sudo snap install djlbench --classic
sudo snap alias djlbench djl-bench
curl -O
sudo dpkg -i djl-bench_0.13.0-1_all.deb

For centOS or Amazon Linux 2

You can download djl-bench zip file from here.

curl -O
sudo ln -s $PWD/benchmark-0.13.0/bin/benchmark /usr/bin/djl-bench

For Windows

We are considering to create a chocolatey package for Windows. For the time being, you can download djl-bench zip file from here.

Or you can run benchmark using gradle:

cd djl

gradlew benchmark --args="--help"


Please ensure Java 8+ is installed and you are using an OS that DJL supported with.

After that, you need to clone the djl project and cd into the folder.

DJL supported OS:

If you are trying to use GPU, please ensure the CUDA driver is installed. You can verify that through:

nvcc -V

to checkout the version. For different Deep Learning engine you are trying to run the benchmark, they have different CUDA version to support. Please check the individual Engine documentation to ensure your CUDA version is supported.

Sample benchmark script

Here is a few sample benchmark script for you to refer. You can also skip this and directly follow the 4-step instructions for your own model.

Benchmark on a Tensorflow model from tfhub url with all-zeros NDArray input for 10 times:

djl-bench -e TensorFlow -u -c 10 -s 1,224,224,3

Similarly, this is for PyTorch

djl-bench -e PyTorch -u -n traced_resnet18 -c 10 -s 1,3,224,224

Benchmark a model from ONNX Model Zoo

djl-bench -e OnnxRuntime -u -s 1,3,224,224 -n resnet18v1/resnet18v1 -c 10

Benchmark from ModelZoo


Resnet50 image classification model:

djl-bench -c 2 -s 1,3,224,224 -u djl://ai.djl.mxnet/resnet/0.0.1/resnet50_v2


SSD object detection model:

djl-bench -e PyTorch -c 2 -s 1,3,300,300 -u djl://ai.djl.pytorch/ssd/0.0.1/ssd_300_resnet50

Configuration of Benchmark script

To start your benchmarking, we need to make sure we provide the following information.

The benchmark script located here.

Just do the following:

djl-bench --help

This will print out the possible arguments to pass in:

usage: djl-bench [-p MODEL-PATH] -s INPUT-SHAPES [OPTIONS]
 -c,--iteration <ITERATION>               Number of total iterations.
 -d,--duration <DURATION>                 Duration of the test in minutes.
 -e,--engine <ENGINE-NAME>                Choose an Engine for the benchmark.
 -g,--gpus <NUMBER_GPUS>                  Number of GPUS to run multithreading inference.
 -h,--help                                Print this help.
 -l,--delay <DELAY>                       Delay of incremental threads.
    --model-arguments <MODEL-ARGUMENTS>   Specify model loading arguments.
    --model-options <MODEL-OPTIONS>       Specify model loading options.
 -n,--model-name <MODEL-NAME>             Specify model file name.
    --neuron-cores <NEURON-CORES>         Number of neuron cores to run multithreading inference, See
 -o,--output-dir <OUTPUT-DIR>             Directory for output logs.
 -p,--model-path <MODEL-PATH>             Model directory file path.
 -s,--input-shapes <INPUT-SHAPES>         Input data shapes for the model.
 -t,--threads <NUMBER_THREADS>            Number of inference threads.
 -u,--model-url <MODEL-URL>               Model archive file URL.

Step 1: Pick your deep engine

By default, the above script will use MXNet as the default Engine, but you can always change that by adding the followings:

-e TensorFlow # TensorFlow
-e PyTorch # PyTorch
-e MXNet # Apache MXNet
-e PaddlePaddle # PaddlePaddle
-e OnnxRuntime # pytorch
-e TFLite # TFLite
-e TensorRT # TensorRT
-e DLR # Neo DLR
-e XGBoost # XGBoost
-e Python # Python script

Step 2: Identify the source of your model

DJL accept variety of models came from different places.

Remote location

Use --model-url option to load a model from a URL. The URL must point to an archive file.

The following is a pytorch model


We would recommend to make model files in a zip for better file tracking.

Local directory

Use --model-path option to load model from a local directory or an archive file.


-p /home/ubuntu/models/pytorch_resnet18
-p /home/ubuntu/models/


-p C:\models\pytorch_resnet18
-p C:\models\

If the model file name is different from the parent folder name (or the archive file name), you need to specify --model-name in the --args:

-n traced_resnet18

Step 3: Define how many runs you would like to make

add -c inside with a number

-c 1000

This will run 1000 times inference.

Step 4: Define your model inputs

The benchmark script uses dummy NDArray inputs. It will make fake NDArrays (like NDArray.ones) to feed in the model for inference.

If we would like to fake an image:

-s 1,3,224,224

This will create a NDArray (DataType FLOAT32) of shape(1, 3, 224, 224).

If your model requires multiple inputs like three NDArrays with shape 1, 384 and 384. You can do the followings:

-s (1),(384),(384)

If you input DataType is not FLOAT32, you can specify the data type with suffix:

For example:

-s (1)i,(384)f,(384)

Optional Step: multithreading inference

You can also do multi-threading inference with DJL. For example, if you would like to run the inference with 10 threads:

-t 10

Best thread number for your system: The same number of cores your system have or double of the total cores.

You can also add -l to simulate the increment load for your inference server. It will add threads with the delay of time.

-t 10 -l 100

The above code will create 10 threads with the wait time of 100ms.

Advanced use cases

For different purposes, we designed different mode you can play with. Such as the following arg:

-d 86400

This will ask the benchmark script repeatedly running the designed task for 86400 seconds (24 hour). If you would like to make sure DJL is stable in the long run, you can do that.

You can also keep monitoring the DJL memory usages by enable the following flag:

export BENCHMARK_OPTS="-Dcollect-memory=true"

The memory report will be made available in build/memory.log.