GithubHelp home page GithubHelp logo

hanrui-wang / onnx-profiler Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 0.0 20 KB

A simple yet useful profiler for NN models (currently supporting ONNX and PyTorch models).

License: MIT License

Python 100.00%

onnx-profiler's Introduction

ONNX Profiler

This tool is used to profile the NN models (currently supporting ONNX and PyTorch models).

Installation

We recommend you to install the latest version of this package from GitHub:

pip install --upgrade git+https://github.com/zhijian-liu/onnx-profiler.git

Getting Started (PyTorch)

Before profiling, you should first define your PyTorch model and a (dummy) input which the model takes:

from torchvision.models import *
import torch

model = resnet18()
inputs = torch.randn(1, 3, 224, 224)

If you want to profile the number of multiplications in your model,

from onnxp import *
import numpy as np

mults = torch_profile(model, inputs, profiler=OperationsProfiler, reduction=np.sum, verbose=True)

Here, we explain a little bit more about the arguments of torch_profile:

  • reduction is set to np.sum to sum up the computations in all layers. If you want to keep the computations in all layers as a list, you can then set this argument to None (which is the default value).
  • verbose is set to True to display the number of multiplications in each layer; alternatively, if you do not want to display any intermediate output, you can also set it to False (which is the default value).

Similarly, if you want to profile the number of parameters in your model,

from onnxp import *
import numpy as np

params = torch_profile(model, inputs, profiler=ParametersProfiler, reduction=np.sum, verbose=True)

Further, if you want to display the output activation sizes of all layers in your model,

from onnxp import *
import numpy as np

torch_profile(model, inputs, profiler=ActivationProfiler, verbose=True)

License

This repository is released under the MIT license. See LICENSE for additional details.

onnx-profiler's People

Contributors

hanrui-wang avatar

Stargazers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.