Local Disk Metric Storage#
- class rizemind.logging.local_disk_metric_storage.LocalDiskMetricStorage(dir: Path, app_name: str)[source]#
Bases:
BaseMetricStorageA concrete implementation of BaseMetricStorage that saves metrics and models to the local disk.
This class provides a straightforward way to persist federated learning artifacts by writing them to a structured directory on the local filesystem. For each run, it creates a unique timestamped subdirectory within the specified application folder.
The generated directory structure is as follows:
- <dir>/
- <app_name>/
- <YYYY-MM-DD-HH-MM-SS>/
config.json (Federated learning configuration settings)
metrics.csv (Round-by-round metrics)
weights.npz (Parameters of the best model)
- dir#
The root directory for storing all run artifacts.
- config_file#
The path to the JSON file for storing configuration.
- metrics_file#
The path to the CSV file for storing metrics.
- weights_file#
The path to the .npz file for storing the best model’s weights.
- update_best_model(server_round: int, loss: float)[source]#
Saves the current model to disk if its loss is the lowest seen so far.
It compares the provided loss with its internally tracked best loss. If the new loss is lower, it updates the best loss and serializes the in-memory model parameters (from update_current_round_model) to a ‘weights.npz’ file, overwriting any previously saved best model.
- Parameters:
server_round (int) – The server round that produced this model. (Not used in this implementation but required by the interface).
loss (float) – The loss value of the current model.
- update_current_round_model(parameters: Parameters)[source]#
Temporarily stores the model parameters for the current round in memory.
This method holds the latest model parameters so they can be saved to disk later by update_best_model if this model proves to be the best one.
- Parameters:
parameters (Parameters) – The model parameters from the current round.
- write_config(config: dict[str, bool | float | int | str])[source]#
Writes configuration parameters to a JSON file.
If the config file already exists and contains data, the new configuration is merged with the existing content.
- Parameters:
config (dict[str, UserConfigValue]) – A dictionary of configuration settings to be saved.
- write_metrics(server_round: int, metrics: dict[str, bool | bytes | float | int | str])[source]#
Appends a dictionary of metrics to the metrics.csv file.
Each key-value pair in the metrics dictionary is written as a new row in the CSV file, along with the server round.
- Parameters:
server_round (int) – The current round of federated learning.
metrics (dict[str, Scalar]) – A dictionary mapping metric names (e.g., “accuracy”) to their scalar values.