Version of :meth:`~opacus.privacy_engine.PrivacyEngine.make_private`, that calculates privacy parameters based on a given privacy budget. For the full documentation see :meth:`~opacus.privacy_engine.PrivacyEngine.make_private` Args: module: PyTo
(
self,
*,
module: nn.Module,
optimizer: optim.Optimizer,
criterion=nn.CrossEntropyLoss(), # Added deafult for backward compatibility
data_loader: DataLoader,
target_epsilon: float,
target_delta: float,
epochs: int,
max_grad_norm: Union[float, List[float]],
batch_first: bool = True,
loss_reduction: str = "mean",
poisson_sampling: bool = True,
clipping: str = "flat",
noise_generator=None,
grad_sample_mode: str = "hooks",
wrap_model: bool = True,
**kwargs,
)
| 475 | return module, optimizer, data_loader |
| 476 | |
| 477 | def make_private_with_epsilon( |
| 478 | self, |
| 479 | *, |
| 480 | module: nn.Module, |
| 481 | optimizer: optim.Optimizer, |
| 482 | criterion=nn.CrossEntropyLoss(), # Added deafult for backward compatibility |
| 483 | data_loader: DataLoader, |
| 484 | target_epsilon: float, |
| 485 | target_delta: float, |
| 486 | epochs: int, |
| 487 | max_grad_norm: Union[float, List[float]], |
| 488 | batch_first: bool = True, |
| 489 | loss_reduction: str = "mean", |
| 490 | poisson_sampling: bool = True, |
| 491 | clipping: str = "flat", |
| 492 | noise_generator=None, |
| 493 | grad_sample_mode: str = "hooks", |
| 494 | wrap_model: bool = True, |
| 495 | **kwargs, |
| 496 | ) -> Union[ |
| 497 | Tuple[ |
| 498 | Union[AbstractGradSampleModule, GradSampleHooks], DPOptimizer, DataLoader |
| 499 | ], |
| 500 | Tuple[ |
| 501 | Union[AbstractGradSampleModule, GradSampleHooks], |
| 502 | DPOptimizer, |
| 503 | DPLossFastGradientClipping, |
| 504 | DataLoader, |
| 505 | ], |
| 506 | ]: |
| 507 | """ |
| 508 | Version of :meth:`~opacus.privacy_engine.PrivacyEngine.make_private`, |
| 509 | that calculates privacy parameters based on a given privacy budget. |
| 510 | |
| 511 | For the full documentation see |
| 512 | :meth:`~opacus.privacy_engine.PrivacyEngine.make_private` |
| 513 | |
| 514 | Args: |
| 515 | module: PyTorch module to be used for training |
| 516 | optimizer: Optimizer to be used for training |
| 517 | data_loader: DataLoader to be used for training |
| 518 | target_epsilon: Target epsilon to be achieved, a metric of privacy loss at differential changes in data. |
| 519 | target_delta: Target delta to be achieved. Probability of information being leaked. |
| 520 | epochs: Number of training epochs you intend to perform; noise_multiplier relies on this to calculate |
| 521 | an appropriate sigma to ensure privacy budget of (target_epsilon, target_delta) at the end |
| 522 | of epochs. |
| 523 | max_grad_norm: The maximum norm of the per-sample gradients. Any gradient with norm |
| 524 | higher than this will be clipped to this value. |
| 525 | batch_first: Flag to indicate if the input tensor to the corresponding module |
| 526 | has the first dimension representing the batch. If set to True, dimensions on |
| 527 | input tensor are expected be ``[batch_size, ...]``, otherwise |
| 528 | ``[K, batch_size, ...]`` |
| 529 | loss_reduction: Indicates if the loss reduction (for aggregating the gradients) |
| 530 | is a sum or a mean operation. Can take values "sum" or "mean" |
| 531 | poisson_sampling: ``True`` if you want to use standard sampling required |
| 532 | for DP guarantees. Setting ``False`` will leave provided data_loader |
| 533 | unchanged. Technically this doesn't fit the assumptions made by |
| 534 | privacy accounting mechanism, but it can be a good approximation when |