{"record":{"id":"57126fbdf06d0dd4","repo":"tensorflow/models","slug":"when-num-gpus-gpus-are-specified-distribution-s","errorCode":null,"errorMessage":"When {num_gpus} GPUs are specified, distribution_strategy flag cannot be set to `off`.","messagePattern":"When (.+?) GPUs are specified, distribution_strategy flag cannot be set to `off`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/common/distribute_utils.py","lineNumber":144,"sourceCode":"      `distribution_strategy` is `tpu` but `tpu_address` is not specified.\n  \"\"\"\n  del kwargs\n  if num_gpus < 0:\n    raise ValueError(\"`num_gpus` can not be negative.\")\n\n  if not isinstance(distribution_strategy, str):\n    msg = (\"distribution_strategy must be a string but got: %s.\" %\n           (distribution_strategy,))\n    if distribution_strategy == False:  # pylint: disable=singleton-comparison,g-explicit-bool-comparison\n      msg += (\" If you meant to pass the string 'off', make sure you add \"\n              \"quotes around 'off' so that yaml interprets it as a string \"\n              \"instead of a bool.\")\n    raise ValueError(msg)\n\n  distribution_strategy = distribution_strategy.lower()\n  if distribution_strategy == \"off\":\n    if num_gpus > 1:\n      raise ValueError(f\"When {num_gpus} GPUs are specified, \"\n                       \"distribution_strategy flag cannot be set to `off`.\")\n    # Return the default distribution strategy.\n    return tf.distribute.get_strategy()\n\n  if distribution_strategy == \"tpu\":\n    # When tpu_address is an empty string, we communicate with local TPUs.\n    # Bug workaround that in v5p we need to explicitly specify the device\n    # assignment when using tpu strategy, adding device assignment to the\n    # strategy.\n    cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver(\n        tpu=tpu_address\n    )\n    if tpu_address not in (\"\", \"local\"):\n      tf.config.experimental_connect_to_cluster(cluster_resolver)\n    topology = tf.tpu.experimental.initialize_tpu_system(cluster_resolver)\n\n    device_assignment = None\n    if hasattr(tf.tpu.experimental, \"HardWareFeature\"):","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/common/distribute_utils.py#L126-L162","documentation":"Error \"When {num_gpus} GPUs are specified, distribution_strategy flag cannot be set to `off`.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/common/distribute_utils.py:144 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"}