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:
objectConfiguration 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, callcalibrate()to obtain a new config with anoise_multipliercalibrated 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_bandsfor the best utility.expected_participations – The number of times each example participates across all iterations. With
POISSONthis is an expectation, and the Poisson sampling probability is derived asexpected_participations * num_bands / iterations. WithRANDOM_ALLOCATIONthis 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_strategywill always return batches of size at mosttruncated_batch_size, and accounting will be based on truncated Poisson sampling (Choquette-Choo et al. (2025)). Only supported withPOISSON.num_examples – The number of examples in the dataset. Required when
truncated_batch_sizeis 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 usingEQUAL_SPLIT, and otherwise it will be partitioned usingINDEPENDENT. Only supported withPOISSON, 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. UseRANDOM_ALLOCATIONfor (cyclic) random allocation, which gives each example exactlyexpected_participationsparticipations.
Methods
__init__Returns a new config with a calibrated
noise_multiplier.Returns a BandMFConfig with an RMSE-optimized strategy.
Returns a DP execution plan for the given BandMF mechanism config.
Attributes
The number of bands in the strategy matrix.
Root mean squared error of the mechanism on the prefix-sum workload.
-
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_multipliermust 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 byexpected_participationsso 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_multiplierhas not been set.NotImplementedError – If
column_normalizeis 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 innoise_multiplierspace 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 toPLDAccountant.
- Return type:
- 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
BandMFConfigfor 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:
- 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 asdtype,sharding, andmicrobatching. IfNone, default values are used for all performance flags.noise_seed (
int|None) – Optional seed for the random number generator used for noise addition. IfNone, 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:
- Returns:
A DPExecutionPlan configured from this config and the given performance flags.
- Raises:
ValueError – If
noise_multiplierhas not been set.