jax_privacy.execution_plan.BandMFConfig#

class jax_privacy.execution_plan.BandMFConfig(*, iterations, expected_participations, strategy, noise_multiplier=None, l2_clip_norm=1.0, rescale_to_unit_norm=True, normalize_by=1.0, truncated_batch_size=None, num_examples=None, column_normalize=False, sub_strategy=CyclicInnerStrategy.POISSON)[source]#

Bases: object

Configuration for an Amplified BandMF-based DPExecutionPlan.

This config is designed to be fully serializable, defined in terms of simple types. The config can be created with or without a noise_multiplier. If created without one, call calibrate() to obtain a new config with a noise_multiplier calibrated to a target (epsilon, delta) guarantee.

Example Usage (Calibrate from epsilon/delta):
>>> config = BandMFConfig.default(
...   num_bands=1, iterations=1000, expected_participations=100,
... ).calibrate(epsilon=1.0, delta=1e-5)
Example Usage (Direct noise_multiplier):
>>> config = BandMFConfig.default(
...   num_bands=1, iterations=1000, expected_participations=100,
...   noise_multiplier=1.0,
... )
Example Usage (BandMF with custom strategy):
>>> config = BandMFConfig(
...   strategy=np.array([1.0, 0.5, 0.2]),
...   iterations=1000, expected_participations=400,
... ).calibrate(epsilon=1.0, delta=1e-5)
Example Usage (DP-SGD with random allocation instead of Poisson sampling):
>>> config = BandMFConfig.default(
...   num_bands=1, iterations=1000, expected_participations=100,
...   sub_strategy=CyclicInnerStrategy.RANDOM_ALLOCATION,
... ).calibrate(epsilon=1.0, delta=1e-5)

References: Choquette-Choo et al. (2023) and McKenna (2024).

Variables:
  • iterations – The number of iterations the mechanism is defined for. Tip: Set this to be a multiple of num_bands for the best utility.

  • expected_participations – The number of times each example participates across all iterations. With POISSON this is an expectation, and the Poisson sampling probability is derived as expected_participations * num_bands / iterations. With RANDOM_ALLOCATION this is the exact number of participations, and must be an integer.

  • strategy – The Toeplitz coefficients of the BandMF strategy matrix.

  • noise_multiplier – The ratio of noise standard deviation to the query sensitivity. The actual noise stddev is determined by this value, the query sensitivity, and the strategy matrix column norm. If not set, use calibrate() to automatically determine it from target (epsilon, delta) privacy parameters.

  • l2_clip_norm – The maximum L2 norm of the per-example gradients.

  • rescale_to_unit_norm – Divide the clipped gradient by the l2_clip_norm.

  • normalize_by – Divide the sum-of-clipped gradients by this value.

  • truncated_batch_size – If using truncated Poisson sampling, the maximum batch size to truncate to. If set, the plan.batch_selection_strategy will always return batches of size at most truncated_batch_size, and accounting will be based on truncated Poisson sampling (Choquette-Choo et al. (2025)). Only supported with POISSON.

  • num_examples – The number of examples in the dataset. Required when truncated_batch_size is set. Only set when the dataset size is considered public, non-sensitive information (e.g., when using zero-out adjacency rather than add-remove). If specified, the dataset will be partitioned using EQUAL_SPLIT, and otherwise it will be partitioned using INDEPENDENT. Only supported with POISSON, because accounting for random allocation assumes the add-or-remove-one adjacency notion.

  • column_normalize – Whether to column-normalize the strategy matrix. If True, each column of the realized strategy matrix is rescaled to have L2 norm 1.0, which makes the mechanism invariant to the scale of strategy.

  • sub_strategy – How examples are assigned to the iterations they are eligible for. Defaults to POISSON. Use RANDOM_ALLOCATION for (cyclic) random allocation, which gives each example exactly expected_participations participations.

Methods

__init__

calibrate

Returns a new config with a calibrated noise_multiplier.

default

Returns a BandMFConfig with an RMSE-optimized strategy.

make

Returns a DP execution plan for the given BandMF mechanism config.

Attributes

column_normalize

l2_clip_norm

noise_multiplier

normalize_by

num_bands

The number of bands in the strategy matrix.

num_examples

rescale_to_unit_norm

rmse

Root mean squared error of the mechanism on the prefix-sum workload.

sub_strategy

truncated_batch_size

iterations

expected_participations

strategy

iterations: int#
expected_participations: float#
strategy: Union[_Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]]#
noise_multiplier: float | None = None#
l2_clip_norm: float = 1.0#
rescale_to_unit_norm: bool = True#
normalize_by: float = 1.0#
truncated_batch_size: int | None = None#
num_examples: int | None = None#
column_normalize: bool = False#
sub_strategy: CyclicInnerStrategy = 'poisson'#
property num_bands: int#

The number of bands in the strategy matrix.

property rmse: float#

Root mean squared error of the mechanism on the prefix-sum workload.

Requires the config to be calibrated (noise_multiplier must be set). The actual noise stddev is noise_multiplier * max_column_norm (see make), so the error includes the same column norm factor and is invariant to the scale of the strategy. This method normalizes by expected_participations so that you can fairly compare RMSE across instances with different expected participations.

Returns:

The RMSE per query, in units of the clipped gradient.

Raises:
  • ValueError – If noise_multiplier has not been set.

  • NotImplementedError – If column_normalize is True.

calibrate(*, epsilon, delta, tol=None, accountant_fn=<class 'dp_accounting.pld.pld_privacy_accountant.PLDAccountant'>)[source]#

Returns a new config with a calibrated noise_multiplier.

Parameters:
  • epsilon (float) – The target privacy budget.

  • delta (float) – The target privacy failure probability.

  • tol (float | None) – The tolerance in noise_multiplier space for the calibration binary search. Defaults to 1e-6 if not specified.

  • accountant_fn (Callable[[NeighboringRelation], PrivacyAccountant]) – A function that returns a fresh privacy accountant used for calibration given a neighboring relation. Defaults to PLDAccountant.

Return type:

BandMFConfig

Returns:

A new BandMFConfig with calibrated noise_multiplier.

classmethod default(num_bands, iterations, expected_participations, strategy_optimization_steps=500, **kwargs)[source]#

Returns a BandMFConfig with an RMSE-optimized strategy.

See BandMFConfig for the full list of keyword arguments.

Parameters:
  • num_bands (int) – The number of bands in the strategy matrix.

  • iterations (int) – The number of iterations the mechanism is defined for.

  • expected_participations (float) – The expected number of times each example participates across all iterations.

  • strategy_optimization_steps (int) – The number of optimization steps to use for the strategy matrix.

  • **kwargs – Keyword arguments to pass to BandMFConfig.

Return type:

BandMFConfig

Returns:

A BandMFConfig with an RMSE-optimized strategy.

make(performance_flags=None, noise_seed=None)[source]#

Returns a DP execution plan for the given BandMF mechanism config.

Parameters:
  • performance_flags (PerformanceFlags | None) – Optional performance flags that control implementation details such as dtype, sharding, and microbatching. If None, default values are used for all performance flags.

  • noise_seed (int | None) – Optional seed for the random number generator used for noise addition. If None, a fresh random seed is drawn; pass an explicit seed for multi-host coordination or reproducible tests (and keep it secret in production deployments).

Return type:

DPExecutionPlan

Returns:

A DPExecutionPlan configured from this config and the given performance flags.

Raises:

ValueError – If noise_multiplier has not been set.