nvflare.app_common.abstract.learner_spec module¶
- class Learner[source]¶
Bases:
FLComponent
Init FLComponent.
The FLComponent is the base class of all FL Components. (executors, controllers, responders, filters, aggregators, and widgets are all FLComponents)
FLComponents have the capability to handle and fire events and contain various methods for logging.
- abort(fl_ctx: FLContext)[source]¶
Called (from another thread) to abort the current task (validate or train).
Note: this is to abort the current task only, not the Trainer. After aborting, the Learner. may still be called to perform another task.
- Parameters:
fl_ctx – FLContext of the running environment
- finalize(fl_ctx: FLContext)[source]¶
Called to finalize the Learner (close/release resources gracefully).
After this call, the Learner will be destroyed.
- Parameters:
fl_ctx – FLContext of the running environment
- get_model_for_validation(model_name: str, fl_ctx: FLContext) Shareable [source]¶
Called to return the trained model from the Learner.
- Parameters:
model_name – type of the model for validation
fl_ctx – FLContext of the running environment
Returns: trained model for validation
- initialize(parts: dict, fl_ctx: FLContext)[source]¶
Initialize the Learner object. This is called before the Learner can train or validate.
This is called only once.
- Parameters:
parts – components to be used by the Trainer
fl_ctx – FLContext of the running environment
- train(data: Shareable, fl_ctx: FLContext, abort_signal: Signal) Shareable [source]¶
Called to perform training. Can be called many times during the lifetime of the Learner.
- Parameters:
data – the training input data (e.g. model weights)
fl_ctx – FLContext of the running environment
abort_signal – signal to abort the train
Returns: train result in Shareable
- validate(data: Shareable, fl_ctx: FLContext, abort_signal: Signal) Shareable [source]¶
Called to perform validation. Can be called many times during the lifetime of the Learner.
- Parameters:
data – the training input data (e.g. model weights)
fl_ctx – FLContext of the running environment
abort_signal – signal to abort the train
Returns: validate result in Shareable