Skip to content

Instantly share code, notes, and snippets.

@Leumastai
Created July 4, 2023 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leumastai/4aa25b47b267175cbc32bc6d5ba02ad2 to your computer and use it in GitHub Desktop.
Save Leumastai/4aa25b47b267175cbc32bc6d5ba02ad2 to your computer and use it in GitHub Desktop.
fvcore flops calculator fo pytorch model
$ from fvcore.nn import FlopCountAnalysis
$ flops = FlopCountAnalysis(model, input)
$ flops.total()
-> 274656
$ flops.by_operator()
-> Counter({'conv': 194616, 'addmm': 80040})
$ flops.by_module()
-> Counter({'': 274656, 'conv1': 48600,
-> 'conv2': 146016, 'fc1': 69120,
-> 'fc2': 10080, 'fc3': 840})
$ flops.by_module_and_operator()
-> {'': Counter({'conv': 194616, 'addmm': 80040}),
-> 'conv1': Counter({'conv': 48600}),
-> 'conv2': Counter({'conv': 146016}),
-> 'fc1': Counter({'addmm': 69120}),
-> 'fc2': Counter({'addmm': 10080}),
-> 'fc3': Counter({'addmm': 840})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment