tensorflow/models · error · ValueError
distribution_strategy must be a string but got: %s.
Error message
distribution_strategy must be a string but got: %s.
What it means
Error "distribution_strategy must be a string but got: %s." thrown in tensorflow/models.
Source
Thrown at official/common/distribute_utils.py:139
Returns:
tf.distribute.Strategy object.
Raises:
ValueError: if `distribution_strategy` is "off" or "one_device" and
`num_gpus` is larger than 1; or `num_gpus` is negative or if
`distribution_strategy` is `tpu` but `tpu_address` is not specified.
"""
del kwargs
if num_gpus < 0:
raise ValueError("`num_gpus` can not be negative.")
if not isinstance(distribution_strategy, str):
msg = ("distribution_strategy must be a string but got: %s." %
(distribution_strategy,))
if distribution_strategy == False: # pylint: disable=singleton-comparison,g-explicit-bool-comparison
msg += (" If you meant to pass the string 'off', make sure you add "
"quotes around 'off' so that yaml interprets it as a string "
"instead of a bool.")
raise ValueError(msg)
distribution_strategy = distribution_strategy.lower()
if distribution_strategy == "off":
if num_gpus > 1:
raise ValueError(f"When {num_gpus} GPUs are specified, "
"distribution_strategy flag cannot be set to `off`.")
# Return the default distribution strategy.
return tf.distribute.get_strategy()
if distribution_strategy == "tpu":
# When tpu_address is an empty string, we communicate with local TPUs.
# Bug workaround that in v5p we need to explicitly specify the device
# assignment when using tpu strategy, adding device assignment to the
# strategy.
cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver(
tpu=tpu_address
)
if tpu_address not in ("", "local"):View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/common/distribute_utils.py:139 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/eddc2794fe0cf5e7.
Report an issue: GitHub.