{"record":{"id":"a2cbfac23ceb4fe3","repo":"tensorflow/models","slug":"y-pred-must-be-of-type-twotowertrainingoutputs","errorCode":null,"errorMessage":"y_pred must be of type `TwoTowerTrainingOutputs`, `tf.Tensor` or `np.ndarray` but got type {type(y_pred)} instead.","messagePattern":"y_pred must be of type `TwoTowerTrainingOutputs`, `tf\\.Tensor` or `np\\.ndarray` but got type (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/metrics/loss_metric.py","lineNumber":160,"sourceCode":"        given, the sample weight will also be sliced by the treatment indicator\n        tensor to compute the weighted control and treatment losses.\n\n    Raises:\n      TypeError: if `y_pred` is not of type `TwoTowerTrainingOutputs`.\n    \"\"\"\n    if isinstance(y_pred, (tf.Tensor, np.ndarray)):\n      if self._slice_by_treatment:\n        raise ValueError(\n            \"`slice_by_treatment` must be False when y_pred is a `tf.Tensor` or\"\n            \" `np.ndarray`.\"\n        )\n      pred = y_pred\n    elif isinstance(y_pred, types.TwoTowerTrainingOutputs):\n      pred = (\n          y_pred.true_logits if self._from_logits else y_pred.true_predictions\n      )\n    else:\n      raise TypeError(\n          \"y_pred must be of type `TwoTowerTrainingOutputs`, `tf.Tensor` or\"\n          f\" `np.ndarray` but got type {type(y_pred)} instead.\"\n      )\n\n    is_treatment = {}\n    if self._slice_by_treatment:\n      is_treatment[\"is_treatment\"] = y_pred.is_treatment\n\n    if isinstance(self._loss_fn, tf_keras.metrics.Metric):\n      self._loss.update_state(\n          y_true,\n          y_pred=pred,  # pyrefly: ignore[unexpected-keyword]\n          sample_weight=sample_weight,\n          **is_treatment,\n      )\n    else:\n      self._loss.update_state(\n          values=self._loss_fn(y_true, pred, **self._loss_fn_kwargs),  # pyrefly: ignore[bad-argument-type]","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/metrics/loss_metric.py#L142-L178","documentation":"Error \"y_pred must be of type `TwoTowerTrainingOutputs`, `tf.Tensor` or `np.ndarray` but got type {type(y_pred)} instead.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/uplift/metrics/loss_metric.py:160 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"}