class_docstr: Mixin to provide momentum encoder functionalities.
  
  Provides the following functionalities:
      - Momentum encoder initialization.
      - Momentum updates.
      - Batch shuffling and unshuffling.
  
  To make use of the mixin, simply inherit from it:
  
  >>> class MyMoCo(nn.Module, _MomentumEncoderMixin):
  >>>
  >>>     def __init__(self, backbone):
  >>>         super(MyMoCo, self).__init__()
  >>>
  >>>         self.backbone = backbone
  >>>         self.projection_head = get_projection_head()
  >>>
  >>>         # initialize momentum_backbone and momentum_projection_head
  >>>         self._init_momentum_encoder()
  >>>
  >>>     def forward(self, x: Tensor):
  >>>
  >>>         # do the momentum update
  >>>         self._momentum_update(0.999)
  >>>
  >>>         # use momentum backbone
  >>>         y = self.momentum_backbone(x)
  >>>         y = self.momentum_projection_head(y)
class_docstr_tok: ["Mixin","to","provide","momentum","encoder","functionalities",".","Provides","the","following","functionalities",":","-","Momentum","encoder","initialization",".","-","Momentum","updates",".","-","Batch","shuffling","and","unshuffling",".","To","make","use","of","the","mixin",",","simply","inherit","from","it",":",">",">",">","class","MyMoCo","(","nn.Module",",","_MomentumEncoderMixin",")",":",">",">",">",">",">",">","def","__init__","(","self",",","backbone",")",":",">",">",">","super","(","MyMoCo",",","self",")",".__init__","(",")",">",">",">",">",">",">","self.backbone","=","backbone",">",">",">","self.projection_head","=","get_projection_head","(",")",">",">",">",">",">",">","#","initialize","momentum_backbone","and","momentum_projection_head",">",">",">","self._init_momentum_encoder","(",")",">",">",">",">",">",">","def","forward","(","self",",","x",":","Tensor",")",":",">",">",">",">",">",">","#","do","the","momentum","update",">",">",">","self._momentum_update","(","0.999",")",">",">",">",">",">",">","#","use","momentum","backbone",">",">",">","y","=","self.momentum_backbone","(","x",")",">",">",">","y","=","self.momentum_projection_head","(","y",")"]
docstr: Initializes momentum backbone and a momentum projection head.
docstr_tok: ["Initializes","momentum","backbone","and","a","momentum","projection","head","."]
code: def _init_momentum_encoder(self) -> None:
      """Initializes momentum backbone and a momentum projection head."""
      assert self.backbone is not None
      assert self.projection_head is not None
  
      self.momentum_backbone = copy.deepcopy(self.backbone)
      self.momentum_projection_head = copy.deepcopy(
          self.projection_head
      )
  
      _deactivate_requires_grad(self.momentum_backbone.parameters())
      _deactivate_requires_grad(
          self.momentum_projection_head.parameters()
      )
  
file_path: lightly/lightly/models/_momentum.py
imports: import copy
  from typing import Iterable, Tuple
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn.parameter import Parameter
label_desc: Use image node_id 1 for calling the _MomentumEncoderMixin obj's underlying member method code with example usage: obj._init_momentum_encoder() without return types