tff.program.FileProgramStateManager

A tff.program.ProgramStateManager that is backed by a file system.

Inherits From: ProgramStateManager

A tff.program.FileProgramStateManager is a utility for saving and loading program state to a file system in a federated program and is used to implement fault tolerance. In particular, it is intended to only restart the same simulation and run with the same version of TensorFlow Federated.

Program state is saved to the file system using the SavedModel (see tf.saved_model) format. When the program state is saved, if the program state is a value reference or a structure containing value references, each value reference is materialized. The program state is then flattened and saved using the SavedModel format. The structure of the program state is discarded, but is required to load the program state.

See https://www.tensorflow.org/guide/saved_model for more information about the SavedModel format.

root_dir A path on the file system to save program state. If this path does not exist it will be created.
prefix A string to use as the prefix for filenames.
keep_total An integer representing the total number of program states to keep. If the value is zero or smaller, all program states will be kept.
keep_first A boolean indicating if the first program state should be kept, irrespective of whether it is the oldest program state or not. This is desirable in settings where you would like to ensure full reproducibility of the simulation, especially in settings where model weights or optimizer states are initialized randomly. By loading from the initial program state, one can avoid re-initializing and obtaining different results.

ValueError If root_dir is an empty string.

Methods

get_versions

View source

Returns a list of saved versions or None.

Returns
A list of saved versions or None if there is no saved program state.

load

View source

Returns the program state for the given version.

Args
version A integer representing the version of a saved program state.
structure The nested structure of the saved program state for the given version used to support serialization and deserailization of user-defined classes in the structure.

Raises
ProgramStateManagerStateNotFoundError If there is no program state for the given version.
ProgramStateManagerStructureError If structure does not match the value loaded for the given version.

load_latest

View source

Returns the latest saved program state and version or (None, 0).

Args
structure The nested structure of the saved program state for the given version used to support serialization and deserailization of user-defined classes in the structure.

Returns
A tuple of the latest saved (program state, version) or (None, 0) if there is no latest saved program state.

save

View source

Saves program_state for the given version.

Args
program_state A materialized value, a value reference, or a structure of materialized values and value references representing the program state to save.
version A strictly increasing integer representing the version of a saved program_state.

Raises
ProgramStateManagerStateAlreadyExistsError If there is already program state for the given version.