Skip to main content

Measure execution time of every layer in your pytorch model.

Project description

Pytorch profiler

Pytorchures is a simple model profiler intended for any pytorch model. It measures execution time of model layers individually. Every layer of a model is wrapped with timing class which measures latency when called.

TLDR;

Install

git clone https://github.com/cezbloch/pytorchures.git

pip install -e .

Run

from pytorchures.timing import wrap_model_layers

wrap_model_layers(model)

model(inputs)

Execution time of every layer is stored in profiling.log file.

Setup

This repo was developed under WSL 2 running Ubuntu 20.04 LTS. The editor of choice is VS Code.

Install python

The code was tested for Python 3.11 and 3.10, if you want to run Python 3.10 or other future version please subsitute the python version in the command below.

In case of running new WSL below are required packages and commands.

sudo apt-get update

sudo apt-get install python3.11

sudo apt-get install python3.11-venv

Install for PIL image.show() to work on WSL sudo apt install imagemagick

Install relevant VS Code extentions.

If you choose to use the recommended VS Code as editor please install the extensions from extensions.json.

Create virtual environment

Create venv

python3.11 -m venv .venv

Install requirements.txt

pip install -r requirements.txt

To activate venv type - VS Code should automatically detect your new venv, so select it as your default interpreter.

source venv/bin/activate

Install package in editable mode

In order to be able to develop and run the code install this repo in editable mode.

pip install -e .

Running

The entry point to profiling the sample object detection models is run_profiling.py file.

Examples

Running on CPU python pytorchures/run_profiling.py --device 'cpu' --nr_images 3

Running on GPU python pytorchures/run_profiling.py --device 'cuda' --nr_images 3

The script will print CPU wall time of every layer encountered in the model. Values are printed in a nested manner showing deeper layers at further indentation.

Testing

All tests are located in 'tests' folder. Please follow Arange-Act-Assert pattern for all tests. The tests should load in the test explorer.

Formatting

This repo uses 'Black' code formatter.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytorchures-0.0.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

pytorchures-0.0.1-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page