{"record":{"id":"0e0f5ae954a77964","repo":"Lightning-AI/pytorch-lightning","slug":"you-called-self-log-self-meta-name-r-in","errorCode":null,"errorMessage":"You called `self.log({self.meta.name!r}, ...)` in your `{self.meta.fx}` but the value needs to be floating to be reduced. Converting it to {dtype}. You can silence this warning by converting the value to floating point yourself. If you don't intend to reduce the value (for instance when logging the global step or epoch) then you can use `self.logger.log_metrics({{{self.meta.name!r}: ...}})` instead.","messagePattern":"You called `self\\.log\\((.+?), \\.\\.\\.\\)` in your `(.+?)` but the value needs to be floating to be reduced\\. Converting it to (.+?)\\. You can silence this warning by converting the value to floating point yourself\\. If you don't intend to reduce the value \\(for instance when logging the global step or epoch\\) then you can use `self\\.logger\\.log_metrics\\((.+?): \\.\\.\\.\\}\\}\\)` instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lightning/pytorch/trainer/connectors/logger_connector/result.py","lineNumber":212,"sourceCode":"            elif metadata.is_min_reduction:\n                default = float(\"inf\")\n            else:\n                default = 0.0\n            # the logged value will be stored in float32 or higher to maintain accuracy\n            self.add_state(\"value\", torch.tensor(default, dtype=_get_default_dtype()), dist_reduce_fx=torch.sum)\n            if self.meta.is_mean_reduction:\n                self.cumulated_batch_size: Tensor\n                self.add_state(\"cumulated_batch_size\", torch.tensor(0), dist_reduce_fx=torch.sum)\n        # this is defined here only because upstream is missing the type annotation\n        self._forward_cache: Optional[Any] = None\n\n    @override\n    def update(self, value: _VALUE, batch_size: int) -> None:\n        if self.is_tensor:\n            value = cast(Tensor, value)\n            dtype = _get_default_dtype()\n            if not torch.is_floating_point(value):\n                warning_cache.warn(\n                    # do not include the value to avoid cache misses\n                    f\"You called `self.log({self.meta.name!r}, ...)` in your `{self.meta.fx}` but the value needs to\"\n                    f\" be floating to be reduced. Converting it to {dtype}.\"\n                    \" You can silence this warning by converting the value to floating point yourself.\"\n                    \" If you don't intend to reduce the value (for instance when logging the global step or epoch) then\"\n                    f\" you can use `self.logger.log_metrics({{{self.meta.name!r}: ...}})` instead.\"\n                )\n                value = value.to(dtype)\n            if value.dtype not in (torch.float32, torch.float64):\n                value = value.to(dtype)\n\n            if self.meta.on_step:\n                self._forward_cache = self.meta.sync(value.clone())  # `clone` because `sync` is in-place\n                # performance: no need to accumulate on values only logged on_step\n                if not self.meta.on_epoch:\n                    self.value = self._forward_cache\n                    return\n","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/logger_connector/result.py#L194-L230","documentation":"Result metric update warns when self.log receives a non-floating tensor (int/long/bool). Reduction ops need floats, so Lightning converts it to the default dtype. The message suggests converting yourself or using logger.log_metrics for non-reducible values like step/epoch numbers.","triggerScenarios":"self.log('epoch', self.current_epoch) or self.log('count', int_tensor) inside training_step/validation_step; logging integer counters that get mean-reduced.","commonSituations":"Logging global step, batch index, or integer counts; debugging code that logs tensor shapes or indices.","solutions":["Convert to float: self.log('n', float(value)) or value.float()","For non-reducible scalars (step/epoch), use self.logger.log_metrics({'epoch': value}, step=...) or enable enable_graph-free logging without reduction","Pass reduce_fx that tolerates ints is not supported — casting is the fix"],"exampleFix":"# before\nself.log('num_tokens', num_tokens)  # long tensor -> warning\n# after\nself.log('num_tokens', num_tokens.float())","handlingStrategy":"type-guard","validationCode":"val = torch.as_tensor(val)\nif val.is_floating_point():\n    self.log(name, val, batch_size=bs)\nelse:\n    self.log(name, val.float(), batch_size=bs)","typeGuard":"def is_float_tensor(v) -> bool:\n    import torch\n    return torch.is_tensor(v) and torch.is_floating_point(v)","tryCatchPattern":null,"preventionTips":["Cast to .float() before logging metrics","Use self.logger.log_metrics for step/epoch counters"],"tags":["logging","dtype","metrics","lightning"],"backgroundTag":"log-value-dtype-mismatch","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}