nvflare.app_opt.sklearn.joblib_model_param_persistor module

class JoblibModelParamPersistor(initial_params: Dict[str, Any] | None = None, save_name: str = 'model_param.joblib', model_path: str | None = None)[source]

Bases: ModelPersistor

Persist global model parameters from a dict to a joblib file.

Note that this contains the necessary information to build a certain model but may not be directly loadable.

Unlike PTFileModelPersistor, this persistor does NOT instantiate model classes. It only stores and transmits parameter values (e.g., hyperparameters, weights). The sklearn model class is instantiated on the client side using these params.

Parameters:
  • initial_params – Initial parameters dict (e.g., {“n_clusters”: 3, “kernel”: “rbf”}). Hyperparameters/config only; do not put model_path here—use the model_path argument instead. Used as fallback when model_path is None and no saved model exists in save_path.

  • save_name – Filename for saving model params. Defaults to “model_param.joblib”.

  • model_path – Optional absolute path to a saved model file (.joblib, .pkl). If provided, the model is loaded from this path at runtime (file must exist). Defaults to None. For backward compatibility, initial_params may still contain key “model_path” and will be used if model_path is None.

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:

ModelLearnable object

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

Persists the Model object.

Parameters:
  • model_learnable – ModelLearnable object

  • fl_ctx – FLContext

validate_model_path(path: str | None) None[source]

Require model_path to be absolute if provided.

All sklearn recipes use this so construction fails fast instead of at runtime when the persistor’s load_model() runs. Call from recipe __init__ or validators.