FLOPSCOPE · A FLOP-COUNTING NUMPY
Count every FLOP.
A NumPy-compatible math library that counts every FLOP analytically, so compute budgets stop being guesswork.
uv add flopscope
508Operations
NumPy-compatible operations with analytical FLOP costs.
πSymmetry-aware
Symmetry metadata propagates through the chain, so costs scale with unique elements.
∞Composable
Budget contexts, namespaces, and per-operation breakdowns.
IN ACTION
What does this code cost?
Same five-layer MLP, written twice. The one on the right counts every FLOP analytically as it runs.
NumPy
import numpy as np depth, width = 5, 256 # Weight initscale = np.sqrt(2 / width)weights = [ np.random.randn(width, width) * scale for _ in range(depth)] # Forward passx = np.random.randn(width)h = xfor i, W in enumerate(weights): h = np.einsum('ij,j->i', W, h) if i < depth - 1: h = np.maximum(h, 0)# Total FLOPs? No idea.Flopscope
import flopscope as flopsimport flopscope.numpy as fnp depth, width = 5, 256 # Weight initscale = fnp.sqrt(2 / width)weights = [ fnp.random.randn(width, width) * scale for _ in range(depth)] # Forward passx = fnp.random.randn(width)h = xfor i, W in enumerate(weights): h = fnp.einsum('ij,j->i', W, h) if i < depth - 1: h = fnp.maximum(h, 0)flops.budget_summary() # 984,321 FLOPsThe answer, on the right: 984,321 FLOPs — counted analytically as the NumPy call runs.
READ ON
