{"id":4019,"library":"fvcore","title":"FVCore: FAIR Computer Vision Core Library","description":"fvcore is a lightweight core library that provides common and essential functionalities shared across various computer vision frameworks developed by FAIR (Facebook AI Research), such as Detectron2, PySlowFast, and ClassyVision. It includes features like PyTorch layers, hierarchical flop/parameter counting tools, checkpointing utilities, configuration management, and hyperparameter schedulers. The library is actively maintained by the FAIR computer vision team and features type-annotated, tested, and benchmarked components.","status":"active","version":"0.1.5.post20221221","language":"en","source_language":"en","source_url":"https://github.com/facebookresearch/fvcore","tags":["computer vision","pytorch","utilities","facebook research","FAIR","model analysis","flops"],"install":[{"cmd":"pip install -U fvcore","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core functionality is built on PyTorch.","package":"torch","optional":false},{"reason":"The PathManager utility was deprecated in fvcore and moved to iopath. Direct migration is recommended.","package":"iopath","optional":false},{"reason":"Used for configuration management via CfgNode.","package":"yacs","optional":true}],"imports":[{"symbol":"FlopCountAnalysis","correct":"from fvcore.nn import FlopCountAnalysis"},{"symbol":"ActivationCountAnalysis","correct":"from fvcore.nn import ActivationCountAnalysis"},{"symbol":"CfgNode","correct":"from fvcore.common.config import CfgNode"},{"symbol":"Registry","correct":"from fvcore.common.registry import Registry"},{"symbol":"Checkpointer","correct":"from fvcore.common.checkpoint import Checkpointer"}],"quickstart":{"code":"import torch\nimport torch.nn as nn\nfrom fvcore.nn import FlopCountAnalysis\n\nclass SimpleModel(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)\n        self.relu = nn.ReLU()\n        self.pool = nn.MaxPool2d(kernel_size=2, stride=2)\n        self.fc = nn.Linear(16 * 16 * 16, 10) # Assuming input size 3x32x32\n\n    def forward(self, x):\n        x = self.pool(self.relu(self.conv1(x)))\n        x = x.view(x.size(0), -1)\n        x = self.fc(x)\n        return x\n\nmodel = SimpleModel()\ninputs = (torch.randn(1, 3, 32, 32),) # Batch size 1, 3 channels, 32x32 image\n\nflops = FlopCountAnalysis(model, inputs)\nprint(f\"Total FLOPs: {flops.total()}\")\nprint(f\"FLOPs by operator: {flops.by_operator()}\")\nprint(f\"FLOPs by module: {flops.by_module()}\")","lang":"python","description":"This quickstart demonstrates how to use `fvcore.nn.FlopCountAnalysis` to calculate the computational FLOPs (Floating Point Operations) of a simple PyTorch model. It initializes a model, creates dummy input, and then uses `FlopCountAnalysis` to report total FLOPs and FLOPs aggregated by operator and module."},"warnings":[{"fix":"Be aware of these limitations. For precise FLOP counting, manual verification or alternative tools might be necessary, or consider `ActivationCountAnalysis` for memory footprint as a supplementary metric.","message":"fvcore's `FlopCountAnalysis` is known to severely undercount FLOPs for certain operations. It may not count activation functions, trigonometric functions, element-wise operations (like addition/multiplication), and bias in linear/convolution layers. This can lead to significant discrepancies between reported and actual FLOPs, especially for complex models or models with many such operations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace `from fvcore.common.file_io import PathManager` with `from iopath.common.file_io import PathManager` in your code. Ensure `iopath` is installed (`pip install iopath`).","message":"The `fvcore.common.file_io.PathManager` utility has been deprecated. Users are advised to migrate to `iopath.common.file_io.PathManager` from the `iopath` library. Continued use of the fvcore version might result in deprecation warnings.","severity":"deprecated","affected_versions":"All versions, specifically from late 2020/early 2021 onwards"},{"fix":"Avoid combining `FlopCountAnalysis` directly with `torch.compile` or `torch.jit.trace` on the same model/function for which FLOPs are being counted. Consider performing FLOP analysis on the base model before applying such optimizations, or use a separate model instance for analysis.","message":"Using `FlopCountAnalysis` or other tracing tools with functions optimized by `torch.compile` or traced by `torch.jit.trace` can lead to `NotImplementedError` or `RuntimeError`. The tracing mechanism might not be fully compatible with these advanced PyTorch features.","severity":"gotcha","affected_versions":"All versions, particularly with newer PyTorch features (>= 1.8 for some quantization features, >= 1.11 for others)."}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}