nvflare.app_common.np.np_model_persistor module

class NPModelPersistor(model_dir='models', model_name='server.npy', model: list | None = None, source_ckpt_file_full_name: str | None = None)[source]

Bases: ModelPersistor

Model persistor for numpy arrays.

Note

This persistor loads model data in the following priority: 1. source_ckpt_file_full_name (if provided and exists) 2. Previously saved numpy array from <run_dir>/<model_dir>/<model_name> 3. model (if provided) 4. Default array [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Parameters:
  • model_dir (str, optional) – model directory. Defaults to “models”.

  • model_name (str, optional) – model name. Defaults to “server.npy”.

  • model (list, optional) – fallback initial model as a (JSON-serializable) list. This is only used when a previously saved model cannot be loaded. It will be converted to numpy array when load_model is called. Defaults to None.

  • source_ckpt_file_full_name (str, optional) – Full path to source checkpoint file. This path may not exist locally (server-side path). If provided and exists at runtime, it takes priority over other loading methods.

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