tff.program.CSVFileReleaseManager
Stay organized with collections
Save and categorize content based on your preferences.
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
View source
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.program.CSVFileReleaseManager\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nA [`tff.program.ReleaseManager`](../../tff/program/ReleaseManager) that releases values to a CSV file.\n\nInherits From: [`ReleaseManager`](../../tff/program/ReleaseManager) \n\n tff.program.CSVFileReleaseManager(\n file_path: Union[bytes, str, os.PathLike[Union[bytes, str]]],\n save_mode: ../../tff/program/CSVSaveMode = ../../tff/program/CSVSaveMode#APPEND,\n key_fieldname: str = 'key'\n )\n\nA [`tff.program.CSVFileReleaseManager`](../../tff/program/CSVFileReleaseManager) is a utility for releasing values\nfrom a federated program to a CSV file and is used to release values from\nplatform storage to customer storage in a federated program.\n\nValues are released to the file system as a CSV file and are quoted as\nstrings. When the value is released, each\n[`tff.program.MaterializableValueReference`](../../tff/program/MaterializableValueReference) is materialized. The value is then\nflattened, converted to a `numpy.ndarray`, and then converted to a nested list\nof Python scalars, and released as a CSV file. For example, `1` will be\nwritten as `'1'` and `tf.constant([[1, 1], [1, 1]])` will be written as\n`'[[1, 1], [1, 1]]'`.\n\nThis manager can be configured to release values using a `save_mode` of either\n[`CSVSaveMode.APPEND`](../../tff/program/CSVSaveMode#APPEND) or [`CSVSaveMode.WRITE`](../../tff/program/CSVSaveMode#WRITE).\n\n- In append mode, when a value is released, this manager will try and append\n the value to the CSV file instead of overwriting the existing file. While\n potentially more efficient, append mode is incompatible with compressed\n files (e.g. `.bz2` formats) and encoded directories. This mode is equivalent\n to write mode when releasing a value with a different structure than the\n currently released values, so it may not be useful when values with\n different structures are being released frequently.\n\n- In write mode (or in append mode when releasing new structures), when a\n value is realeased, this manager reads the entire CSV file and overwrites\n the existing file with the additional values. This can be slower than append\n mode, but is compatible with compressed files (e.g. `.bz2` formats) and\n encoded directories.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|------------------------------------------------------------------------------------------------------|\n| `file_path` | A path on the file system to save releases values. If this file does not exist it will be created. |\n| `save_mode` | A [`tff.program.CSVSaveMode`](../../tff/program/CSVSaveMode) specifying how to save released values. |\n| `key_fieldname` | A `str` specifying the fieldname used for the key when saving released value. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------------------------|-------------------------------------------------------------------------|\n| `ValueError` | If `file_path` or `key_fieldname` is an empty string. |\n| `CSVKeyFieldnameNotFoundError` | If the file exists but does not contain a fieldname of `key_fieldname`. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `release`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n release(\n value: ../../tff/program#ReleasableStructure,\n key\n ) -\u003e value_reference.MaterializedValue\n\nReleases `value` from a federated program.\n\nThis method will atomically update the managed CSV file by removing all\nvalues previously released with a key greater than or equal to `key` before\nwriting `value`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|----------------------------------------------------------------------------------------------------|\n| `value` | A [`tff.program.ReleasableStructure`](../../tff/program#ReleasableStructure) to release. |\n| `key` | An integer used to reference the released `value`; `key` represents a step in a federated program. |\n\n\u003cbr /\u003e"]]