Count the MACs / FLOPs of PyTorch models
Project description
TorchProfile
TorchProfile counts the number of MACs (multiply-accumulate operations) in a PyTorch model. It works by tracing the computation graph with torch.jit.trace, making it more accurate than hook-based profilers and more general than ONNX-based ones.
Installation
pip install torchprofile
Quick Start
import torch
from transformers import AutoModel
from torchprofile import profile_macs
model = AutoModel.from_pretrained("meta-llama/Llama-3.2-1B").eval()
inputs = torch.randint(0, model.config.vocab_size, (1, 128))
macs = profile_macs(model, inputs)
print(f"{macs / 1e9:.2f} GMACs")
To get a per-operator breakdown, pass reduction=None:
results = profile_macs(model, inputs, reduction=None)
for node, macs in results.items():
if macs > 0:
print(f"{node.scope:40s} {node.operator:30s} {macs / 1e6:>8.2f} MMACs")
License
This repository is released under the MIT license. See LICENSE for additional details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchprofile-0.1.0.tar.gz.
File metadata
- Download URL: torchprofile-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeb725e9446b3a6d8f82d0f0cf944a6ffb9cced4e5db1354ad3b9692ce820dac
|
|
| MD5 |
b65e706e24800cdff91b9e5fb160fc06
|
|
| BLAKE2b-256 |
0339564175b0147da5f712702209de3904cf97de492a115943c75af1b1b56d82
|
Provenance
The following attestation bundles were made for torchprofile-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on zhijian-liu/torchprofile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchprofile-0.1.0.tar.gz -
Subject digest:
aeb725e9446b3a6d8f82d0f0cf944a6ffb9cced4e5db1354ad3b9692ce820dac - Sigstore transparency entry: 1074519574
- Sigstore integration time:
-
Permalink:
zhijian-liu/torchprofile@ec8bf8ad1563267c9532aa46d3cfa0fbeb184b03 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/zhijian-liu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ec8bf8ad1563267c9532aa46d3cfa0fbeb184b03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchprofile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torchprofile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39aefcd194927befb0cfe7ed886be565dee384e3889d0b6890bace5ae1614578
|
|
| MD5 |
114b5fb58987423c26fa8c789cb485e7
|
|
| BLAKE2b-256 |
137682c336b80fcd19ad9eedd7c17e459d69a0024aed7229dbcf663c975c5ded
|
Provenance
The following attestation bundles were made for torchprofile-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on zhijian-liu/torchprofile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchprofile-0.1.0-py3-none-any.whl -
Subject digest:
39aefcd194927befb0cfe7ed886be565dee384e3889d0b6890bace5ae1614578 - Sigstore transparency entry: 1074519615
- Sigstore integration time:
-
Permalink:
zhijian-liu/torchprofile@ec8bf8ad1563267c9532aa46d3cfa0fbeb184b03 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/zhijian-liu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ec8bf8ad1563267c9532aa46d3cfa0fbeb184b03 -
Trigger Event:
push
-
Statement type: