Converts the argument into an instance of the abstract class tff.Value.

Instances of tff.Value represent TFF values that appear internally in federated computations. This helper function can be used to wrap a variety of Python objects as tff.Value instances to allow them to be passed as arguments, used as functions, or otherwise manipulated within bodies of federated computations.

At the moment, the supported types include:

  • Simple constants of str, int, float, and bool types, mapped to values of a TFF tensor type.

  • Numpy arrays (np.ndarray objects), also mapped to TFF tensors.

  • Dictionaries (collections.OrderedDict and unordered dict), lists, tuples, namedtuples, and Structs, all of which are mapped to TFF tuple type.

  • Computations (constructed with either the tff.tensorflow.computation or with the tff.federated_computation decorator), typically mapped to TFF functions.

  • Placement literals (tff.CLIENTS, tff.SERVER), mapped to values of the TFF placement type.

This function is also invoked when attempting to execute a TFF computation. All arguments supplied in the invocation are converted into TFF values prior to execution. The types of Python objects that can be passed as arguments to computations thus matches the types listed here.

arg An instance of one of the Python types that are convertible to TFF values (instances of tff.Value).
type_spec An optional type specifier that allows for disambiguating the target type (e.g., when two TFF types can be mapped to the same Python representations). If not specified, TFF tried to determine the type of the TFF value automatically.
parameter_type_hint An optional tff.Type or value convertible to it by tff.to_type() which specifies an argument type to use in the case that arg is a polymorphic_computation.PolymorphicComputation.
zip_if_needed If True, attempt to coerce the result of to_value to match type_spec by applying intrinsics.federated_zip to appropriate elements.

An instance of tff.Value as described above.

TypeError if arg is of an unsupported type, or of a type that does not match type_spec. Raises explicit error message if TensorFlow constructs are encountered, as TensorFlow code should be sealed away from TFF federated context.