fedn.utils.helpers package

The helpers package is responsible for serialization/deserialization and numerics operations for various machine learning frameworks.

Subpackages

Submodules

fedn.utils.helpers.helperbase module

class fedn.utils.helpers.helperbase.HelperBase[source]

Bases: ABC

Abstract class defining helpers.

abstract increment_average(m1, m2, a, W)[source]

Compute one increment of incremental weighted averaging.

Parameters:
  • m1 – Current model weights in array-like format.

  • m2 – New model weights in array-like format.

  • a – Number of examples in new model.

  • W – Total number of examples.

Returns:

Incremental weighted average of model weights.

abstract load(fh)[source]

Load weights from file or filelike.

Parameters:

fh – file path, filehandle, filelike.

Returns:

Weights in array-like format.

abstract save(model, path)[source]

Serialize weights to file. The serialized model must be a single binary object.

Parameters:
  • model – Weights in array-like format.

  • path – Path to file.

fedn.utils.helpers.helpers module

fedn.utils.helpers.helpers.get_helper(helper_module_name)[source]

Return an instance of the helper class.

Parameters:

helper_module_name (str) – The name of the helper plugin module.

Returns:

A helper instance.

Return type:

class: fedn.utils.helpers.helpers.HelperBase

fedn.utils.helpers.helpers.save_metadata(metadata, filename)[source]

Save metadata to file.

Parameters:
  • metadata (dict) – The metadata to save.

  • filename (str) – The name of the file to save to.

fedn.utils.helpers.helpers.save_metrics(metrics, filename)[source]

Save metrics to file.

Parameters:
  • metrics (dict) – The metrics to save.

  • filename (str) – The name of the file to save to.