class_docstr: Adapted from CLIP: https://github.com/openai/CLIP/blob/main/clip/model.py
class_docstr_tok: ["Adapted","from","CLIP",":","https",":","\/\/github.com\/openai\/CLIP\/blob\/main\/clip\/model.py"]
code: def __init__(
      self,
      spacial_dim: int,
      embed_dim: int,
      num_heads_channels: int,
      output_dim: Optional[int] = None,
  ):
      super().__init__()
      self.positional_embedding = nn.Parameter(
          th.randn(embed_dim, spacial_dim**2 + 1) / embed_dim**0.5
      )
      self.qkv_proj = conv_nd(1, embed_dim, 3 * embed_dim, 1)
      self.c_proj = conv_nd(1, embed_dim, output_dim or embed_dim, 1)
      self.num_heads = embed_dim // num_heads_channels
      self.attention = QKVAttention(self.num_heads)
  
imports: import logging
  import math
  from abc import abstractmethod
  from typing import Iterable, List, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from einops import rearrange
  from torch.utils.checkpoint import checkpoint
  from ...modules.attention import SpatialTransformer
  from ...modules.diffusionmodules.util import avg_pool_nd, conv_nd, linear, normalization, timestep_embedding, zero_module
  from ...modules.video_attention import SpatialVideoTransformer
  from ...util import exists
label_desc: Use image node_id 1 to create a new AttentionPool2d object from inherited base classes: nn with example: obj = AttentionPool2d(spacial_dim, embed_dim, num_heads_channels, output_dim)