tensorflow/models · error · ValueError
When {num_gpus} GPUs are specified, distribution_strategy fl
Error message
When {num_gpus} GPUs are specified, distribution_strategy flag cannot be set to `off`. What it means
Error "When {num_gpus} GPUs are specified, distribution_strategy flag cannot be set to `off`." thrown in tensorflow/models.
Source
Thrown at official/common/distribute_utils.py:144
`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"):
tf.config.experimental_connect_to_cluster(cluster_resolver)
topology = tf.tpu.experimental.initialize_tpu_system(cluster_resolver)
device_assignment = None
if hasattr(tf.tpu.experimental, "HardWareFeature"):View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/common/distribute_utils.py:144 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/57126fbdf06d0dd4.
Report an issue: GitHub.