{"record":{"id":"7a220b7337b40d37","repo":"Lightning-AI/pytorch-lightning","slug":"spikedetection-requires-torchmetrics-1-0-0-plea","errorCode":null,"errorMessage":"SpikeDetection requires `torchmetrics>=1.0.0` Please upgrade your version.","messagePattern":"SpikeDetection requires `torchmetrics>=1\\.0\\.0` Please upgrade your version\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/utilities/spike.py","lineNumber":52,"sourceCode":"        finite_only: If set to ``False``, consider non-finite values like NaN, inf and -inf a spike as well.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        mode: Literal[\"min\", \"max\"] = \"min\",\n        window: int = 10,\n        warmup: int = 1,\n        atol: Optional[float] = None,\n        rtol: Optional[float] = 2.0,\n        exclude_batches_path: Optional[_PATH] = None,\n        finite_only: bool = True,\n    ):\n        if _TORCHMETRICS_GREATER_EQUAL_1_0_0:\n            from torchmetrics.aggregation import MeanMetric\n            from torchmetrics.wrappers import Running\n        else:\n            raise RuntimeError(\"SpikeDetection requires `torchmetrics>=1.0.0` Please upgrade your version.\")\n        super().__init__()\n\n        self.last_val: Union[torch.Tensor, float] = 0.0\n        # spike detection happens individually on each machine\n        self.running_mean = Running(MeanMetric(dist_sync_on_step=False, sync_on_compute=False), window=window)\n        # workaround for https://github.com/Lightning-AI/torchmetrics/issues/1899\n        self.running_mean.dist_sync_on_step = False\n        self.running_mean.sync_on_compute = False\n\n        self.mode = mode\n        self.warmup = warmup\n        self.atol = atol\n        self.rtol = rtol\n        self.bad_batches: list[int] = []\n        self.exclude_batches_path = exclude_batches_path\n        self.finite_only = finite_only\n\n    @torch.no_grad()","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/utilities/spike.py#L34-L70","documentation":"Lightning's `SpikeDetection` callback/metric uses `torchmetrics.aggregation.MeanMetric` and `torchmetrics.wrappers.Running`, both introduced in torchmetrics 1.0. On import at construction time it checks `_TORCHMETRICS_GREATER_EQUAL_1_0_0` and raises RuntimeError if the installed torchmetrics is older (0.11.x and below).","triggerScenarios":"Instantiating `SpikeDetection(...)` (usually as a Trainer callback) with torchmetrics < 1.0.0 installed, e.g. pinned by an old environment or another package constraint.","commonSituations":"Old conda/pip environments, `lightning` installed alongside legacy `pytorch-lightning` pins that force torchmetrics 0.x, CI images with stale dependencies.","solutions":["Upgrade: `pip install -U torchmetrics` (>=1.0.0)","Check for conflicting pins: `pip check` / `pip install -U lightning` to let it pull a compatible torchmetrics","If you must stay on torchmetrics 0.x, remove the SpikeDetection callback"],"exampleFix":"# before  (torchmetrics 0.11)\ntrainer = Trainer(callbacks=[SpikeDetection()])  # RuntimeError\n\n# after\n# pip install -U \"torchmetrics>=1.0.0\"\ntrainer = Trainer(callbacks=[SpikeDetection()])","handlingStrategy":"validation","validationCode":"import torchmetrics\nfrom packaging.version import Version\nassert Version(torchmetrics.__version__) >= Version(\"1.0.0\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin torchmetrics>=1.0.0 alongside lightning","Run pip check after environment changes to catch conflicting pins"],"tags":["lightning","torchmetrics","version-mismatch"],"backgroundTag":"dependency-version-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}