def master(self, task_type=None, task_index=None, rpc_layer=None): """Returns the master address to use when creating a session. You must have set the task_type and task_index object properties before calling this function, or pass in the `task_type` and `task_index` parameters when using this function. If you do both, the function parameters will override the object properties. Args: task_type: (Optional) The type of the TensorFlow task of the master. task_index: (Optional) The index of the TensorFlow task of the master. rpc_layer: (Optional) The RPC protocol for the given cluster. Returns: The name or URL of the session master. """ if task_type is not None and task_index is not None: return format_master_url( self.cluster_spec().task_address(task_type, task_index), rpc_layer or self.rpc_layer) if self.task_type is not None and self.task_index is not None: return format_master_url( self.cluster_spec().task_address(self.task_type, self.task_index), rpc_layer or self.rpc_layer) return ''
def master(self, task_type=None, task_index=None, rpc_layer=None): """Returns the master address to use when creating a session. You must have set the task_type and task_index object properties before calling this function, or pass in the `task_type` and `task_index` parameters when using this function. If you do both, the function parameters will override the object properties. Args: task_type: (Optional) The type of the TensorFlow task of the master. task_index: (Optional) The index of the TensorFlow task of the master. rpc_layer: (Optional) The RPC protocol for the given cluster. Returns: The name or URL of the session master. """ if task_type is not None and task_index is not None: return format_master_url( self.cluster_spec().task_address(task_type, task_index), rpc_layer or self.rpc_layer) if self.task_type is not None and self.task_index is not None: return format_master_url( self.cluster_spec().task_address(self.task_type, self.task_index), rpc_layer or self.rpc_layer) return ''
def master(self, task_type=None, task_id=None, rpc_layer=None): """Get the Master string to be used for the session. In the normal case, this returns the grpc path (grpc://1.2.3.4:8470) of first instance in the ClusterSpec returned by the cluster_spec function. If a non-TPU name is used when constructing a TPUClusterResolver, that will be returned instead (e.g. If the tpus argument's value when constructing this TPUClusterResolver was 'grpc://10.240.1.2:8470', 'grpc://10.240.1.2:8470' will be returned). Args: task_type: (Optional, string) The type of the TensorFlow task of the master. task_id: (Optional, integer) The index of the TensorFlow task of the master. rpc_layer: (Optional, string) The RPC protocol TensorFlow should use to communicate with TPUs. Returns: string, the connection string to use when creating a session. Raises: ValueError: If none of the TPUs specified exists. """ if self._should_resolve(): # We are going to communicate with the Cloud TPU APIs to get a Cluster. cluster_spec = self.cluster_spec() if task_type is not None and task_id is not None: # task_type and task_id is from the function parameter master = cluster_spec.task_address(task_type, task_id) elif self.task_type is not None and self.task_id is not None: # task_type and task_id is from the object master = cluster_spec.task_address(self.task_type, self.task_id) else: # by default we take the first item in the cluster with the right name job_tasks = cluster_spec.job_tasks(self.task_type) if not job_tasks: raise ValueError('No TPUs with the specified names exist.') master = job_tasks[0] else: if isinstance(self._tpu, (bytes, bytearray)): master = compat.as_text( self._tpu).split(_ENDPOINTS_SEPARATOR)[0] else: master = self._tpu.split(_ENDPOINTS_SEPARATOR)[0] return format_master_url(master, rpc_layer or self.rpc_layer)
def master(self, task_type=None, task_id=None, rpc_layer=None): """Get the Master string to be used for the session. In the normal case, this returns the grpc path (grpc://1.2.3.4:8470) of first instance in the ClusterSpec returned by the cluster_spec function. If a non-TPU name is used when constructing a TPUClusterResolver, that will be returned instead (e.g. If the tpus argument's value when constructing this TPUClusterResolver was 'grpc://10.240.1.2:8470', 'grpc://10.240.1.2:8470' will be returned). Args: task_type: (Optional, string) The type of the TensorFlow task of the master. task_id: (Optional, integer) The index of the TensorFlow task of the master. rpc_layer: (Optional, string) The RPC protocol TensorFlow should use to communicate with TPUs. Returns: string, the connection string to use when creating a session. Raises: ValueError: If none of the TPUs specified exists. """ if self._shouldResolve(): # We are going to communicate with the Cloud TPU APIs to get a Cluster. cluster_spec = self.cluster_spec() if task_type is not None and task_id is not None: # task_type and task_id is from the function parameter master = cluster_spec.task_address(task_type, task_id) elif self.task_type is not None and self.task_id is not None: # task_type and task_id is from the object master = cluster_spec.task_address(self.task_type, self.task_id) else: # by default we take the first item in the cluster with the right name job_tasks = cluster_spec.job_tasks(self.task_type) if not job_tasks: raise ValueError('No TPUs with the specified names exist.') master = job_tasks[0] else: if isinstance(self._tpu, (bytes, bytearray)): master = self._tpu.split(compat.as_bytes(_ENDPOINTS_SEPARATOR))[0] else: master = self._tpu.split(_ENDPOINTS_SEPARATOR)[0] return format_master_url(master, rpc_layer or self.rpc_layer)
def master(self, task_type=None, task_id=None, rpc_layer=None): """Returns the master string for connecting to a TensorFlow master. Args: task_type: (Optional) Overrides the default auto-selected task type. task_id: (Optional) Overrides the default auto-slected task index. rpc_layer: (Optional) Overrides the default RPC protocol TensorFlow uses to communicate across nodes. Returns: A connection string for connecting to a TensorFlow master. """ task_type = task_type if task_type is not None else self.task_type task_id = task_id if task_id is not None else self.task_id if task_type is not None and task_id is not None: return format_master_url( self.cluster_spec().task_address(task_type, task_id), rpc_layer or self.rpc_layer) return ''
def master(self, task_type=None, task_id=None, rpc_layer=None): """Returns the master string for connecting to a TensorFlow master. Args: task_type: (Optional) Overrides the default auto-selected task type. task_id: (Optional) Overrides the default auto-slected task index. rpc_layer: (Optional) Overrides the default RPC protocol TensorFlow uses to communicate across nodes. Returns: A connection string for connecting to a TensorFlow master. """ task_type = task_type if task_type is not None else self.task_type task_id = task_id if task_id is not None else self.task_id if task_type is not None and task_id is not None: return format_master_url( self.cluster_spec().task_address(task_type, task_id), rpc_layer or self.rpc_layer) return ''
def master(self, task_type=None, task_id=None, rpc_layer=None): """Retrieves the name or URL of the session master. Args: task_type: (Optional) The type of the TensorFlow task of the master. task_id: (Optional) The index of the TensorFlow task of the master. rpc_layer: (Optional) The RPC protocol for the given cluster. Returns: The name or URL of the session master. Implementors of this function must take care in ensuring that the master returned is up-to-date at the time to calling this function. This usually means retrieving the master every time this function is invoked. """ task_type = task_type if task_type is not None else self.task_type task_id = task_id if task_id is not None else self.task_id if task_type is not None and task_id is not None: return format_master_url( self.cluster_spec().task_address(task_type, task_id), rpc_layer or self.rpc_layer) return ''