calculate-flops.pytorch  by MrYxJ

PyTorch tool to calculate FLOPs, MACs, and parameters for neural networks

created 1 year ago
835 stars

Top 43.5% on sourcepulse

GitHubView on GitHub
Project Summary

This library calculates FLOPs, MACs, and parameters for various neural networks in PyTorch, including CNNs, RNNs, GCNs, and Transformers (like BERT and LLaMA). It's useful for researchers and engineers needing to understand model computational complexity and resource consumption, offering detailed breakdowns per submodule.

How It Works

The tool instruments PyTorch models to count operations. For Hugging Face models, it can perform calculations remotely without downloading weights, leveraging meta-device inference or requiring a tokenizer for input generation. It supports custom models by tracing operations through torch.nn.functional.

Quick Start & Requirements

Highlighted Details

  • Supports calculating FLOPs for Hugging Face models by name, avoiding local downloads.
  • Can include backward pass FLOPs with a configurable factor.
  • Provides detailed breakdowns of FLOPs, MACs, and parameters for each submodule.
  • Offers flexible output formatting (string, precision, units).

Maintenance & Community

The project is maintained by MrYxJ. Further community engagement details are not explicitly provided in the README.

Licensing & Compatibility

The README does not explicitly state a license. Compatibility for commercial use or closed-source linking is not specified.

Limitations & Caveats

The tool's accuracy relies on PyTorch's tracing capabilities and may not perfectly capture all hardware-specific optimizations. Some models might require specific tokenizer configurations for accurate input generation. The README mentions that FLOPs for activation recomputation are not included by default but can be approximated by multiplying forward FLOPs by 4 or setting compute_bp_factor=3.

Health Check
Last commit

1 year ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
1
Star History
58 stars in the last 90 days

Explore Similar Projects

Starred by Ying Sheng Ying Sheng(Author of SGLang) and Stas Bekman Stas Bekman(Author of Machine Learning Engineering Open Book; Research Engineer at Snowflake).

llm-analysis by cli99

0%
441
CLI tool for LLM latency/memory analysis during training/inference
created 2 years ago
updated 3 months ago
Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems) and Jeremy Howard Jeremy Howard(Cofounder of fast.ai).

GPTFast by MDK8888

0%
685
HF Transformers accelerator for faster inference
created 1 year ago
updated 11 months ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera), and
2 more.

gemma_pytorch by google

0.1%
6k
PyTorch implementation for Google's Gemma models
created 1 year ago
updated 2 months ago
Feedback? Help us improve.