Пример #1
0
def _bind_comp_as_reference(comp):
    fc_context = context_stack_impl.context_stack.current
    if not isinstance(fc_context, symbol_binding_context.SymbolBindingContext):
        raise context_base.ContextError(
            f'Attempted to construct an intrinsic in context {fc_context} which '
            ' does not support binding references.')
    return fc_context.bind_computation_to_reference(comp)
Пример #2
0
def _check_symbol_binding_context(context: context_base.Context):
  if not isinstance(context, symbol_binding_context.SymbolBindingContext):
    raise context_base.ContextError('TFF values should only be materialized '
                                    'inside a context which can bind '
                                    'references, generally a '
                                    '`FederatedComputationContext`. Attempted '
                                    'to materialize a TFF value in a context '
                                    '{c} of type {t}.'.format(
                                        c=context, t=type(context)))
Пример #3
0
def _bind_computation_to_reference(comp, op: str):
    context = context_stack_impl.context_stack.current
    if not isinstance(context, symbol_binding_context.SymbolBindingContext):
        raise context_base.ContextError(
            '`tff.Value`s should only be used in contexts which can bind '
            'references, generally a `FederatedComputationContext`. Attempted '
            f'to bind the result of {op} in a context {context} of '
            f'type {type(context)}.')
    return context.bind_computation_to_reference(comp)
Пример #4
0
def get_session_token() -> tf.Tensor:
  """Returns a string tensor identifying the current session."""
  context = context_stack_impl.context_stack.current
  if not isinstance(context, TensorFlowComputationContext):
    raise context_base.ContextError(
        'Session tokens can only be retrieved from within the '
        '`TensorFlowComputationContext (in a `@tff.tf_computation`). '
        f'Instead, the context {context} of type {type(context)} was found.')
  return context.session_token
Пример #5
0
 def _bind_comp_as_reference(self, comp):
   fc_context = self._context_stack.current
   if not isinstance(fc_context, symbol_binding_context.SymbolBindingContext):
     raise context_base.ContextError(
         'Intrsinics cannot be constructed without '
         'the ability to bind references to the '
         'generated ASTs; attempted to construct '
         'an intrinsic in context {c} which '
         'exposes no such mechanism.'.format(c=fc_context))
   return fc_context.bind_computation_to_reference(comp)