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. :type layer_selection_function: Callable[[Module, Module | None], tuple[List[ndarray[Any, dtype[Any]]], list[str]]] :param layer_selection_function: 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

apply_layer_filter(model)[source]
Return type:

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

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

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

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