{"id":21018,"library":"calflops","title":"CalFlops","description":"CalFlops is a PyTorch-based FLOPs, MACs, and parameter counter for neural networks including CNNs, RNNs, GCNs, and Transformers (e.g., BERT, LLaMA). Version 0.3.2 supports custom models. Released as needed on GitHub.","status":"active","version":"0.3.2","language":"python","source_language":"en","source_url":"https://github.com/MrYxJ/calculate-flops.pytorch","tags":["flops","macs","parameters","pytorch","model-analysis"],"install":[{"cmd":"pip install calflops","lang":"bash","label":"pip install"}],"dependencies":[{"reason":"Core dependency for model definitions and tensors.","package":"torch","optional":false}],"imports":[{"wrong":"from calflops import calculate_flops","symbol":"calculate_flops","correct":"from calflops import calculate_flops"}],"quickstart":{"code":"import torch\nimport torchvision.models as models\nfrom calflops import calculate_flops\n\nmodel = models.resnet18()\nbatch_size = 1\ninput_shape = (batch_size, 3, 224, 224)\nflops, macs, params = calculate_flops(\n    model=model,\n    input_shape=input_shape,\n    output_as_string=True,\n    output_precision=4\n)\nprint(f\"FLOPs: {flops}, MACs: {macs}, Params: {params}\")","lang":"python","description":"Compute FLOPs, MACs, and parameters for a ResNet-18 model."},"warnings":[{"fix":"Set model.eval() before calling calculate_flops to disable dropout/batchnorm effects.","message":"Torchvision models may include non-parameter operations (like softmax) that are counted differently. Ensure model is in eval mode.","severity":"gotcha","affected_versions":"all"},{"fix":"Pass a callable that returns a tuple of tensors: input_constructor=lambda: (x,).","message":"If model has multiple inputs (e.g., encoders), use input_constructor instead of input_shape.","severity":"gotcha","affected_versions":"all"},{"fix":"If using control flow, test with a simple forward pass first and verify counts are reasonable.","message":"FLOPs counting for dynamic architectures (e.g., with torch.where) may be inaccurate due to static graph assumption.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.3.2':26 'analysi':41 'base':7 'bert':23 'calflop':1,2 'cnns':17 'counter':12 'custom':28 'e.g':22 'flop':8,35 'gcns':19 'github':34 'includ':16 'llama':24 'mac':9,36 'model':29,40 'model-analysi':39 'need':32 'network':15 'neural':14 'paramet':11,37 'pytorch':6,38 'pytorch-bas':5 'releas':30 'rnns':18 'support':27 'transform':21 'version':25","created_at":"2026-04-27T16:57:40.371925+00:00","updated_at":"2026-04-27T16:57:40.371925+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmp99ps2w79/venv/lib/python3.12/site-packages/calflops/__init__.py\", line 16, in <module>\n    from .flops_counter_hf import calculate_flops_hf\n  File \"/tmp/tmp99ps2w79/venv/lib/python3.12/site-packages/calflops/fl"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.3.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/MrYxJ/calculate-flops.pytorch","docs":null,"changelog":null,"pypi":"https://pypi.org/project/calflops/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}