{"record":{"id":"90fbd6a7beafaf18","repo":"tensorflow/models","slug":"spatial-partitioning-is-only-supported-for-tpustra","errorCode":null,"errorMessage":"Spatial partitioning is only supported for TPUStrategy.","messagePattern":"Spatial partitioning is only supported for TPUStrategy\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/train_spatial_partitioning.py","lineNumber":74,"sourceCode":"  elif num_logical_devices == 8:\n    return [2, 2, 1, 2]\n  elif num_logical_devices == 16:\n    return [4, 2, 1, 2]\n  else:\n    raise ValueError(\n        'The number of logical devices %d is not supported. Supported numbers '\n        'are 1, 2, 4, 8, 16' % num_logical_devices)\n\n\ndef create_distribution_strategy(distribution_strategy,\n                                 tpu_address,\n                                 input_partition_dims=None,\n                                 num_gpus=None):\n  \"\"\"Creates distribution strategy to use for computation.\"\"\"\n\n  if input_partition_dims is not None:\n    if distribution_strategy != 'tpu':\n      raise ValueError('Spatial partitioning is only supported '\n                       'for TPUStrategy.')\n\n    # When `input_partition_dims` is specified create custom TPUStrategy\n    # instance with computation shape for model parallelism.\n    resolver = tf.distribute.cluster_resolver.TPUClusterResolver(\n        tpu=tpu_address)\n    if tpu_address not in ('', 'local'):\n      tf.config.experimental_connect_to_cluster(resolver)\n\n    topology = tf.tpu.experimental.initialize_tpu_system(resolver)\n    num_replicas = resolver.get_tpu_system_metadata().num_cores // np.prod(\n        input_partition_dims)\n    device_assignment = tf.tpu.experimental.DeviceAssignment.build(\n        topology,\n        num_replicas=num_replicas,\n        computation_shape=input_partition_dims)\n    return tf.distribute.TPUStrategy(\n        resolver, experimental_device_assignment=device_assignment)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/train_spatial_partitioning.py#L56-L92","documentation":"Error \"Spatial partitioning is only supported for TPUStrategy.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/train_spatial_partitioning.py:74 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run under TPUStrategy when using spatial partitioning.","Disable spatial partitioning when training on GPU/CPU."],"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"}