nvflare.app_opt.he.model_encryptor module

class HEModelEncryptor(tenseal_context_file='client_context.tenseal', encrypt_layers=None, aggregation_weights=None, weigh_by_local_iter=True, data_kinds=None)[source]

Bases: DXOFilter

Filter to encrypt Shareable object using homomorphic encryption (HE) with TenSEAL

https://github.com/OpenMined/TenSEAL.

Parameters:
  • tenseal_context_file – tenseal context files containing encryption keys and parameters

  • encrypt_layers – if not specified (None), all layers are being encrypted; if list of variable/layer names, only specified variables are encrypted; if string containing regular expression (e.g. “conv”), only matched variables are being encrypted.

  • aggregation_weights – dictionary of client aggregation {“client1”: 1.0, “client2”: 2.0, “client3”: 3.0}; defaults to a weight of 1.0 if not specified. Note, if specified, the same aggregation_weights should also be used on the server aggregator for the resulting weighted sum to be valid, i.e. in HEInTimeAccumulateWeightedAggregator.

  • weigh_by_local_iter – If true, multiply client weights on first before encryption (default: True

  • HE) (which is recommended for) –

  • data_kinds – data kinds to apply this filter

encryption(params, fl_ctx: FLContext)[source]
handle_event(event_type: str, fl_ctx: FLContext)[source]

Handles events.

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

  • fl_ctx (FLContext) – FLContext information.

process_dxo(dxo: DXO, shareable: Shareable, fl_ctx: FLContext) None | DXO[source]

Filter process apply to the Shareable object.

Parameters:
  • dxo – data to be processed

  • shareable – that the dxo belongs to

  • fl_ctx – FLContext

Returns: DXO object with encrypted weights