class_docstr: <a id="ConvMixerLayer"></a>
  
  ## ConvMixer layer
  
  This is a single ConvMixer layer. The model will have a series of these.
class_docstr_tok: ["<","a","id=","''","ConvMixerLayer","''",">","<","\/a",">","#","#","ConvMixer","layer","This","is","a","single","ConvMixer","layer",".","The","model","will","have","a","series","of","these","."]
docstr: * `d_model` is the number of channels in patch embeddings, $h$
  * `kernel_size` is the size of the kernel of spatial convolution, $k$
docstr_tok: ["*","`","d_model","`","is","the","number","of","channels","in","patch","embeddings",",","$","h","$","*","`","kernel_size","`","is","the","size","of","the","kernel","of","spatial","convolution",",","$","k","$"]
code: def __init__(self, d_model: int, kernel_size: int):
      """
      * `d_model` is the number of channels in patch embeddings, $h$
      * `kernel_size` is the size of the kernel of spatial convolution, $k$
      """
      super().__init__()
      # Depth-wise convolution is separate convolution for each channel.
      # We do this with a convolution layer with the number of groups equal to the number of channels.
      # So that each channel is it's own group.
      self.depth_wise_conv = nn.Conv2d(
          d_model,
          d_model,
          kernel_size=kernel_size,
          groups=d_model,
          padding=(kernel_size - 1) // 2,
      )
      # Activation after depth-wise convolution
      self.act1 = nn.GELU()
      # Normalization after depth-wise convolution
      self.norm1 = nn.BatchNorm2d(d_model)
  
      # Point-wise convolution is a $1 \times 1$ convolution.
      # i.e. a linear transformation of patch embeddings
      self.point_wise_conv = nn.Conv2d(d_model, d_model, kernel_size=1)
      # Activation after point-wise convolution
      self.act2 = nn.GELU()
      # Normalization after point-wise convolution
      self.norm2 = nn.BatchNorm2d(d_model)
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/conv_mixer/__init__.py
imports: import torch
  from torch import nn
  from labml_helpers.module import Module
  from labml_nn.utils import clone_module_list
label_desc: Use image node_id 1 to create a new ConvMixerLayer object from inherited base classes: Module with example: obj = ConvMixerLayer(d_model, kernel_size)