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
|
float | None
|
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
|
float | None
|
Max L2 norm for per-sample gradient clipping. |
None
|
noise_multiplier
|
float | None
|
Gaussian noise scale for gradients. Mutually exclusive with target_epsilon. |
None
|
poisson_sampling
|
bool
|
Enable Poisson sampling for proper DP accounting. |
False
|
use_prv
|
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
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |