{"record":{"id":"587088e0288e4c89","repo":"tensorflow/models","slug":"slice-by-treatment-must-be-set-to-false-when","errorCode":null,"errorMessage":"`slice_by_treatment` must be set to `False` when `y_pred` is not of type `TwoTowerTrainingOutputs`.","messagePattern":"`slice_by_treatment` must be set to `False` when `y_pred` is not of type `TwoTowerTrainingOutputs`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/metrics/poisson_metrics.py","lineNumber":180,"sourceCode":"    self._slice_by_treatment = slice_by_treatment\n\n    if slice_by_treatment:\n      self._mean_label = treatment_sliced_metric.TreatmentSlicedMetric(\n          metric=tf_keras.metrics.Mean(name=name, dtype=dtype)\n      )\n    else:\n      self._mean_label = tf_keras.metrics.Mean(name=name, dtype=dtype)\n\n  def update_state(\n      self,\n      y_true: tf.Tensor,\n      y_pred: types.TwoTowerTrainingOutputs | tf.Tensor | None = None,\n      sample_weight: tf.Tensor | None = None,\n  ):\n    is_treatment = {}\n    if self._slice_by_treatment:\n      if not isinstance(y_pred, types.TwoTowerTrainingOutputs):\n        raise ValueError(\n            \"`slice_by_treatment` must be set to `False` when `y_pred` is not\"\n            \" of type `TwoTowerTrainingOutputs`.\"\n        )\n      is_treatment[\"is_treatment\"] = y_pred.is_treatment\n\n    self._mean_label.update_state(\n        y_true, sample_weight=sample_weight, **is_treatment\n    )\n\n  def result(self) -> tf.Tensor | dict[str, tf.Tensor]:\n    return tf.nest.map_structure(_safe_x_minus_xlogx, self._mean_label.result())\n\n  def get_config(self) -> dict[str, Any]:\n    config = super().get_config()\n    config[\"compute_full_loss\"] = self._compute_full_loss\n    config[\"slice_by_treatment\"] = self._slice_by_treatment\n    return config\n","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/metrics/poisson_metrics.py#L162-L198","documentation":"Error \"`slice_by_treatment` must be set to `False` when `y_pred` is not of type `TwoTowerTrainingOutputs`.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/uplift/metrics/poisson_metrics.py:180 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"}