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"]
code: def _prepare_model(
      self,
      module: nn.Module,
      *,
      batch_first: bool = True,
      loss_reduction: str = "mean",
      grad_sample_mode: str = "hooks",
  ) -> AbstractGradSampleModule:
      # Ideally, validation should have been taken care of by calling
      # `get_compatible_module()`
      self.validate(module=module, optimizer=None, data_loader=None)
  
      # wrap
      if isinstance(module, AbstractGradSampleModule):
          if (
              module.batch_first != batch_first
              or module.loss_reduction != loss_reduction
              or type(module) is not get_gsm_class(grad_sample_mode)
          ):
              raise ValueError(
                  f"Pre-existing GradSampleModule doesn't match new arguments."
                  f"Got: module.batch_first: {module.batch_first}, module.loss_reduction: {module.loss_reduction}, type(module): {type(module)}"
                  f"Requested: batch_first:{batch_first}, loss_reduction: {loss_reduction}, grad_sample_mode: {grad_sample_mode} "
                  f"Please pass vanilla nn.Module instead"
              )
  
          return module
      else:
          return wrap_model(
              module,
              grad_sample_mode=grad_sample_mode,
              batch_first=batch_first,
              loss_reduction=loss_reduction,
          )
  
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 4 for calling the PrivacyEngine obj's underlying member method code with example usage: obj._prepare_model(module) and returns: module, wrap_model