nvflare.app_common.abstract.model_persistor module
- class ModelPersistor(filter_id: str | None = None)[source]
Bases:
LearnablePersistor,ABCAbstract class. Implementations will need to implement the load_model() and save_model() methods to persist & load the current ModelLearnable.
- Parameters:
filter_id – Optional string that defines a filter component that is applied to prepare the model to be saved, e.g. for serialization of custom Python objects.
- get_model(model_file: str, fl_ctx: FLContext) ModelLearnable[source]
Retrieve a specific model by file name.
This method is called by get() to load a specific model from the inventory. Persistors that support multiple models (e.g., for cross-site evaluation) should override this method to load the specified model file.
Simple persistors that only work with a single model (like NPModelPersistor) do not need to implement this method.
- Parameters:
model_file – Name or path of the model file to retrieve
fl_ctx – FLContext
- Returns:
ModelLearnable object containing the model data
- Raises:
NotImplementedError – If the persistor doesn’t support retrieving specific models
- get_model_inventory(fl_ctx: FLContext) Dict[str, ModelDescriptor][source]
Get the model inventory of the ModelPersister.
- Parameters:
fl_ctx – FLContext
- Returns:
ModelDescriptor
- Return type:
A dict of model_name
- load(fl_ctx: FLContext) ModelLearnable[source]
Load the Learnable object.
- Parameters:
fl_ctx – FLContext
- Returns:
Learnable object loaded
- abstract load_model(fl_ctx: FLContext) ModelLearnable[source]
Initialize and load the model.
- Parameters:
fl_ctx – FLContext
- Returns:
Model object
- save(learnable: ModelLearnable, fl_ctx: FLContext)[source]
Persist the Learnable object.
- Parameters:
learnable – the Learnable object to be saved
fl_ctx – FLContext
- abstract save_model(model: ModelLearnable, fl_ctx: FLContext)[source]
Persist the model object.
- Parameters:
model – Model object to be saved
fl_ctx – FLContext