{"record":{"id":"2531c655933fa345","repo":"Lightning-AI/pytorch-lightning","slug":"error-2531c6","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/logger_connector/result.py","lineNumber":137,"sourceCode":"    _sync: Optional[_Sync] = None\n\n    def __post_init__(self) -> None:\n        if not self.on_step and not self.on_epoch:\n            raise MisconfigurationException(\"`self.log(on_step=False, on_epoch=False)` is not useful.\")\n        self._parse_reduce_fx()\n\n    def _parse_reduce_fx(self) -> None:\n        error = (\n            \"Only `self.log(..., reduce_fx={min,max,mean,sum})` are supported.\"\n            \" If you need a custom reduction, please log a `torchmetrics.Metric` instance instead.\"\n            f\" Found: {self.reduce_fx}\"\n        )\n        if isinstance(self.reduce_fx, str):\n            reduce_fx = self.reduce_fx.lower()\n            if reduce_fx == \"avg\":\n                reduce_fx = \"mean\"\n            if reduce_fx not in (\"min\", \"max\", \"mean\", \"sum\"):\n                raise MisconfigurationException(error)\n            self.reduce_fx = getattr(torch, reduce_fx)\n        elif self.is_custom_reduction:\n            raise MisconfigurationException(error)\n\n    @property\n    def sync(self) -> _Sync:\n        assert self._sync is not None\n        return self._sync\n\n    @sync.setter\n    def sync(self, sync: _Sync) -> None:\n        if sync.op is None:\n            sync.op = self.reduce_fx.__name__\n        self._sync = sync\n\n    @property\n    def forked(self) -> bool:\n        return self.on_step and self.on_epoch","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/logger_connector/result.py#L119-L155","documentation":"When reduce_fx is given as a string, _parse_reduce_fx lowercases it, maps 'avg' to 'mean', and only accepts {'min','max','mean','sum'}; any other string raises this MisconfigurationException. Non-builtin reductions must be expressed via a torchmetrics.Metric, not a custom callable.","triggerScenarios":"self.log('x', x, reduce_fx='median'), reduce_fx='AVG' is fine (mapped to mean) but reduce_fx='std' or 'rms' raises; any string outside min/max/mean/sum (after the avg->mean aliasing).","commonSituations":"Porting code that used 'avg' in older Lightning plus adding other names like 'average' (invalid); trying to get median or std of a metric via a string shortcut instead of implementing a Metric.","solutions":["Use one of the supported strings: reduce_fx='mean' (or 'min'/'max'/'sum'); note 'avg' also works via aliasing","For median/std/custom reductions, log a torchmetrics.Metric instance instead of a tensor with reduce_fx","Pass a supported torch function directly if the string variant is limiting, keeping within the supported set"],"exampleFix":"# before\nself.log('loss', loss, reduce_fx='median')\n\n# after\nself.median = torchmetrics.Median()\nself.log('loss', self.median(loss))  # or use a torchmetrics aggregation metric","handlingStrategy":"validation","validationCode":"assert reduce_fx in (\"min\", \"max\", \"mean\", \"sum\", \"avg\"), \"unsupported reduce_fx string\"","typeGuard":"from typing import Union\n\ndef is_supported_reduce_str(reduce_fx: str) -> bool:\n    return reduce_fx.lower() in (\"min\", \"max\", \"mean\", \"sum\", \"avg\")","tryCatchPattern":null,"preventionTips":["Stick to the four documented strings; remember 'avg' aliases 'mean'","For anything else use torchmetrics.Metric","Grep for reduce_fx= during Lightning upgrades"],"tags":["pytorch-lightning","logging","reduce-fx","misconfiguration"],"backgroundTag":"unsupported-reduction-function","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}