class_docstr: 2D Image to Patch Embedding
class_docstr_tok: ["2D","Image","to","Patch","Embedding"]
code: def __init__(self, config: MgpstrConfig):
      super().__init__()
      image_size = (
          config.image_size
          if isinstance(config.image_size, collections.abc.Iterable)
          else (config.image_size, config.image_size)
      )
      patch_size = (
          config.patch_size
          if isinstance(config.patch_size, collections.abc.Iterable)
          else (config.patch_size, config.patch_size)
      )
      self.image_size = image_size
      self.patch_size = patch_size
      self.grid_size = (
          image_size[0] // patch_size[0],
          image_size[1] // patch_size[1],
      )
      self.num_patches = self.grid_size[0] * self.grid_size[1]
      self.num_tokens = 2 if config.distilled else 1
  
      self.proj = nn.Conv2d(
          config.num_channels,
          config.hidden_size,
          kernel_size=patch_size,
          stride=patch_size,
      )
  
      self.cls_token = nn.Parameter(
          torch.zeros(1, 1, config.hidden_size)
      )
  
      self.pos_embed = nn.Parameter(
          torch.zeros(
              1, self.num_patches + self.num_tokens, config.hidden_size
          )
      )
      self.pos_drop = nn.Dropout(p=config.drop_rate)
  
imports: import collections.abc
  from dataclasses import dataclass
  from typing import Optional, Tuple, Union
  import torch
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch import nn
  from ...modeling_outputs import BaseModelOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import ModelOutput, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_mgp_str import MgpstrConfig
label_desc: Use image node_id 1 to create a new MgpstrEmbeddings object from inherited base classes: nn with example: obj = MgpstrEmbeddings(config)