fl_server_ai.trainer ¶
Modules:
| Name | Description |
|---|---|
events | |
model_trainer | |
options | |
tasks | |
Classes:
| Name | Description |
|---|---|
ModelTrainer | Common model trainer. |
TrainerOptions | Trainer options including their default values. |
Functions:
| Name | Description |
|---|---|
process_trainer_task | Celery task that processes a dispatched trainer task. |
Attributes¶
Classes¶
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 ¶
TrainerOptions dataclass ¶
Trainer options including their default values.
- API Reference
fl_server_aitrainer
Methods:
| Name | Description |
|---|---|
__init__ | |
Attributes:
| Name | Type | Description |
|---|---|---|
delete_local_models_after_aggregation | bool | Flag indicating if local models should be deleted after aggregation. |
model_test_after_each_round | bool | Flag indicating if a model test should be performed after each round. |
skip_model_tests | bool | Flag indicating if model tests should be skipped. |
Source code in fl_server_ai/trainer/options.py
Attributes¶
delete_local_models_after_aggregation class-attribute instance-attribute ¶
delete_local_models_after_aggregation: bool = True
Flag indicating if local models should be deleted after aggregation.
model_test_after_each_round class-attribute instance-attribute ¶
model_test_after_each_round: bool = True
Flag indicating if a model test should be performed after each round.
skip_model_tests class-attribute instance-attribute ¶
skip_model_tests: bool = False
Flag indicating if model tests should be skipped.
Functions¶
Functions¶
process_trainer_task ¶
process_trainer_task(training_uuid: UUID, event_cls: Type[ModelTrainerEvent])
Celery task that processes a dispatched trainer task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| UUID | The UUID of the training. | required |
| Type[ModelTrainerEvent] | The class of the event to handle. | required |