flopscope.
Getting Started

Quickstart

Run your first FLOP-counted computation in under 2 minutes.

You will learn:

  • How to run a FLOP-counted computation with the global default budget
  • How to read the budget summary output

Prerequisites

Quickest possible start

You do not need to set up a budget context to start counting FLOPs. flopscope activates a global default context the first time any counted operation runs. The default budget is 1e15 FLOPs (configurable via the FLOPSCOPE_DEFAULT_BUDGET environment variable).

Save this as first_budget.py:

import flopscope as flops
import flopscope.numpy as fnp

depth = 10   # number of layers
width = 256  # hidden dimension

# No BudgetContext needed — the global default activates automatically
scale = fnp.sqrt(2.0 / width)     # Kaiming init scale: counted through flopscope
weights = [
    fnp.array(fnp.multiply(fnp.random.randn(width, width), scale))
    for _ in range(depth)
]
x = fnp.random.randn(width)

h = x
for W in weights:
    h = fnp.einsum('ij,j->i', W, h)  # matrix-vector multiply
    h = fnp.maximum(h, 0)             # ReLU activation: counted

result = fnp.sum(h)                   # reduction: counted

# Print the default flat summary
flops.budget_summary()

Run it:

uv run python first_budget.py

What you'll see

flopscope FLOP Budget Summary
=========================
  Total budget:    1,000,000,000,000,000
  Used:                       2,624,513  (0.0%)
  Remaining:        999,999,997,375,487  (100.0%)

  By operation:
    random.randn              655,616  ( 25.0%)  [11 calls]
    multiply                  655,360  ( 25.0%)  [10 calls]
    array                     655,360  ( 25.0%)  [10 calls]
    einsum                    655,360  ( 25.0%)  [10 calls]
    maximum                     2,560  (  0.1%)  [10 calls]
    sum                           256  (  0.0%)  [1 call]
    sqrt                            1  (  0.0%)  [1 call]

  By operation (time):
    random.randn           ...s  ( ...%)  [11 calls]
    multiply               ...s  ( ...%)  [10 calls]
    einsum                 ...s  ( ...%)  [10 calls]
    array                  ...s  ( ...%)  [10 calls]
    maximum                ...s  ( ...%)  [10 calls]
    sum                    ...s  ( ...%)  [1 call]
    sqrt                   ...s  ( ...%)  [1 call]

Reading the output:

  • Top rows: Used is the total FLOP count spent so far across the current session, and Remaining shows the implicit global headroom
  • Flat default: the summary stays flat unless you explicitly ask for flops.budget_summary(by_namespace=True)
  • Operations table: the 10-layer MLP spreads FLOPs roughly equally across random.randn, multiply, array, and einsum (~25% each); activations (maximum) are comparatively cheap, and the Kaiming scale sqrt adds just 1 FLOP

If you want namespace attribution, opt in separately:

with flops.BudgetContext(flop_budget=10**6, namespace="train") as budget:
    with fnp.namespace("precompute"):
        ...
    print(budget.summary(by_namespace=True))

Next steps

Ready for budget limits? See the Competition Guide.

On this page