本文整理汇总了Python中tensorflow.python.distribute.cluster_resolver.TPUClusterResolver.num_accelerators方法的典型用法代码示例。如果您正苦于以下问题:Python TPUClusterResolver.num_accelerators方法的具体用法?Python TPUClusterResolver.num_accelerators怎么用?Python TPUClusterResolver.num_accelerators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.distribute.cluster_resolver.TPUClusterResolver
的用法示例。
在下文中一共展示了TPUClusterResolver.num_accelerators方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNumAcceleratorsRetryFailure
# 需要导入模块: from tensorflow.python.distribute.cluster_resolver import TPUClusterResolver [as 别名]
# 或者: from tensorflow.python.distribute.cluster_resolver.TPUClusterResolver import num_accelerators [as 别名]
def testNumAcceleratorsRetryFailure(self, mock_list_devices,
mock_eager_list_devices):
resolver = TPUClusterResolver(tpu='')
mock_list_devices.side_effect = errors.DeadlineExceededError(
None, None, 'timeout')
mock_eager_list_devices.side_effect = errors.DeadlineExceededError(
None, None, 'timeout')
with self.assertRaises(RuntimeError):
resolver.num_accelerators()
示例2: testNumAcceleratorsSuccess
# 需要导入模块: from tensorflow.python.distribute.cluster_resolver import TPUClusterResolver [as 别名]
# 或者: from tensorflow.python.distribute.cluster_resolver.TPUClusterResolver import num_accelerators [as 别名]
def testNumAcceleratorsSuccess(self, mock_list_devices):
device_names = [
'/job:tpu_worker/task:0/device:TPU:0',
'/job:tpu_worker/task:1/device:TPU:1',
'/job:tpu_worker/task:2/device:TPU:0',
'/job:tpu_worker/task:3/device:TPU:1',
'/job:tpu_worker/task:0/device:TPU:4',
'/job:tpu_worker/task:1/device:TPU:5',
'/job:tpu_worker/task:2/device:TPU:4',
'/job:tpu_worker/task:3/device:TPU:5',
]
device_list = [
session._DeviceAttributes(
name, 'TPU', 1024, 0) for name in device_names
]
mock_list_devices.return_value = device_list
resolver = TPUClusterResolver(tpu='')
self.assertEqual(resolver.num_accelerators(), 2)