tensorflow/models · error · ValueError
`slice_by_treatment` must be set to `False` when `y_pred` is
Error message
`slice_by_treatment` must be set to `False` when `y_pred` is not of type `TwoTowerTrainingOutputs`.
What it means
Error "`slice_by_treatment` must be set to `False` when `y_pred` is not of type `TwoTowerTrainingOutputs`." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/metrics/poisson_metrics.py:180
self._slice_by_treatment = slice_by_treatment
if slice_by_treatment:
self._mean_label = treatment_sliced_metric.TreatmentSlicedMetric(
metric=tf_keras.metrics.Mean(name=name, dtype=dtype)
)
else:
self._mean_label = tf_keras.metrics.Mean(name=name, dtype=dtype)
def update_state(
self,
y_true: tf.Tensor,
y_pred: types.TwoTowerTrainingOutputs | tf.Tensor | None = None,
sample_weight: tf.Tensor | None = None,
):
is_treatment = {}
if self._slice_by_treatment:
if not isinstance(y_pred, types.TwoTowerTrainingOutputs):
raise ValueError(
"`slice_by_treatment` must be set to `False` when `y_pred` is not"
" of type `TwoTowerTrainingOutputs`."
)
is_treatment["is_treatment"] = y_pred.is_treatment
self._mean_label.update_state(
y_true, sample_weight=sample_weight, **is_treatment
)
def result(self) -> tf.Tensor | dict[str, tf.Tensor]:
return tf.nest.map_structure(_safe_x_minus_xlogx, self._mean_label.result())
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config["compute_full_loss"] = self._compute_full_loss
config["slice_by_treatment"] = self._slice_by_treatment
return config
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/poisson_metrics.py:180 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/587088e0288e4c89.
Report an issue: GitHub.