fl4health.parameter_exchange.layer_exchanger module¶
- class DynamicLayerExchanger(layer_selection_function)[source]¶
Bases:
PartialParameterExchanger
[list
[str
]]- __init__(layer_selection_function)[source]¶
This exchanger uses
layer_selection_function
to select a subset of a model’s layers at the end of each training round. Only the selected layers are exchanged with the server.- Parameters:
layer_selection_function (LayerSelectionFunction) – Function responsible for selecting the layers to be exchanged. This function relies on extra parameters such as norm threshold or exchange percentage, but we assume that it has already been pre-constructed using the class
LayerSelectionFunctionConstructor
, so it only needs to take in twonn.Module
objects as inputs. For more details, please see the docstring ofLayerSelectionFunctionConstructor
.
- class FixedLayerExchanger(layers_to_transfer)[source]¶
Bases:
ParameterExchanger
- __init__(layers_to_transfer)[source]¶
Exchanger that only exchanges a static set of layers at each round of FL
- apply_layer_filter(model)[source]¶
Filter layers to the specific set of layers to be transferred using the
layers_to_transfer
property.NOTE: Filtering layers only works if each client exchanges exactly the same layers
- Parameters:
model (nn.Module) – Model whose parameters are to be filtered then transferred.
- Returns:
Filter set of model parameters.
- Return type:
NDArrays
- class LayerExchangerWithExclusions(model, module_exclusions)[source]¶
Bases:
ParameterExchanger
- __init__(model, module_exclusions)[source]¶
This class implements exchanging all model layers except those matching a specified set of types. The constructor is provided with the model in order to extract the proper layers to be exchanged based on the exclusion criteria
- Parameters:
model (nn.Module) – Model whose layers are to be exchanged.
module_exclusions (Set[type[TorchModule]]) – modules within the model to EXCLUDE from exchange with the server. It should correspond to a torch module or set of modules.