{"record":{"id":"e88f00e671f0fed3","repo":"tensorflow/models","slug":"y-pred-must-be-of-type-twotowertrainingoutputs-b-e88f00","errorCode":null,"errorMessage":"y_pred must be of type `TwoTowerTrainingOutputs` but got type {type(y_pred)} instead.","messagePattern":"y_pred must be of type `TwoTowerTrainingOutputs` but got type (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/metrics/label_variance.py","lineNumber":92,"sourceCode":"      y_pred: types.TwoTowerTrainingOutputs,\n      sample_weight: tf.Tensor | None = None,\n  ):\n    \"\"\"Updates the overall, control and treatment label variances.\n\n    Args:\n      y_true: tensor labels.\n      y_pred: two tower training outputs. The treatment indicator tensor is used\n        to slice the labels into control and treatment groups.\n      sample_weight: optional sample weight to compute weighted label variances.\n        If given, the sample weight will also be sliced by the treatment\n        indicator tensor to compute the weighted control and treatment label\n        variances.\n\n    Raises:\n      TypeError: if y_pred is not of type `TwoTowerTrainingOutputs`.\n    \"\"\"\n    if not isinstance(y_pred, types.TwoTowerTrainingOutputs):\n      raise TypeError(\n          \"y_pred must be of type `TwoTowerTrainingOutputs` but got type\"\n          f\" {type(y_pred)} instead.\"\n      )\n\n    self._sliced_variance.update_state(\n        values=y_true,\n        is_treatment=y_pred.is_treatment,\n        sample_weight=sample_weight,\n    )\n\n  def result(self) -> dict[str, tf.Tensor]:\n    return self._sliced_variance.result()\n","sourceCodeStart":74,"sourceCodeEnd":105,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/metrics/label_variance.py#L74-L105","documentation":"Type guard in LabelVariance.update_state: variance-by-treatment-group requires the treatment indicator inside TwoTowerTrainingOutputs; the received y_pred type carries none, so slicing into control/treatment groups cannot proceed.","triggerScenarios":"Thrown at official/recommendation/uplift/metrics/label_variance.py:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass TwoTowerTrainingOutputs from the two-tower model as y_pred","Ensure the model's train_step returns the full outputs tuple, not just logits"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}