Пример #1
0
  def call(self,
           method_name: str,
           args: Optional[Sequence[core_tf_types.Tensor]] = None,
           output_specs=None,
           timeout_in_ms=0):
    """Method to invoke remote registered functions on the connected server.

    Server should be started before making an RPC Call.

    Args:
      method_name: Registered method to invoke on Server.
      args: Input arguments for the method.
      output_specs: Output specs for the output from method.
      timeout_in_ms: Timeout for this call. If 0, default client timeout will be
       used.

    Returns:
      StatusOrResult object. This function issues the RPC call to server, it
      does not block for the duration of RPC. Please call is_ok, get_error or
      get_value methods on the returned object to blocked till RPC finishes.
    """
    if args is None:
      args = []
    status_or, deleter = gen_rpc_ops.rpc_call(
        self._client_handle,
        args=nest.flatten(args),
        method_name=method_name,
        timeout_in_ms=timeout_in_ms)
    return StatusOrResult(status_or, deleter, output_specs)
Пример #2
0
 def call_wrapper(*args, timeout_in_ms=0):
   status_or, deleter = gen_rpc_ops.rpc_call(
       client_handle,
       args=validate_and_get_flat_inputs(*args),
       method_name=method_name,
       timeout_in_ms=timeout_in_ms)
   return StatusOrResult(status_or, deleter, output_specs)
Пример #3
0
 def call_blocking_wrapper(*args, timeout_in_ms=0):
     status_or, deleter = gen_rpc_ops.rpc_call(
         client_handle,
         args=validate_and_get_flat_inputs(*args),
         method_name=method_name,
         timeout_in_ms=timeout_in_ms)
     status_or = StatusOrResult(status_or, deleter, output_specs)
     if status_or.is_ok():
         return status_or.get_value()
     else:
         error_code, error_msg = status_or.get_error()
         raise errors.exception_type_from_error_code(
             error_code.numpy())(None, None, error_msg.numpy())
Пример #4
0
    def call(self,
             method_name: str,
             args: Optional[Sequence[core_tf_types.Tensor]] = None,
             output_specs=None):
        """Method to invoke remote registered functions on the connected server.

    Server should be started before making an RPC Call.

    Args:
      method_name: Registered method to invoke on Server.
      args: Input arguments for the method.
      output_specs: Output specs for the output from method.
       For example, if tf function is:
         @tf.function(input_signature=[
            tensor_spec.TensorSpec([], tf.int32),
            tensor_spec.TensorSpec([], tf.int32)
        ])
        def multiply_fn(a, b):
          return tf.math.multiply(a, b)

       output_spec is: tf.TensorSpec((), tf.int32)

       If you have access to TF Function, the output specs can be generated
       from tf.function by calling:
         output_specs = tf.nest.map_structure(tf.type_spec_from_value,
                  tf_function.get_concrete_function().structured_outputs)

    Returns:
      StatusOrResult object. This function issues the RPC call to server, it
      does not block for the duration of RPC. Please call is_ok, get_error or
      get_value methods on the returned object to blocked till RPC finishes.
    """
        if args is None:
            args = []
        status_or, deleter = gen_rpc_ops.rpc_call(self._client_handle,
                                                  args=nest.flatten(args),
                                                  method_name=method_name)
        return StatusOrResult(status_or, deleter, output_specs)