View source on GitHub |
A tff.program.ProgramStateManager
that is backed by a file system.
Inherits From: ProgramStateManager
tff.program.FileProgramStateManager(
root_dir: Union[str, os.PathLike[str]],
prefix: str = 'program_state_',
keep_total: int = 5,
keep_first: bool = True,
keep_every_k: int = 1
)
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, each
tff.program.MaterializableValueReference
is materialized and each
tff.Serializable
is serialized. 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.
Raises | |
---|---|
ValueError
|
If root_dir is an empty string.
|
Methods
get_versions
get_versions()
Returns a list of saved versions or None
.
Returns | |
---|---|
A list of saved versions or None if there is no saved program state.
|
load
load(
version, structure
) -> tff.program.ProgramStateStructure
Returns the program state for the given version
.
Args | |
---|---|
version
|
A integer representing the version of a saved program state. |
structure
|
The structure of the saved program state for the given
version used to support serialization and deserialization of
user-defined classes in the structure.
|
Raises | |
---|---|
ProgramStateNotFoundError
|
If there is no program state for the given
version .
|
load_latest
load_latest(
structure
)
Returns the latest saved program state and version or (None
, 0).
Args | |
---|---|
structure
|
The 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.
|
remove_all
remove_all()
Removes all program states.
save
save(
program_state, version
)
Saves program_state
for the given version
.
Args | |
---|---|
program_state
|
A tff.program.ProgramStateStructure to save.
|
version
|
A strictly increasing integer representing the version of a saved
program_state .
|
Raises | |
---|---|
ProgramStateExistsError
|
If there is already program state for the given
version .
|