{"record":{"id":"eddc2794fe0cf5e7","repo":"tensorflow/models","slug":"distribution-strategy-must-be-a-string-but-got-s","errorCode":null,"errorMessage":"distribution_strategy must be a string but got: %s.","messagePattern":"distribution_strategy must be a string but got: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/common/distribute_utils.py","lineNumber":139,"sourceCode":"  Returns:\n    tf.distribute.Strategy object.\n  Raises:\n    ValueError: if `distribution_strategy` is \"off\" or \"one_device\" and\n      `num_gpus` is larger than 1; or `num_gpus` is negative or if\n      `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\"):","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/common/distribute_utils.py#L121-L157","documentation":"Error \"distribution_strategy must be a string but got: %s.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/common/distribute_utils.py:139 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"}