๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #457

FLOPs

FLOPs (floating-point operations) measure the actual computational cost of running a model โ€” a complementary metric to parameter count that more directly reflects compute requirements and inference speed.

FLOPs vs Parameter Count โ€” Why Both Are Reported

MetricWhat It MeasuresLimitation
Parameter countTotal learnable capacity / model sizeDoesn't directly indicate compute cost (especially for sparse/MoE architectures)
FLOPsActual computational operations required for one forward passDoesn't directly indicate memory requirements or capacity

Together, these two metrics give a more complete picture than either alone โ€” a model can be reported as, for example, "7B parameters, 15 GFLOPs per forward pass," giving readers a sense of both its scale/capacity and its actual runtime computational cost.

Computing FLOPs for Common Operations

OperationApproximate FLOPs
Fully-connected layer (matrix multiply)\(2 \times \text{input\_dim} \times \text{output\_dim}\) (the factor of 2 accounts for both a multiply and an add per computation)
Convolutional layer\(2 \times \text{kernel\_h} \times \text{kernel\_w} \times \text{in\_channels} \times \text{out\_channels} \times \text{output\_h} \times \text{output\_w}\)

Code โ€” Measuring a Model's FLOPs

from fvcore.nn import FlopCountAnalysis
import torch

model = MyModel()
dummy_input = torch.randn(1, 3, 224, 224)

flop_analysis = FlopCountAnalysis(model, dummy_input)
total_flops = flop_analysis.total()

print(f"Total FLOPs for one forward pass: {total_flops:,}")
print(f"That's {total_flops / 1e9:.2f} GFLOPs")

Why FLOPs Matters Practically

FLOPs correlates much more directly with actual inference latency and energy cost than parameter count alone โ€” two models with identical parameter counts but different architectures (e.g. different amounts of weight sharing or activation reuse) can have meaningfully different FLOPs, and therefore meaningfully different real-world inference speed, even at the same nominal "model size."

FLOPs Isn't the Whole Story Either

Real-world inference latency also depends on factors FLOPs doesn't capture directly โ€” memory bandwidth (moving data can be as much of a bottleneck as computing on it), hardware-specific optimization (how well an operation maps to available hardware acceleration), and parallelization efficiency. This is exactly why the practical latency profiling covered in Inference Latency (Research) and memory requirements analysis remain necessary alongside theoretical FLOPs counting, not a full replacement for it.

Common Mistakes

  • Assuming lower FLOPs always means faster real-world inference โ€” memory bandwidth bottlenecks and hardware-specific efficiency can sometimes matter more than raw FLOPs count for actual measured latency.
  • Reporting only parameter count without FLOPs (or vice versa) when comparing model efficiency โ€” the two metrics capture genuinely different, complementary aspects of computational cost.

Interview Relevance

Q: "Why do research papers often report both parameter count and FLOPs, rather than just one or the other?" Parameter count reflects a model's total learnable capacity/size but doesn't directly indicate actual computational cost, particularly for architectures like Mixture of Experts where most parameters go unused per input. FLOPs directly measures the computational operations required per forward pass, correlating more closely with real inference speed and energy cost โ€” but doesn't capture memory requirements or capacity on its own. Reporting both together gives a more complete picture of a model's efficiency profile than either metric alone would provide.

Practice Question

Why might two models with identical FLOPs still show meaningfully different measured inference latency on the same hardware?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

FLOPs โ€“ FAQs

Quick answers about learning FLOPs in Deep Learning.

This free note from CodingNow 2.0 explains FLOPs in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including FLOPs, is 100% free with no signup required.
With focused practice, most students grasp FLOPs in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now