FlopCounterMode#
- class torch.utils.flop_counter.FlopCounterMode(mods=None, depth=2, display=True, custom_mapping=None)[source]#
Count theoretical FLOPs for operators that run inside the context.
FlopCounterModeusesTorchDispatchModeto intercept operations and apply registered FLOP formulas. Counts are shape-based and formula-defined; unsupported operations contribute zero FLOPs unless they decompose into supported operations.The optional
modsargument is no longer needed for module attribution. Whendisplayis true, exiting the context prints a table. Useget_total_flops()orget_flop_counts()to read the same information programmatically.Example usage:
mod = ... inp = ... with FlopCounterMode(display=False) as flop_counter: mod(inp).sum().backward() total = flop_counter.get_total_flops()