fedn.utils.plugins package
The plugins package is responsible for loading model helper functions supporting different ML frameworks. The fedn.utils.plugins.helperbase.HelperBase
is
an abstract class which user can implement their own helper functions to support different ML frameworks.
Submodules
fedn.utils.plugins.helperbase module
- class fedn.utils.plugins.helperbase.HelperBase[source]
Bases:
ABC
Abstract class defining helpers.
- get_tmp_path()[source]
Return a temporary output path compatible with save_model, load_model.
- Returns:
Path to file.
- abstract increment_average(model, model_next, a, W)[source]
Compute one increment of incremental weighted averaging.
- Parameters:
model – Current model weights in array-like format.
model_next – 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.
fedn.utils.plugins.kerashelper module
- class fedn.utils.plugins.kerashelper.Helper[source]
Bases:
HelperBase
FEDn helper class for keras.Sequential.
- increment_average(model, model_next, num_examples, total_examples)[source]
Incremental weighted average of model weights.
- Parameters:
- Returns:
Incremental weighted average of model weights.
- Return type:
list of numpy arrays.
- increment_average_add(model, model_next, num_examples, total_examples)[source]
Incremental weighted average of model weights.
- Parameters:
- Returns:
Incremental weighted average of model weights.
- Return type:
list of numpy arrays.
fedn.utils.plugins.numpyarrayhelper module
- class fedn.utils.plugins.numpyarrayhelper.Helper[source]
Bases:
HelperBase
FEDn helper class for numpy arrays.
- increment_average(model, model_next, n)[source]
Update an incremental average.
- Parameters:
model (numpy array.) – Current model weights.
model_next (numpy array.) – New model weights.
n (int) – Number of examples in new model.
- Returns:
Incremental weighted average of model weights.
- Return type:
numpy.array
fedn.utils.plugins.pytorchhelper module
- class fedn.utils.plugins.pytorchhelper.Helper[source]
Bases:
HelperBase
FEDn helper class for pytorch.
- increment_average(model, model_next, num_examples, total_examples)[source]
Update a weighted incremental average of model weights.
- Parameters:
- Returns:
Incremental weighted average of model weights.
- Return type:
OrderedDict
- load(path)[source]
Load weights from file or filelike.
- Parameters:
path (str) – file path, filehandle, filelike.
- Returns:
Weights of model with keys from torch state_dict.
- Return type:
OrderedDict