nvflare.app_common.ccwf.comps.np_file_model_persistor module

class NPFileModelPersistor(last_global_model_file_name='last_global_model.npy', best_global_model_file_name='best_global_model.npy', model_dir='models', initial_model_file_name='initial_model.npy')[source]

Bases: ModelPersistor

Abstract 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]
get_model_inventory(fl_ctx: FLContext) {<class 'str'>: <class 'nvflare.app_common.model_desc.ModelDescriptor'>}[source]

Get the model inventory of the ModelPersistor.

Parameters:

fl_ctx – FLContext

Returns: { model_kind: ModelDescriptor }

handle_event(event: str, fl_ctx: FLContext)[source]

Handles events.

Parameters:
  • event_type (str) – event type fired by workflow.

  • fl_ctx (FLContext) – FLContext information.

load_model(fl_ctx: FLContext) ModelLearnable[source]

Initialize and load the model.

Parameters:

fl_ctx – FLContext

Returns:

Model object

save_model(model_learnable: ModelLearnable, fl_ctx: FLContext)[source]

Persist the model object.

Parameters:
  • model – Model object to be saved

  • fl_ctx – FLContext