View source on GitHub |
A tff.program.ReleaseManager
that releases values to a CSV file.
Inherits From: ReleaseManager
tff.program.CSVFileReleaseManager(
file_path: Union[bytes, str, os.PathLike[Union[bytes, str]]],
save_mode: tff.program.CSVSaveMode
= tff.program.CSVSaveMode.APPEND
,
key_fieldname: str = 'key'
)
A tff.program.CSVFileReleaseManager
is a utility for releasing values
from a federated program to a CSV file and is used to release values from
platform storage to customer storage in a federated program.
Values are released to the file system as a CSV file and are quoted as
strings. When the value is released, each
tff.program.MaterializableValueReference
is materialized. The value is then
flattened, converted to a numpy.ndarray
, and then converted to a nested list
of Python scalars, and released as a CSV file. For example, 1
will be
written as '1'
and tf.constant([[1, 1], [1, 1]])
will be written as
'[[1, 1], [1, 1]]'
.
This manager can be configured to release values using a save_mode
of either
CSVSaveMode.APPEND
or CSVSaveMode.WRITE
.
In append mode, when a value is released, this manager will try and append the value to the CSV file instead of overwriting the existing file. While potentially more efficient, append mode is incompatible with compressed files (e.g.
.bz2
formats) and encoded directories. This mode is equivalent to write mode when releasing a value with a different structure than the currently released values, so it may not be useful when values with different structures are being released frequently.In write mode (or in append mode when releasing new structures), when a value is realeased, this manager reads the entire CSV file and overwrites the existing file with the additional values. This can be slower than append mode, but is compatible with compressed files (e.g.
.bz2
formats) and encoded directories.
Args | |
---|---|
file_path
|
A path on the file system to save releases values. If this file does not exist it will be created. |
save_mode
|
A tff.program.CSVSaveMode specifying how to save released
values.
|
key_fieldname
|
A str specifying the fieldname used for the key when
saving released value.
|
Raises | |
---|---|
ValueError
|
If file_path or key_fieldname is an empty string.
|
CSVKeyFieldnameNotFoundError
|
If the file exists but does not contain a
fieldname of key_fieldname .
|
Methods
release
release(
value: tff.program.ReleasableStructure
,
key
) -> value_reference.MaterializedValue
Releases value
from a federated program.
This method will atomically update the managed CSV file by removing all
values previously released with a key greater than or equal to key
before
writing value
.
Args | |
---|---|
value
|
A tff.program.ReleasableStructure to release.
|
key
|
An integer used to reference the released value ; key represents a
step in a federated program.
|