{"record":{"id":"eb7406db2aeeec87","repo":"tensorflow/models","slug":"from-logits-must-be-set-to-true-when-y-pred","errorCode":null,"errorMessage":"`from_logits` must be set to `True` when `y_pred` is of type TwoTowerTrainingOutputs. Note that the true logits and true predictions are assumed to be linked to each other through the log link function: `true_logits = tf.math.log(true_predictions).","messagePattern":"`from_logits` must be set to `True` when `y_pred` is of type TwoTowerTrainingOutputs\\. Note that the true logits and true predictions are assumed to be linked to each other through the log link function: `true_logits = tf\\.math\\.log\\(true_predictions\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/metrics/poisson_metrics.py","lineNumber":107,"sourceCode":"    \"\"\"\n    super().__init__(\n        loss_fn=tf.nn.log_poisson_loss,\n        from_logits=from_logits,\n        compute_full_loss=compute_full_loss,\n        slice_by_treatment=slice_by_treatment,\n        name=name,\n        dtype=dtype,\n    )\n\n  def update_state(\n      self,\n      y_true: tf.Tensor,\n      y_pred: types.TwoTowerTrainingOutputs | tf.Tensor,\n      sample_weight: tf.Tensor | None = None,\n  ):\n    if not self._from_logits:\n      if isinstance(y_pred, types.TwoTowerTrainingOutputs):\n        raise ValueError(\n            \"`from_logits` must be set to `True` when `y_pred` is of type\"\n            \" TwoTowerTrainingOutputs. Note that the true logits and true\"\n            \" predictions are assumed to be linked to each other through the\"\n            \" log link function: `true_logits = tf.math.log(true_predictions).\"\n        )\n      y_pred = tf.math.log(y_pred)\n\n    super().update_state(y_true, y_pred, sample_weight)\n\n  def get_config(self) -> dict[str, Any]:\n    config = super().get_config()\n    del config[\"loss_fn\"]\n    return config\n\n  @classmethod\n  def from_config(cls, config: dict[str, Any]) -> LogLoss:\n    return cls(**config)\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/metrics/poisson_metrics.py#L89-L125","documentation":"Error \"`from_logits` must be set to `True` when `y_pred` is of type TwoTowerTrainingOutputs. Note that the true logits and true predictions are assumed to be linked to each other through the log link function: `true_logits = tf.math.log(true_predictions).\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/uplift/metrics/poisson_metrics.py:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}