tensorflow/models · error · ValueError
is_treatment must be a tensor castable to boolean but got te
Error message
is_treatment must be a tensor castable to boolean but got tensor {is_treatment} of dtype {is_treatment.dtype} instead. What it means
Error "is_treatment must be a tensor castable to boolean but got tensor {is_treatment} of dtype {is_treatment.dtype} instead." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/utils.py:68
A tuple with control and treatment values sliced by the is_treatment tensor.
"""
if is_treatment.shape.rank > 2 or (
is_treatment.shape == 2 and is_treatment.shape[1] != 1 # pyrefly: ignore[unsupported-operation]
):
raise ValueError(
"is_treatment tensor must be a tensor of shape (D0,) (D0, 1) but got a"
f" tensor of shape {is_treatment.shape} instead."
)
if values.shape[0] != is_treatment.shape[0]:
raise ValueError(
"values and is_treatment must be tensors of shapes (D0, D1, ..., DN)"
f" and (D0, 1) (or (D0,)), but got tensors of shapes {values.shape} and"
f" {is_treatment.shape} respectively."
)
if is_treatment.dtype == tf.string:
raise ValueError(
"is_treatment must be a tensor castable to boolean but got tensor"
f" {is_treatment} of dtype {is_treatment.dtype} instead."
)
# Assert is_treatment tensor containss only 0 or 1 values.
if is_treatment.dtype != tf.bool:
is_treatment_float = tf.cast(is_treatment, tf.float32)
tf.debugging.assert_equal(
tf.reduce_all(
tf.logical_or(is_treatment_float == 1.0, is_treatment_float == 0.0)
),
tf.convert_to_tensor(True),
message=(
"When is_treatment is not a boolean tensor all of its values must"
f" either be 0 or 1, but got tensor {is_treatment} instead."
),
)
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/utils.py:68 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/6c2e55a6c58c2332.
Report an issue: GitHub.