nvflare.app_common.filters package

Submodules

Module contents

class ExcludeVars(exclude_vars: List[str] | str | None = None, data_kinds: List[str] | None = None)[source]

Bases: DXOFilter

Exclude/Remove variables from Shareable.

Parameters:
  • exclude_vars (Union[List[str], str, None] , optional) – variables/layer names to be excluded.

  • data_kinds – kinds of DXO object to filter

Notes

Based on different types of exclude_vars, this filter has different behavior:

if a list of variable/layer names, only specified variables will be excluded. if a string, it will be converted into a regular expression, only matched variables will be excluded. if not provided or other formats the Shareable remains unchanged.

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

Called by upper layer to remove variables in weights/weight_diff dictionary.

When the return code of shareable is not ReturnCode.OK, this function will not perform any process and returns the shareable back.

Parameters:
  • dxo (DXO) – DXO to be filtered.

  • shareable – that the dxo belongs to

  • fl_ctx (FLContext) – only used for logging.

Returns: filtered dxo

class PercentilePrivacy(percentile=10, gamma=0.01, data_kinds: List[str] | None = None)[source]

Bases: DXOFilter

Implementation of “largest percentile to share” privacy preserving policy.

Shokri and Shmatikov, Privacy-preserving deep learning, CCS ‘15

Parameters:
  • percentile (int, optional) – Only abs diff greater than this percentile is updated. Allowed range 0..100. Defaults to 10.

  • gamma (float, optional) – The upper limit to truncate abs values of weight diff. Defaults to 0.01. Any weight diff with abs<gamma will become 0.

  • data_kinds – kinds of DXO to filter

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

Compute the percentile on the abs delta_W.

Only share the params where absolute delta_W greater than the percentile value

Parameters:
  • dxo – information from client

  • shareable – that the dxo belongs to

  • fl_ctx – context provided by workflow

Returns: filtered dxo

class SVTPrivacy(fraction=0.1, epsilon=0.1, noise_var=0.1, gamma=1e-05, tau=1e-06, data_kinds: [<class 'str'>] = None, replace=True)[source]

Bases: DXOFilter

Implementation of the standard Sparse Vector Technique (SVT) differential privacy algorithm.

lambda_rho = gamma * 2.0 / epsilon threshold = tau + np.random.laplace(scale=lambda_rho)

Parameters:
  • fraction (float, optional) – used to determine dataset threshold. Defaults to 0.1.

  • epsilon (float, optional) – Defaults to 0.1.

  • noise_var (float, optional) – additive noise. Defaults to 0.1.

  • gamma (float, optional) – Defaults to 1e-5.

  • tau (float, optional) – Defaults to 1e-6.

  • data_kinds (str, optional) – Defaults to None.

  • replace (bool) – whether to sample with replacement. Defaults to True.

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

Compute the differentially private SVT.

Parameters:
  • dxo – information from client

  • shareable – that the dxo belongs to

  • fl_ctx – context provided by workflow

Returns: filtered result.