RecordSet

class RecordSet(parameters_records: dict[str, ParametersRecord] | None = None, metrics_records: dict[str, MetricsRecord] | None = None, configs_records: dict[str, ConfigsRecord] | None = None)[소스]

기반 클래스: object

RecordSet은 매개변수, 메트릭 및 설정 그룹을 저장합니다.

A RecordSet is the unified mechanism by which parameters, metrics and configs can be either stored as part of a flwr.common.Context in your apps or communicated as part of a flwr.common.Message between your apps.

매개변수:
  • parameters_records (Optional[Dict[str, ParametersRecord]]) – A dictionary of ParametersRecords that can be used to record and communicate model parameters and high-dimensional arrays.

  • metrics_records (Optional[Dict[str, MetricsRecord]]) – A dictionary of MetricsRecord that can be used to record and communicate scalar-valued metrics that are the result of performing and action, for example, by a ClientApp.

  • configs_records (Optional[Dict[str, ConfigsRecord]]) – A dictionary of ConfigsRecord that can be used to record and communicate configuration values to an entity (e.g. to a ClientApp) for it to adjust how an action is performed.

예제

A RecordSet can hold three types of records, each designed with an specific purpose. What is common to all of them is that they are Python dictionaries designed to ensure that each key-value pair adheres to specified data types.

Let’s see an example.

>>>  from flwr.common import RecordSet
>>>  from flwr.common import ConfigsRecord, MetricsRecord, ParametersRecord
>>>
>>>  # Let's begin with an empty record
>>>  my_recordset = RecordSet()
>>>
>>>  # We can create a ConfigsRecord
>>>  c_record = ConfigsRecord({"lr": 0.1, "batch-size": 128})
>>>  # Adding it to the record_set would look like this
>>>  my_recordset.configs_records["my_config"] = c_record
>>>
>>>  # We can create a MetricsRecord following a similar process
>>>  m_record = MetricsRecord({"accuracy": 0.93, "losses": [0.23, 0.1]})
>>>  # Adding it to the record_set would look like this
>>>  my_recordset.metrics_records["my_metrics"] = m_record

Adding a ParametersRecord follows the same steps as above but first, the array needs to be serialized and represented as a flwr.common.Array. If the array is a NumPy array, you can use the built-in utility function array_from_numpy. It is often possible to convert an array first to NumPy and then use the aforementioned function.

>>>  from flwr.common import array_from_numpy
>>>  # Creating a ParametersRecord would look like this
>>>  arr_np = np.random.randn(3, 3)
>>>
>>>  # You can use the built-in tool to serialize the array
>>>  arr = array_from_numpy(arr_np)
>>>
>>>  # Finally, create the record
>>>  p_record = ParametersRecord({"my_array": arr})
>>>
>>>  # Adding it to the record_set would look like this
>>>  my_recordset.configs_records["my_config"] = c_record

For additional examples on how to construct each of the records types shown above, please refer to the documentation for ConfigsRecord, MetricsRecord and ParametersRecord.

메소드

속성

configs_records

Dictionary holding ConfigsRecord instances.

metrics_records

Dictionary holding MetricsRecord instances.

parameters_records

Dictionary holding ParametersRecord instances.

property configs_records: TypedDict[str, ConfigsRecord]

Dictionary holding ConfigsRecord instances.

property metrics_records: TypedDict[str, MetricsRecord]

Dictionary holding MetricsRecord instances.

property parameters_records: TypedDict[str, ParametersRecord]

Dictionary holding ParametersRecord instances.