privacy_args
privacy_args
¶
Privacy arguments and noise multiplier computation for DP training.
Provides PrivacyArguments (target epsilon/delta, noise multiplier, clipping norm),
SafeSynthesizerAccountant for epsilon accounting (PRV or RDP), and
prv_find_noise_multiplier() to solve for noise scale given a target epsilon.
Classes:
| Name | Description |
|---|---|
SafeSynthesizerAccountant |
Privacy accountant for computing epsilon from training steps. |
PrivacyArguments |
Store for DP training parameters (epsilon, delta, noise, clipping). |
Functions:
| Name | Description |
|---|---|
prv_find_noise_multiplier |
Find a noise multiplier that satisfies a given target epsilon. |
SafeSynthesizerAccountant(use_prv, noise_multiplier, sampling_probability, delta, num_steps)
dataclass
¶
Privacy accountant for computing epsilon from training steps.
Wraps either PRV (privacy random variable) or Opacus RDP accountant. Use PRV when possible; RDP is used as fallback if PRV fails to converge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_prv
|
bool
|
If True, use PRV accountant; otherwise RDP. |
required |
noise_multiplier
|
Scale of Gaussian noise added to gradients. |
required | |
sampling_probability
|
Probability of a record being in a batch. |
required | |
delta
|
Target delta for (epsilon, delta)-DP. |
required | |
num_steps
|
Maximum number of composition steps (+1 for headroom) (i.e. "would one more step exceed the budget?"). |
required |
Methods:
| Name | Description |
|---|---|
compute_epsilon |
Compute epsilon consumed after the given number of steps. |
Source code in src/nemo_safe_synthesizer/privacy/dp_transformers/privacy_args.py
compute_epsilon(steps)
¶
Compute epsilon consumed after the given number of steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
int
|
Number of optimizer steps taken. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The current epsilon value for the configured delta. |
Source code in src/nemo_safe_synthesizer/privacy/dp_transformers/privacy_args.py
PrivacyArguments(target_epsilon=None, target_delta=None, per_sample_max_grad_norm=None, noise_multiplier=None, poisson_sampling=False, use_prv=True)
dataclass
¶
Store for DP training parameters (epsilon, delta, noise, clipping).
Exactly one of target_epsilon or noise_multiplier must be set.
If target_epsilon is set, initialize() must be called to solve
for the noise multiplier before training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_epsilon
|
Optional[float]
|
Target epsilon at end of training (mutually exclusive with noise multiplier). |
None
|
target_delta
|
float | Literal['auto'] | None
|
Target delta. |
None
|
per_sample_max_grad_norm
|
Optional[float]
|
Max L2 norm for per-sample gradient clipping. |
None
|
noise_multiplier
|
Optional[float]
|
Gaussian noise scale for gradients. Mutually exclusive with target_epsilon. |
None
|
poisson_sampling
|
Optional[bool]
|
Enable Poisson sampling for proper DP accounting. |
False
|
use_prv
|
Optional[bool]
|
If True, use PRV accountant; fallback to RDP if PRV fails to converge. |
True
|
Methods:
| Name | Description |
|---|---|
initialize |
Solve for noise multiplier from target epsilon, or confirm existing multiplier. |
Attributes:
| Name | Type | Description |
|---|---|---|
is_initialized |
bool
|
True if per_sample_max_grad_norm, noise_multiplier, and target_delta are set. |
is_initialized
property
¶
True if per_sample_max_grad_norm, noise_multiplier, and target_delta are set.
initialize(sampling_probability, num_steps)
¶
Solve for noise multiplier from target epsilon, or confirm existing multiplier.
Called before training when target_epsilon is set. Uses PRV accountant
first; on convergence failure, falls back to Opacus RDP and sets
use_prv to False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_probability
|
float
|
Probability of a record being in a batch. |
required |
num_steps
|
int
|
Expected number of optimization steps. |
required |
Source code in src/nemo_safe_synthesizer/privacy/dp_transformers/privacy_args.py
prv_find_noise_multiplier(sampling_probability, num_steps, target_epsilon, target_delta, eps_error=0.05)
¶
Find a noise multiplier that satisfies a given target epsilon.
Uses binary search with PRV accountant to solve for the noise scale. Adapted from https://github.com/microsoft/prv_accountant/blob/main/prv_accountant/dpsgd.py#L39
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampling_probability
|
float
|
Probability of a record being in a batch. |
required |
num_steps
|
int
|
Number of optimization steps. |
required |
target_epsilon
|
float
|
Desired epsilon at end of training. |
required |
target_delta
|
float
|
Delta for (epsilon, delta)-DP. |
required |
eps_error
|
float
|
Allowed error for the final epsilon value. |
0.05
|
Returns:
| Type | Description |
|---|---|
float
|
Noise multiplier achieving approximately target_epsilon. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no valid noise multiplier found (e.g. epsilon too low or too few records), or if epsilon cannot be computed within eps_error. |
Source code in src/nemo_safe_synthesizer/privacy/dp_transformers/privacy_args.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |