tff.program.FederatedContext
Stay organized with collections
Save and categorize content based on your preferences.
An abstract interface representing a federated context.
Inherits From: SyncContext
A federated context supports invoking a limited set of tff.Computation
s,
making guarantees about what a tff.Computation
can accept as an argument and
what it returns when invoked.
Restrictions on the TensorFlow Federated Type
Arguments can be nested structures of values corresponding to the TensorFlow
Federated type signature of the tff.Computation
:
Return values can be structures of tff.program.MaterializableValueReference
s
or a single tff.program.MaterializableValueReference
, where a reference
corresponds to the tensor-type of the TensorFlow Federated type signature in
the return value of the invoked tff.Computation
.
TensorFlow Federated Type to Python Representation
In order to interact with the value returned by a tff.Computation
, it is
helpful to be able to reason about the Python type of this value. In some way
this Python type must depend on the TensorFlow Federated type signature of the
associated value. To provide uniformity of experience and ease of reasoning,
we specify the Python representation of values in a manner that can be stated
entirely in the TensorFlow Federated typesystem.
We have chosen to limit the TensorFlow Federated type signatures of invoked
tff.Computation
s to disallow the returning of client-placed values,
tff.SequenceTypes
, and tff.FunctionTypes
, in order to reduced the area
which needs to be supported by federated programs. Below we describe the
mapping between TensorFlow Federated type signatures and Python
representations of values that can be passed as arguments to or returned as
results from tff.Computation
s.
Python representations of values that can be accepted as an arguments to or
returned as a value from a tff.Computation
:
Python representations of values that can be only be accepted as an arguments
to a tff.Computation
:
Methods
invoke
View source
@abc.abstractmethod
invoke(
comp: tff.Computation
,
arg: Optional[ComputationArgValue]
) -> structure_utils.Structure[value_reference.MaterializableValueReference]
Invokes the comp
with the argument arg
.
Raises |
ValueError
|
If the result type of comp does not contain only structures,
server-placed values, or tensors.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.program.FederatedContext\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nAn abstract interface representing a federated context.\n\nInherits From: [`SyncContext`](../../tff/framework/SyncContext)\n\nA federated context supports invoking a limited set of [`tff.Computation`](../../tff/Computation)s,\nmaking guarantees about what a [`tff.Computation`](../../tff/Computation) can accept as an argument and\nwhat it returns when invoked.\n\nRestrictions on the TensorFlow Federated Type\n---------------------------------------------\n\nArguments can be nested structures of values corresponding to the TensorFlow\nFederated type signature of the [`tff.Computation`](../../tff/Computation):\n\n- Server-placed values must be represented by [`tff.program.MaterializableStructure`](../../tff/program/MaterializableStructure).\n- Client-placed values must be represented by structures of values returned by a [`tff.program.FederatedDataSourceIterator`](../../tff/program/FederatedDataSourceIterator).\n\nReturn values can be structures of [`tff.program.MaterializableValueReference`](../../tff/program/MaterializableValueReference)s\nor a single [`tff.program.MaterializableValueReference`](../../tff/program/MaterializableValueReference), where a reference\ncorresponds to the tensor-type of the TensorFlow Federated type signature in\nthe return value of the invoked [`tff.Computation`](../../tff/Computation).\n\nTensorFlow Federated Type to Python Representation\n--------------------------------------------------\n\nIn order to interact with the value returned by a [`tff.Computation`](../../tff/Computation), it is\nhelpful to be able to reason about the Python type of this value. In some way\nthis Python type must depend on the TensorFlow Federated type signature of the\nassociated value. To provide uniformity of experience and ease of reasoning,\nwe specify the Python representation of values in a manner that can be stated\nentirely in the TensorFlow Federated typesystem.\n\nWe have chosen to limit the TensorFlow Federated type signatures of invoked\n[`tff.Computation`](../../tff/Computation)s to disallow the returning of client-placed values,\n`tff.SequenceTypes`, and `tff.FunctionTypes`, in order to reduced the area\nwhich needs to be supported by federated programs. Below we describe the\nmapping between TensorFlow Federated type signatures and Python\nrepresentations of values that can be passed as arguments to or returned as\nresults from [`tff.Computation`](../../tff/Computation)s.\n\nPython representations of values that can be *accepted as an arguments to* or\n*returned as a value from* a [`tff.Computation`](../../tff/Computation):\n\n| TensorFlow Federated Type | Python Representation |\n|----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|\n| [`tff.TensorType`](../../tff/types/TensorType) | [`tff.program.MaterializableValueReference`](../../tff/program/MaterializableValueReference) |\n| [`tff.SequenceType`](../../tff/types/SequenceType) | [`tff.program.MaterializableValueReference`](../../tff/program/MaterializableValueReference) |\n| [`tff.FederatedType`](../../tff/types/FederatedType) (server-placed) | Python representation of the `member` of the [`tff.FederatedType`](../../tff/types/FederatedType) |\n| [`tff.StructWithPythonType`](../../tff/types/StructWithPythonType) | Python container of the [`tff.StructWithPythonType`](../../tff/types/StructWithPythonType) |\n| [`tff.StructType`](../../tff/types/StructType) (with no Python type, all fields named) | `collections.OrderedDict` |\n| [`tff.StructType`](../../tff/types/StructType) (with no Python type, no fields named) | `tuple` |\n\nPython representations of values that can be only be *accepted as an arguments\nto* a [`tff.Computation`](../../tff/Computation):\n\n| TFF Type | Python Representation |\n|----------------------------------------------------------------------|-------------------------------------------------------------------|\n| [`tff.FederatedType`](../../tff/types/FederatedType) (client-placed) | Opaque object returned by `tff.program.DataSourceIterator.select` |\n| [`tff.FunctionType`](../../tff/types/FunctionType) | [`tff.Computation`](../../tff/Computation) |\n\nMethods\n-------\n\n### `invoke`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n @abc.abstractmethod\n invoke(\n comp: ../../tff/Computation,\n arg: Optional[ComputationArgValue]\n ) -\u003e structure_utils.Structure[value_reference.MaterializableValueReference]\n\nInvokes the `comp` with the argument `arg`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `comp` | The [`tff.Computation`](../../tff/Computation) being invoked. |\n| `arg` | The optional argument of `comp`; server-placed values must be represented by [`tff.program.MaterializableStructure`](../../tff/program/MaterializableStructure), and client-placed values must be represented by structures of values returned by a [`tff.program.FederatedDataSourceIterator`](../../tff/program/FederatedDataSourceIterator). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The result of invocation; a structure of [`tff.program.MaterializableValueReference`](../../tff/program/MaterializableValueReference). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|--------------------------------------------------------------------------------------------------|\n| `ValueError` | If the result type of `comp` does not contain only structures, server-placed values, or tensors. |\n\n\u003cbr /\u003e"]]