fvcore

repository·main·Indexed 25 days ago

https://github.com/facebookresearch/fvcore

A lightweight core library providing type-annotated and benchmarked functionality for FAIR computer vision frameworks such as Detectron2, PySlowFast, and ClassyVision. It includes tools for FLOP and parameter counting via FlopCountAnalysis and parameter_count, BatchNorm population statistics updates, and a stateless hyperparameter scheduler.

Tokens
503
Snippets
0
Records
4
Agent score
31%

What's inside fvcore

  1. Overview of fvcore features

    main

    fvcore is a lightweight core library providing essential functionality used across FAIR computer vision frameworks like Detectron2, PySlowFast, and ClassyVision. Key features include:

    • fvcore.nn: Common PyTorch layers, functions, and losses.
    • FLOP Counting: A hierarchical per-operator FLOP counting tool.
    • Parameter Counting: Recursive parameter counting via fvcore.nn.parameter_count.
    • BatchNorm Updates: Tools to recompute BatchNorm population statistics via fvcore.nn.update_bn_stats.
    • Hyperparameter Scheduling: A stateless, scale-invariant scheduler via fvcore.common.param_scheduler.ParamScheduler.
  2. Analyze activation counts with ActivationCountAnalysis

    main
    In addition to FLOPs, fvcore provides fvcore.nn.ActivationCountAnalysis to collect operator-level statistics such as activation counts. This is useful for research where FLOP counts may not correlate perfectly with GPU latency, as activation counts or memory footprint can serve as alternative metrics for model efficiency.
  3. Analyze PyTorch model FLOPs with FlopCountAnalysis

    main

    Use fvcore.nn.FlopCountAnalysis to calculate both operator-level and module-level FLOP counts for a PyTorch model. The tool works by tracing the model's execution to observe operator calls and their input/output shapes.

    Key features:

    • Total FLOPs: Get the overall count for the model.
    • Operator-level counts: See counts broken down by specific operators (e.g., conv, addmm).
    • Module-level counts: See counts aggregated by the nn.Module hierarchy.
    • Hierarchical breakdown: View which operators belong to which modules.

    Requirements & Limitations:

    • The tool uses torch.jit.trace, so it only traces the model.forward method.
    • Inputs and outputs of model.forward must be (a tuple of) tensors. If your model uses custom classes, wrap it in a simple wrapper to make it traceable.
    • It may under-count if heavy computations only affect control flow and are pruned by JIT tracing.