{"record":{"id":"3bc7a7520d9263ad","repo":"tensorflow/models","slug":"num-gpus-can-not-be-negative","errorCode":null,"errorMessage":"`num_gpus` can not be negative.","messagePattern":"`num_gpus` can not be negative\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/common/distribute_utils.py","lineNumber":130,"sourceCode":"      \"hierarchical_copy\". For `MultiWorkerMirroredStrategy`, valid values are\n      \"ring\" and \"nccl\".  If None, DistributionStrategy will choose based on\n      device topology.\n    num_packs: Optional.  Sets the `num_packs` in `tf.distribute.NcclAllReduce`\n      or `tf.distribute.HierarchicalCopyAllReduce` for `MirroredStrategy`.\n    tpu_address: Optional. String that represents TPU to connect to. Must not be\n      None if `distribution_strategy` is set to `tpu`.\n    **kwargs: Additional kwargs for internal usages.\n\n  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","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/common/distribute_utils.py#L112-L148","documentation":"Error \"`num_gpus` can not be negative.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/common/distribute_utils.py:130 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"}