class_docstr: Main entry point to the Opacus API - use ``PrivacyEngine``  to enable differential
  privacy for your model training.
  
  ``PrivacyEngine`` object encapsulates current privacy state (privacy budget +
  method it's been calculated) and exposes ``make_private`` method to wrap your
  PyTorch training objects with their private counterparts.
  
  Example:
      >>> dataloader = demo_dataloader
      >>> model = MyCustomModel()
      >>> optimizer = torch.optim.SGD(model.parameters(), lr=0.05)
      >>> privacy_engine = PrivacyEngine()
      >>>
      >>> model, optimizer, dataloader = privacy_engine.make_private(
      ...    module=model,
      ...    optimizer=optimizer,
      ...    data_loader=dataloader,
      ...    noise_multiplier=1.0,
      ...    max_grad_norm=1.0,
      ... )
      >>> # continue training as normal
class_docstr_tok: ["Main","entry","point","to","the","Opacus","API","-","use","``","PrivacyEngine","``","to","enable","differential","privacy","for","your","model","training",".","``","PrivacyEngine","``","object","encapsulates","current","privacy","state","(","privacy","budget","+","method","it","'s","been","calculated",")","and","exposes","``","make_private","``","method","to","wrap","your","PyTorch","training","objects","with","their","private","counterparts",".","Example",":",">",">",">","dataloader","=","demo_dataloader",">",">",">","model","=","MyCustomModel","(",")",">",">",">","optimizer","=","torch.optim.SGD","(","model.parameters","(",")",",","lr=0.05",")",">",">",">","privacy_engine","=","PrivacyEngine","(",")",">",">",">",">",">",">","model",",","optimizer",",","dataloader","=","privacy_engine.make_private","(","...","module=model",",","...","optimizer=optimizer",",","...","data_loader=dataloader",",","...","noise_multiplier=1.0",",","...","max_grad_norm=1.0",",","...",")",">",">",">","#","continue","training","as","normal"]
docstr: Args:
      accountant: Accounting mechanism. Currently supported:
          - rdp (:class:`~opacus.accountants.RDPAccountant`)
          - gdp (:class:`~opacus.accountants.GaussianAccountant`)
          - prv (:class`~opacus.accountants.PRVAccountant`)
      secure_mode: Set to ``True`` if cryptographically strong DP guarantee is
          required. ``secure_mode=True`` uses secure random number generator for
          noise and shuffling (as opposed to pseudo-rng in vanilla PyTorch) and
          prevents certain floating-point arithmetic-based attacks.
          See :meth:`~opacus.optimizers.optimizer._generate_noise` for details.
          When set to ``True`` requires ``torchcsprng`` to be installed
docstr_tok: ["Args",":","accountant",":","Accounting","mechanism",".","Currently","supported",":","-","rdp","(",":","class",":","`","~opacus.accountants.RDPAccountant","`",")","-","gdp","(",":","class",":","`","~opacus.accountants.GaussianAccountant","`",")","-","prv","(",":","class","`","~opacus.accountants.PRVAccountant","`",")","secure_mode",":","Set","to","``","True","``","if","cryptographically","strong","DP","guarantee","is","required",".","``","secure_mode=True","``","uses","secure","random","number","generator","for","noise","and","shuffling","(","as","opposed","to","pseudo-rng","in","vanilla","PyTorch",")","and","prevents","certain","floating-point","arithmetic-based","attacks",".","See",":","meth",":","`","~opacus.optimizers.optimizer._generate_noise","`","for","details",".","When","set","to","``","True","``","requires","``","torchcsprng","``","to","be","installed"]
code: def __init__(
      self, *, accountant: str = "prv", secure_mode: bool = False
  ):
      """
  
      Args:
          accountant: Accounting mechanism. Currently supported:
              - rdp (:class:`~opacus.accountants.RDPAccountant`)
              - gdp (:class:`~opacus.accountants.GaussianAccountant`)
              - prv (:class`~opacus.accountants.PRVAccountant`)
          secure_mode: Set to ``True`` if cryptographically strong DP guarantee is
              required. ``secure_mode=True`` uses secure random number generator for
              noise and shuffling (as opposed to pseudo-rng in vanilla PyTorch) and
              prevents certain floating-point arithmetic-based attacks.
              See :meth:`~opacus.optimizers.optimizer._generate_noise` for details.
              When set to ``True`` requires ``torchcsprng`` to be installed
      """
      self.accountant = create_accountant(mechanism=accountant)
      self.secure_mode = secure_mode
      self.secure_rng = None
      self.dataset = (
          None  # only used to detect switching to a different dataset
      )
      if self.secure_mode:
          try:
              import torchcsprng as csprng
          except ImportError as e:
              msg = (
                  "To use secure RNG, you must install the torchcsprng package! "
                  "Check out the instructions here: https://github.com/pytorch/csprng#installation"
              )
              raise ImportError(msg) from e
  
          self.secure_rng = csprng.create_random_device_generator(
              "/dev/urandom"
          )
      else:
          warnings.warn(
              "Secure RNG turned off. This is perfectly fine for experimentation as it allows "
              "for much faster training performance, but remember to turn it on and retrain "
              "one last time before production with ``secure_mode`` turned on."
          )
  
imports: import os
  import warnings
  from itertools import chain
  from typing import IO, Any, BinaryIO, Dict, List, Optional, Tuple, Union
  import torch
  from opacus.accountants import create_accountant
  from opacus.accountants.utils import get_noise_multiplier
  from opacus.data_loader import DPDataLoader, switch_generator
  from opacus.distributed import DifferentiallyPrivateDistributedDataParallel
  from opacus.grad_sample import AbstractGradSampleModule, GradSampleModule, get_gsm_class, wrap_model
  from opacus.optimizers import DPOptimizer, get_optimizer_class
  from opacus.schedulers import _GradClipScheduler, _NoiseScheduler
  from opacus.validators.module_validator import ModuleValidator
  from torch import nn, optim
  from torch.nn.parallel import DistributedDataParallel
  from torch.utils.data import DataLoader
label_desc: Use image node_id 1 to create a new PrivacyEngine object  with example: obj = PrivacyEngine()