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 two nn.Module objects as inputs. For more details, please see the docstring of LayerSelectionFunctionConstructor.

pull_parameters(parameters, model, config=None)[source]
Return type:

None

push_parameters(model, initial_model=None, config=None)[source]
Return type:

List[ndarray[Any, dtype[Any]]]

select_parameters(model, initial_model=None)[source]
Return type:

tuple[List[ndarray[Any, dtype[Any]]], list[str]]

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

Parameters:

layers_to_transfer (list[str]) – Names of the layers to be exchanged. These should correspond to the names of the layers in the state_dict of the pytorch module.

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

pull_parameters(parameters, model, config=None)[source]
Return type:

None

push_parameters(model, initial_model=None, config=None)[source]
Return type:

List[ndarray[Any, dtype[Any]]]

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.

apply_layer_filter(model)[source]
Return type:

List[ndarray[Any, dtype[Any]]]

get_layers_to_transfer(model)[source]
Return type:

list[str]

pull_parameters(parameters, model, config=None)[source]
Return type:

None

push_parameters(model, initial_model=None, config=None)[source]
Return type:

List[ndarray[Any, dtype[Any]]]

should_layer_be_excluded(layer_name)[source]
Return type:

bool

should_module_be_excluded(module)[source]
Return type:

bool