Profiler for deep learning models
Project description
Deeplite Profiler
To be able to use a deep learning model in research and production, it is essential to understand different performance metrics of the model beyond just the model's accuracy. deeplite-profiler
helps to easily and effectively measure the different performance metrics of a deep learning model. In addition to the existing metrics in the deeplite-profiler
, users could seamlessly contribute any custom metric to measure using the profiler. deeplite-profiler
could also be used to compare the performance between two different deep learning models, for example, a teacher and a student model. deeplite-profiler
currently supports PyTorch and TensorFlow Keras (v1) as two different backend frameworks.
Installation
Install using pip
Use following command to install the package from our internal PyPI repository.
$ pip install --upgrade pip
$ pip install deeplite-profiler[`backend`]
Install from source
$ git clone https://github.com/Deeplite/deeplite-profiler.git
$ pip install .[`backend`]
One can install specific backend
modules, depending on the required framework and compute support. backend
could be one of the following values
torch
: to install atorch
specific profilertf
: to install aTensorFlow
specific profiler (this supports only CPU compute)tf-gpu
: to install aTensorFlow-gpu
specific profiler (this supports both CPU and GPU compute)all
: to install bothtorch
andTensorFlow
specific profiler (this supports only CPU compute for TensorFlow)all-gpu
: to install bothtorch
andTensorFlow-gpu
specific profiler (for GPU environment) (this supports both CPU and GPU compute for TensorFlow)
Install in Dev mode
$ git clone https://github.com/Deeplite/deeplite-profiler.git
$ pip install -e .[`backend`]
$ pip install -r requirements-test.txt
To test the installation, one can run the basic tests using pytest
command in the root folder.
NOTE: Currently, we support Tensorflow 1.14 and 1.15 versions, for Python 3.6 and 3.7. We do not support Python 3.8+.
How to Use
For PyTorch Model
# Step 1: Define native pytorch dataloaders and model
# 1a. data_splits = {"train": train_dataloder, "test": test_dataloader}
data_splits = /* ... load iterable data loaders ... */
model = /* ... load native deep learning model ... */
# Step 2: Create Profiler class and register the profiling functions
data_loader = TorchProfiler.enable_forward_pass_data_splits(data_splits)
profiler = TorchProfiler(model, data_splits, name="Original Model")
profiler.register_profiler_function(ComputeComplexity())
profiler.register_profiler_function(ComputeExecutionTime())
profiler.register_profiler_function(ComputeEvalMetric(get_accuracy, 'accuracy', unit_name='%'))
# Step 3: Compute the registered profiler metrics for the PyTorch Model
profiler.compute_network_status(batch_size=1, device=Device.CPU, short_print=False,
include_weights=True, print_mode='debug')
# Step 4: Compare two different models or profilers.
profiler2 = profiler.clone(model=deepcopy(model)) # Creating a dummy clone of the current profiler
profiler2.name = "Clone Model"
profiler.compare(profiler2, short_print=False, batch_size=1, device=Device.CPU, print_mode='debug')
For Tensorflow Model
# Step 1: Define native tensorflow dataloaders and model
# 1a. data_splits = {"train": train_dataloder, "test": test_dataloader}
data_splits = /* ... load iterable data loaders ... */
model = /* ... load native deep learning model ... */
# Step 2: Create Profiler class and register the profiling functions
data_loader = TFProfiler.enable_forward_pass_data_splits(data_splits)
profiler = TFProfiler(model, data_splits, name="Original Model")
profiler.register_profiler_function(ComputeFlops())
profiler.register_profiler_function(ComputeSize())
profiler.register_profiler_function(ComputeParams())
profiler.register_profiler_function(ComputeLayerwiseSummary())
profiler.register_profiler_function(ComputeExecutionTime())
profiler.register_profiler_function(ComputeEvalMetric(get_accuracy, 'accuracy', unit_name='%'))
# Step 3: Compute the registered profiler metrics for the Tensorflow Keras Model
profiler.compute_network_status(batch_size=1, device=Device.CPU, short_print=False,
include_weights=True, print_mode='debug')
# Step 4: Compare two different models or profilers.
profiler2 = profiler.clone(model=model) # Creating a dummy clone of the current profiler
profiler2.name = "Clone Model"
profiler.compare(profiler2, short_print=False, batch_size=1, device=Device.CPU, print_mode='debug')
Output Display
An example output of the deeplite-profiler
for resnet18
model using the standard CIFAR100
dataset using PyTorch
backend, looks as follows
+---------------------------------------------------------------+
| deeplite Model Profiler |
+-----------------------------------------+---------------------+
| Param Name (Original Model) | Value|
| Backend: TorchBackend | |
+-----------------------------------------+---------------------+
| Evaluation Metric (%) | 76.8295|
| Model Size (MB) | 42.8014|
| Computational Complexity (GigaMACs) | 0.5567|
| Total Parameters (Millions) | 11.2201|
| Memory Footprint (MB) | 48.4389|
| Execution Time (ms) | 2.6537|
+-----------------------------------------+---------------------+
- Evaluation Metric: Computed performance of the model on the given data
- Model Size: Memory consumed by the parameters (weights and biases) of the model
- Computational Complexity: Summation of Multiply-Add Cumulations (MACs) per single image (batch_size=1)
- #Total Parameters: Total number of parameters (trainable and non-trainable) in the model
- Memory Footprint: Total memory consumed by parameters and activations per single image (batch_size=1)
- Execution Time: On
NVIDIA TITAN V <https://www.nvidia.com/en-us/titan/titan-v/>
_ GPU, time required for the forward pass per single image (batch_size=1)
Examples
A list of different examples to use deeplite-profiler
to profiler different PyTorch and TensorFlow models can be found here
Contribute a Custom Metric
NOTE: If you looking for an SDK documentation, please head over here.
We always welcome community contributions to expand the scope of deeplite-profiler
and also to have additional new metrics. Please refer to the documentation for the detailed steps on how to design a new metrics. In general, we follow the fork-and-pull
Git workflow.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for deeplite_profiler-1.2.2-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03a8139449449eba3ec41b8f85d1ca7d964c01d7ceb355cae4852ebfd001a22c |
|
MD5 | a39ed3a92fff46a51752a5bd409a6612 |
|
BLAKE2b-256 | a3e456bc15837813c0151aceb0d88352c8b919983f5814dc31aaf97b6e4f5b72 |
Hashes for deeplite_profiler-1.2.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac63560396b57c3dfe9b70cdb0e86d2674e7a8f888e5f987e43784654178ed26 |
|
MD5 | c2796ad467e24f7524270848906972b1 |
|
BLAKE2b-256 | 3700db8f2430da90843b7ef1bc6b3237fd400674d099e7973c5d5b06697996e1 |
Hashes for deeplite_profiler-1.2.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4620542bf5a54ceee03a37acc29f4bccd2314a24b874cf44be24b1dbc58d2423 |
|
MD5 | 64087de81b571b133e4bdbbe9d28ab8a |
|
BLAKE2b-256 | 2ae081f8bf8929275eaf50456d4bbb3454398b958c3b7ca32e87cbf68f1319f2 |
Hashes for deeplite_profiler-1.2.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7507bb58e22cd2594af0a18df417e0825bd6e87e8b18f99aba26ece9a31cd75 |
|
MD5 | 56b9802fe27de444915ab5ef0422f919 |
|
BLAKE2b-256 | eea3215e19d21d92b7d800cc945c63f0280fd2e11e9adf72097aed8bd88561cd |
Hashes for deeplite_profiler-1.2.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8899ed7b8a46c11911ebeb0b01da7d486aac9c7c6376494be47c6fc181514871 |
|
MD5 | 7884b55628496b5de62c3eebe1ff5b51 |
|
BLAKE2b-256 | 4080e0a57760b17cb885557800a848d9393a8f32d32727f5cea65f22c4d1891d |
Hashes for deeplite_profiler-1.2.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc876731094c50985b375060e7ab0b61fe4b6e6457c3eaf643cb43a83ad5daf |
|
MD5 | fa3b513e552b62f7e6b2027df0837619 |
|
BLAKE2b-256 | 7d294e1ffb736c91ef4d601e0199d9dea3275a9815582f6febeb4447bc39454a |
Hashes for deeplite_profiler-1.2.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d12e3d4ac086020b2d54cb4da6ecf2ca4716fb93fcb2cd834cbea345a162ab23 |
|
MD5 | 105a8cdb51c8be78df66797cad876a15 |
|
BLAKE2b-256 | 8a220159a611e1fbedf98a967e603811de03387024c874ed9c911ea82ebb01cb |
Hashes for deeplite_profiler-1.2.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 190f72666f69c95cd2ef22f61fc0bbf4a52d267a092a92912442cdf36cad18f7 |
|
MD5 | baf0ce639d9dda6b70f7dfc2334ebcc3 |
|
BLAKE2b-256 | f9ddfd8d6af0a11432dc8a8d9cca00daf24869db3ce17f297153062aca542f5c |