Ejemplo n.º 1
0
def create_local_executor(num_clients):
  """Constructs an executor to execute computations on the local machine.

  The initial temporary implementation requires that the number of clients be
  specified in advance. This limitation will be removed in the near future.

  NOTE: This function is only available in Python 3.

  Args:
    num_clients: The number of clients.

  Returns:
    An instance of `tff.framework.Executor` for single-machine use only.
  """
  # TODO(b/134543154): We should not have to specif the number of clients; this
  # needs to go away once we flesh out all the remaining bits ad pieces.

  py_typecheck.check_type(num_clients, int)
  bottom_ex = lambda_executor.LambdaExecutor(eager_executor.EagerExecutor())

  def _make(n):
    return [concurrent_executor.ConcurrentExecutor(bottom_ex) for _ in range(n)]

  return lambda_executor.LambdaExecutor(
      federated_executor.FederatedExecutor({
          None: _make(1),
          placement_literals.SERVER: _make(1),
          placement_literals.CLIENTS: _make(num_clients)
      }))
def _make_test_executor(num_clients=1):
  eager_ex = eager_executor.EagerExecutor()
  return federated_executor.FederatedExecutor({
      placements.SERVER: eager_ex,
      placements.CLIENTS: [eager_ex for _ in range(num_clients)],
      None: eager_ex
  })
Ejemplo n.º 3
0
def _create_federated_stack(num_clients):
  executor_dict = {
      placement_literals.CLIENTS: [
          _create_bottom_stack() for _ in range(num_clients)
      ],
      placement_literals.SERVER: _create_bottom_stack(),
      None: _create_bottom_stack()
  }
  return _complete_stack(federated_executor.FederatedExecutor(executor_dict))
def _make_test_executor(num_clients=1, use_lambda_executor=False):
  bottom_ex = eager_executor.EagerExecutor()
  if use_lambda_executor:
    bottom_ex = lambda_executor.LambdaExecutor(bottom_ex)
  return federated_executor.FederatedExecutor({
      placements.SERVER: bottom_ex,
      placements.CLIENTS: [bottom_ex for _ in range(num_clients)],
      None: bottom_ex
  })
Ejemplo n.º 5
0
def create_local_executor(num_clients=None):
  """Constructs an executor to execute computations on the local machine.

  The initial temporary implementation requires that the number of clients be
  specified in advance. This limitation will be removed in the near future.

  NOTE: This function is only available in Python 3.

  Args:
    num_clients: The number of clients. If not specified (`None`), then this
      executor is not federated (can only execute unplaced computations).

  Returns:
    An instance of `tff.framework.Executor` for single-machine use only.

  Raises:
    ValueError: If the number of clients is not one or larger.
  """

  def _create_single_worker_stack():
    ex = eager_executor.EagerExecutor()
    ex = concurrent_executor.ConcurrentExecutor(ex)
    ex = caching_executor.CachingExecutor(ex)
    return lambda_executor.LambdaExecutor(ex)

  if num_clients is None:
    return _create_single_worker_stack()
  else:
    # TODO(b/134543154): We shouldn't have to specif the number of clients; this
    # needs to go away once we flesh out all the remaining bits ad pieces.
    py_typecheck.check_type(num_clients, int)
    if num_clients < 1:
      raise ValueError('If the number of clients is present, it must be >= 1.')

    def _create_multiple_worker_stacks(num_workers):
      return [_create_single_worker_stack() for _ in range(num_workers)]

    return lambda_executor.LambdaExecutor(
        caching_executor.CachingExecutor(
            federated_executor.FederatedExecutor({
                None:
                    _create_multiple_worker_stacks(1),
                placement_literals.SERVER:
                    _create_multiple_worker_stacks(1),
                placement_literals.CLIENTS:
                    (_create_multiple_worker_stacks(num_clients))
            })))
Ejemplo n.º 6
0
 def _create_variable_clients_executors(x):
     """Constructs executor stacks from `dict` argument."""
     py_typecheck.check_type(x, dict)
     for k, v in six.iteritems(x):
         py_typecheck.check_type(k, placement_literals.PlacementLiteral)
         if v <= 0:
             raise ValueError(
                 'Cardinality must be at '
                 'least one; you have passed {} for placement {}.'.format(
                     v, k))
     executor_dict = dict([(placement, _create_multiple_worker_stacks(n))
                           for placement, n in six.iteritems(x)])
     executor_dict.update({None: _create_multiple_worker_stacks(1)})
     executor_dict.update(
         {placement_literals.SERVER: _create_multiple_worker_stacks(1)})
     return lambda_executor.LambdaExecutor(
         caching_executor.CachingExecutor(
             federated_executor.FederatedExecutor(executor_dict)))
Ejemplo n.º 7
0
 def _return_executor(x):
     del x  # Unused
     return lambda_executor.LambdaExecutor(
         caching_executor.CachingExecutor(
             federated_executor.FederatedExecutor(executor_dict)))