{"record":{"id":"fb3af058c75741a7","repo":"Lightning-AI/pytorch-lightning","slug":"you-tried-to-log-v-which-is-currently-not-suppor","errorCode":null,"errorMessage":"you tried to log {v} which is currently not supported. Try a dict or a scalar/tensor.","messagePattern":"you tried to log (.+?) which is currently not supported\\. Try a dict or a scalar/tensor\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/loggers/tensorboard.py","lineNumber":216,"sourceCode":"    @override\n    @rank_zero_only\n    def log_metrics(self, metrics: Mapping[str, float], step: Optional[int] = None) -> None:\n        assert rank_zero_only.rank == 0, \"experiment tried to log from global_rank != 0\"\n\n        metrics = _add_prefix(metrics, self._prefix, self.LOGGER_JOIN_CHAR)\n\n        for k, v in metrics.items():\n            if isinstance(v, Tensor):\n                v = v.item()\n\n            if isinstance(v, dict):\n                self.experiment.add_scalars(k, v, step)\n            else:\n                try:\n                    self.experiment.add_scalar(k, v, step)\n                # TODO(fabric): specify the possible exception\n                except Exception as ex:\n                    raise ValueError(\n                        f\"\\n you tried to log {v} which is currently not supported. Try a dict or a scalar/tensor.\"\n                    ) from ex\n\n    @override\n    @rank_zero_only\n    def log_hyperparams(\n        self,\n        params: Union[dict[str, Any], Namespace],\n        metrics: Optional[dict[str, Any]] = None,\n        step: Optional[int] = None,\n    ) -> None:\n        \"\"\"Record hyperparameters. TensorBoard logs with and without saved hyperparameters are incompatible, the\n        hyperparameters are then not displayed in the TensorBoard. Please delete or move the previously saved logs to\n        display the new ones with hyperparameters.\n\n        Args:\n            params: A dictionary-like container with the hyperparameters\n            metrics: Dictionary with metric names as keys and measured quantities as values","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/loggers/tensorboard.py#L198-L234","documentation":"Raised by TensorBoardLogger's `log_metrics` when a metric value cannot be written via `experiment.add_scalar` — i.e. it is not a scalar number, a 0-d/1-element tensor, or a dict of such values. The bare `except Exception` wraps any backend failure into this ValueError.","triggerScenarios":"Passing metrics whose values are lists, multi-element tensors, strings, or None; nested dicts that fall into the non-dict branch; tensors with shape (N,) of multiple values. Also triggered when add_scalar itself rejects the value type.","commonSituations":"Logging a full prediction array, a confusion matrix, or a batch of losses instead of their mean; logging string metrics; logging numpy arrays with more than one element.","solutions":["Reduce the value to a scalar before logging: `float(value.mean())` or `value.item()` for single-element tensors","For multi-value data, log each entry as its own key or use a dedicated summary writer method (add_histogram etc.) outside log_metrics","Sanitize your metrics dict: keep only numbers or 0-d tensors"],"exampleFix":"# before\nlogger.log_metrics({'preds': preds_batch, 'loss': loss})  # preds_batch is shape (B, C)\n\n# after\nlogger.log_metrics({'loss': loss.item(), 'pred_mean': preds_batch.mean().item()})","handlingStrategy":"validation","validationCode":"import math\ndef sanitize(metrics):\n    return {k: (float(v) if not hasattr(v, 'mean') else float(v.mean())) for k, v in metrics.items()}","typeGuard":null,"tryCatchPattern":"try:\n    logger.log_metrics(metrics, step=step)\nexcept ValueError:\n    logger.log_metrics(sanitize(metrics), step=step)","preventionTips":["Only log numbers/0-d tensors; aggregate batches to scalars before logging","Test metric shapes once in CI"],"tags":["pytorch-lightning","tensorboard","logging","type-validation"],"backgroundTag":"invalid-metric-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}