--- id: torchprofile version: "0.1.0" license: MIT license_treatment: permissive maintenance: active --- # torchprofile — Count the MACs / FLOPs of PyTorch models License: permissive · Maintenance: active · Downloads: 297.6K/mo ## What it is and what it does TorchProfile is a lightweight profiler that measures the computational cost of PyTorch models by counting multiply-accumulate operations (MACs). It works by tracing the model's computation graph using torch.jit.trace, which is more accurate than hook-based profilers and more general than ONNX-based approaches. The package outputs either a single aggregate MAC count or a per-operator breakdown showing which layers consume the most computation. You pass a model and sample input tensors to the profile_macs function, and it returns the total MACs or a dictionary mapping operation nodes to their individual MAC counts. This is useful for understanding model efficiency, comparing architectures, and identifying computational bottlenecks without running the model on actual hardware. Use it for: - Estimate computational cost of a model before deploying to resource-constrained devices. - Compare MAC efficiency across different model architectures or hyperparameter choices. - Identify which layers in a model consume the most computation for optimization targeting. - Profile models during development to catch unexpectedly expensive operations early. - Generate per-operator breakdowns for detailed performance analysis and model auditing. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Counts multiply-accumulate operations (MACs) in PyTorch models by tracing the computation graph, providing both aggregate and per-operator breakdowns. Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real need for PyTorch developers who want to profile model efficiency. The MIT license is permissive. Main caveat: your model must be traceable with torch.jit.trace, which excludes models with dynamic control flow. ## Install pip install torchprofile uv add torchprofile poetry add torchprofile ## Installing torchprofile Before you install: Low friction: pure Python wheel with only torch as a runtime dependency. Active maintenance with recent commits and a moderate user base. License in practice: MIT license is permissive; you can use, modify, and distribute this package with minimal restrictions. Quickstart: pip install torchprofile import torch from torchprofile import profile_macs model = torch.nn.Linear(10, 10) inputs = torch.randn(1, 10) macs = profile_macs(model, inputs) print(macs) Requires Python >= 3.9 and torch installed; models must be traceable with torch.jit.trace. Verify before relying: - Whether the tracing approach handles dynamic control flow or models with conditional branches accurately. - Performance characteristics when profiling very large models or batches. - Compatibility with torch.jit.trace limitations across different PyTorch versions. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 297.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pytorch model mac counter, flop profiler torch, neural network operation counter, pytorch computation graph profiler, model efficiency analysis, pytorch mac counting, deep learning profiling tool, profiling, pytorch, model-analysis [View on SkillFed](https://skillfed.io/packages/torchprofile) · [View on PyPI](https://pypi.org/project/torchprofile/)