torchprofile is a lightweight Python library designed to accurately count the Multiply-Accumulate Operations (MACs) or FLOPs of PyTorch models. Its current version is 0.1.0. Releases are infrequent but indicate ongoing maintenance, focusing on core profiling capabilities.
pip install torchprofileVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a standard PyTorch model and use `torchprofile.profile_macs` to count its Multiply-Accumulate Operations (MACs) for a given input tensor. The result is printed in GigaMACs.
Understand the definition used by torchprofile and adjust comparisons accordingly, or consult the source for exact definitions. The library's focus is on MACs.
For custom modules, you may need to implement and register a specific MACs handler using `torchprofile.register_macs_handler`. Refer to the `torchprofile.handlers` module and documentation for examples.
Pin your dependency version (e.g., `torchprofile==0.1.0`) in your project and review release notes or the GitHub changelog when upgrading to new versions.
`pip install torchprofile`
Ensure both the model and the input tensor are on the same device before profiling, for example: `model.to('cuda')` and `inputs.to('cuda')`.You likely need to implement and register a custom MACs handler for that specific module type. Refer to `torchprofile.handlers` for examples and instructions on `register_macs_handler`.