class_docstr: ## Group Normalization Layer
docstr: * `groups` is the number of groups the features are divided into
  * `channels` is the number of features in the input
  * `eps` is $\epsilon$, used in $\sqrt{Var[x^{(k)}] + \epsilon}$ for numerical stability
  * `affine` is whether to scale and shift the normalized value
docstr_tok: ["*","`","groups","`","is","the","number","of","groups","the","features","are","divided","into","*","`","channels","`","is","the","number","of","features","in","the","input","*","`","eps","`","is","$","\\epsilon","$",",","used","in","$","\\sqrt","{","Var","[","x^","{","(","k",")","}","]","+","\\epsilon","}","$","for","numerical","stability","*","`","affine","`","is","whether","to","scale","and","shift","the","normalized","value"]
code: def __init__(
      self,
      groups: int,
      channels: int,
      *,
      eps: float = 1e-5,
      affine: bool = True,
  ):
      """
      * `groups` is the number of groups the features are divided into
      * `channels` is the number of features in the input
      * `eps` is $\epsilon$, used in $\sqrt{Var[x^{(k)}] + \epsilon}$ for numerical stability
      * `affine` is whether to scale and shift the normalized value
      """
      super().__init__()
  
      assert (
          channels % groups == 0
      ), "Number of channels should be evenly divisible by the number of groups"
      self.groups = groups
      self.channels = channels
  
      self.eps = eps
      self.affine = affine
      # Create parameters for $\gamma$ and $\beta$ for scale and shift
      if self.affine:
          self.scale = nn.Parameter(torch.ones(channels))
          self.shift = nn.Parameter(torch.zeros(channels))
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/normalization/group_norm/__init__.py
imports: import torch
  from torch import nn
  from labml_helpers.module import Module
label_desc: Use image node_id 1 to create a new GroupNorm object from inherited base classes: Module with example: obj = GroupNorm(groups, channels)