class_docstr: This class defines an nn.Module whose parameters are renamed. This is useful when you want to
  reimplement a layer but make sure its state_dict and list of parameters are exactly the same
  as another reference layer so that you can have a drop-in replacement that does not depend on
  how your layer is actually implemented. In Opacus, this is used for DPLSTM, where our
  implementation leverages submodules and requires alignment to the state_dict of nn.LSTM.
  
  Example:
  
      >>> class DPModel(RenameParamsMixin, nn.Module):
      ...    def __init__(self, hidden_size):
      ...        super().__init__()
      ...        self.w = nn.Parameter(torch.zeros(hidden_size, requires_grad=True))
      ...        self.set_rename_map({"w": "weights"})
      ...
      >>> model = DPModel(5)
      >>> model.state_dict()
      {'weights': tensor([0., 0., 0., 0., 0.])}
docstr: Whenever you set an attribute, eg `self.linear`, this is called to actually register it in
  any nn.Module. We rely on the masking trick explained in the docs for
  ``_register_renamed_parameters`` to make sure we replace things only once. If a new parameter
  in the rename list is detected, we rename and mask it so next time this is called we will
  no longer find it.
docstr_tok: ["Whenever","you","set","an","attribute",",","eg","`","self.linear","`",",","this","is","called","to","actually","register","it","in","any","nn.Module",".","We","rely","on","the","masking","trick","explained","in","the","docs","for","``","_register_renamed_parameters","``","to","make","sure","we","replace","things","only","once",".","If","a","new","parameter","in","the","rename","list","is","detected",",","we","rename","and","mask","it","so","next","time","this","is","called","we","will","no","longer","find","it","."]
code: def __setattr__(
      self, name: str, value: Union[Tensor, nn.Module]
  ) -> None:
      """
      Whenever you set an attribute, eg `self.linear`, this is called to actually register it in
      any nn.Module. We rely on the masking trick explained in the docs for
      ``_register_renamed_parameters`` to make sure we replace things only once. If a new parameter
      in the rename list is detected, we rename and mask it so next time this is called we will
      no longer find it.
      """
      super().__setattr__(name, value)
      try:
          self._register_renamed_parameters()
      except AttributeError:
          # At the very beginning of instantiation, this will fail because we do not yet have
          # self._parameters. Safe to ignore.
          pass
  
file_path: opacus/opacus/layers/param_rename.py
imports: from typing import Dict, Union
  import torch.nn
  from torch import Tensor
  from torch.nn.modules.module import _IncompatibleKeys
label_desc: Use image node_id 3 for calling the RenameParamsMixin obj's underlying member method code with example usage: obj.__setattr__(name, value) without return types