fl_server_ai.trainer.model_trainer ¶
Classes:
| Name | Description |
|---|---|
FedDCModelTrainer | Federated daisy-chaining (FedDC) model trainer. |
ModelTrainer | Common model trainer. |
SWAGModelTrainer | Stochastic weight averaging Gaussian (SWAG) model trainer. |
Functions:
| Name | Description |
|---|---|
get_trainer | Get a model trainer instance for the given training object. |
get_trainer_class | Get the appropriate model trainer class based on a training object. |
Classes¶
FedDCModelTrainer ¶
Bases: ModelTrainer
flowchart TD
fl_server_ai.trainer.model_trainer.FedDCModelTrainer[FedDCModelTrainer]
fl_server_ai.trainer.model_trainer.ModelTrainer[ModelTrainer]
fl_server_ai.trainer.model_trainer.ModelTrainer --> fl_server_ai.trainer.model_trainer.FedDCModelTrainer
click fl_server_ai.trainer.model_trainer.FedDCModelTrainer href "" "fl_server_ai.trainer.model_trainer.FedDCModelTrainer"
click fl_server_ai.trainer.model_trainer.ModelTrainer href "" "fl_server_ai.trainer.model_trainer.ModelTrainer"
Federated daisy-chaining (FedDC) model trainer.
To tackle the problem that client models are potentially quite small and thus the models tend to overfit and therefore result in bad prediction quality on unseen data, one proposed solution is FedDC (also named Federated daisy-chaining). FedDC sends before each aggregation step each client model to another randomly selected client, which trains it on its local data. From the model perspective, it is as if the model is trained on a larger dataset.
Paper: Picking Daisies in Private: Federated Learning from Small Datasets
Methods:
| Name | Description |
|---|---|
handle | |
start_round | |
Source code in fl_server_ai/trainer/model_trainer.py
Functions¶
handle ¶
handle(event: ModelTrainerEvent)
start_round ¶
Source code in fl_server_ai/trainer/model_trainer.py
ModelTrainer ¶
Common model trainer.
- API Reference
fl_server_aitrainer
- API Reference
fl_server_aitrainermodel_trainer Classes
- API Reference
fl_server_aitrainerevents
Methods:
| Name | Description |
|---|---|
__init__ | Initialize the trainer with the given training and options. |
__new__ | Ensure that the correct trainer class is returned based on the training. |
finish | Finish the training and send a finished notification. |
get_trainer_class | Get the appropriate model trainer class based on a training object. |
handle | Handle a model trainer event and proceed to the next event. |
handle_cls | Handle a model trainer event class by creating an instance of the event and handling it. |
start | Start the training and send a start notification. |
start_round | Start a training round and send a round start notification. |
test_round | Test a training round and send a model test notification. |
Attributes:
| Name | Type | Description |
|---|---|---|
options | The options for the trainer. | |
training | The training to be handled by the trainer. |
Source code in fl_server_ai/trainer/model_trainer.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
Attributes¶
options instance-attribute ¶
options = options if options else TrainerOptions()
The options for the trainer.
Functions¶
__init__ ¶
__init__(training: Training, options: TrainerOptions | None = None)
Initialize the trainer with the given training and options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Training | The training to be handled by the trainer. | required |
| TrainerOptions | None | The options for the trainer. If None, default options will be used. | None |
Source code in fl_server_ai/trainer/model_trainer.py
__new__ ¶
__new__(training: Training, options: TrainerOptions | None = None) -> ModelTrainer
Ensure that the correct trainer class is returned based on the training.
The returned trainer class is determined by the get_trainer_class method. It could for example return a SWAGModelTrainer if the training uses the SWAG uncertainty method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Training | The training for which to get the trainer. | required |
| TrainerOptions | None | The options for the trainer. If None, default options will be used. | None |
Returns:
| Type | Description |
|---|---|
ModelTrainer | "ModelTrainer": The trainer instance. |
Source code in fl_server_ai/trainer/model_trainer.py
finish ¶
Finish the training and send a finished notification.
get_trainer_class classmethod ¶
get_trainer_class(training: Training) -> Type[ModelTrainer]
Get the appropriate model trainer class based on a training object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Training | The training for which to get the trainer class. | required |
Returns:
| Type | Description |
|---|---|
Type[ModelTrainer] | Type["ModelTrainer"]: The appropriate trainer class. |
Source code in fl_server_ai/trainer/model_trainer.py
handle ¶
handle(event: ModelTrainerEvent)
Handle a model trainer event and proceed to the next event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| ModelTrainerEvent | The event to handle. | required |
handle_cls ¶
handle_cls(event_cls: Type[ModelTrainerEvent])
Handle a model trainer event class by creating an instance of the event and handling it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Type[ModelTrainerEvent] | The class of the event to handle. | required |
Source code in fl_server_ai/trainer/model_trainer.py
start ¶
Start the training and send a start notification.
Source code in fl_server_ai/trainer/model_trainer.py
start_round ¶
test_round ¶
SWAGModelTrainer ¶
Bases: ModelTrainer
flowchart TD
fl_server_ai.trainer.model_trainer.SWAGModelTrainer[SWAGModelTrainer]
fl_server_ai.trainer.model_trainer.ModelTrainer[ModelTrainer]
fl_server_ai.trainer.model_trainer.ModelTrainer --> fl_server_ai.trainer.model_trainer.SWAGModelTrainer
click fl_server_ai.trainer.model_trainer.SWAGModelTrainer href "" "fl_server_ai.trainer.model_trainer.SWAGModelTrainer"
click fl_server_ai.trainer.model_trainer.ModelTrainer href "" "fl_server_ai.trainer.model_trainer.ModelTrainer"
Stochastic weight averaging Gaussian (SWAG) model trainer.
Methods:
| Name | Description |
|---|---|
handle | |
start_swag_round | Start a SWAG round and send a SWAG round start notification. |
Source code in fl_server_ai/trainer/model_trainer.py
Functions¶
handle ¶
handle(event: ModelTrainerEvent)
start_swag_round ¶
Start a SWAG round and send a SWAG round start notification.
Source code in fl_server_ai/trainer/model_trainer.py
Functions¶
get_trainer ¶
get_trainer(training: Training, options: TrainerOptions | None = None) -> ModelTrainer
Get a model trainer instance for the given training object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Training | The training for which to get the trainer. | required |
| TrainerOptions | None | The options for the trainer. Defaults to None. | None |
Returns:
| Type | Description |
|---|---|
ModelTrainer | "ModelTrainer": The trainer instance. |
Source code in fl_server_ai/trainer/model_trainer.py
get_trainer_class ¶
get_trainer_class(training: Training) -> Type[ModelTrainer]
Get the appropriate model trainer class based on a training object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Training | The training for which to get the trainer class. | required |
Returns:
| Type | Description |
|---|---|
Type[ModelTrainer] | Type["ModelTrainer"]: The appropriate trainer class. |