ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

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.

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

load

View source

Returns the program state for the given version.

Args
version A integer representing the version of a saved program state.

Raises
ProgramStateManagerStateNotFoundError If there is no program state for the given version.
FileProgramStateManagerStructureError If structure has not been set.

load_latest

View source

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

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 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.

set_structure

View source

Configures a structure to use when loading program state.

The structure must be set before calling load.

Args
structure A nested structure which tf.convert_to_tensor supports to use as a template when calling load.

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.