Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

tff.utils.create_variables

View source

Creates a set of variables that matches the given type_spec.

tff.utils.create_variables(
    name,
    type_spec,
    **kwargs
)

Unlike tf.get_variables, this method will always create new variables, and will not retrieve variables previously created with the same name.

Args:

  • name: The common name to use for the scope in which all of the variables are to be created.
  • type_spec: An instance of tff.Type or something convertible to it. The type signature may only be composed of tensor types and named tuples, possibly nested.
  • **kwargs: Additional keyword args to pass to tf.Variable construction.

Returns:

Either a single variable when invoked with a tensor TFF type, or a nested structure of variables created in the appropriately-named variable scopes made up of anonymous tuples if invoked with a named tuple TFF type.

Raises:

  • TypeError: if type_spec is not a type signature composed of tensor and named tuple TFF types.