code: def create_clip_model(
      config_path: Optional[str] = None,
      device: Optional[torch.device] = None,
      tokenizer: Optional[SimpleTokenizer] = None,
  ) -> CLIPModel:
      if config_path is None:
          config_path = default_config_path()
      if device is None:
          device = torch.device(
              "cuda" if torch.cuda.is_available() else "cpu"
          )
      if tokenizer is None:
          tokenizer = SimpleTokenizer()
  
      with open(config_path, "r") as f:
          config = yaml.load(f, Loader=yaml.SafeLoader)
  
      text_encoder = TextEncoder(
          n_bpe_vocab=config["n_vocab"],
          max_text_len=config["max_text_len"],
          n_embd=config["n_embd"],
          n_head=config["n_head_text"],
          n_xf_blocks=config["n_xf_blocks_text"],
          n_head_state=config["n_head_state_text"],
          device=device,
      )
  
      image_encoder = ImageEncoder(
          image_size=config["image_size"],
          patch_size=config["patch_size"],
          n_embd=config["n_embd"],
          n_head=config["n_head_image"],
          n_xf_blocks=config["n_xf_blocks_image"],
          n_head_state=config["n_head_state_image"],
          n_timestep=config["n_timesteps"],
          device=device,
      )
  
      logit_scale = torch.tensor(
          np.log(config["logit_scale"]),
          dtype=torch.float32,
          device=device,
          requires_grad=False,
      )
  
      return CLIPModel(
          config=config,
          text_encoder=text_encoder,
          image_encoder=image_encoder,
          logit_scale=logit_scale,
          device=device,
          tokenizer=tokenizer,
      )
  
file_path: glide-text2im/glide_text2im/clip/model_creation.py
imports: import os
  from functools import lru_cache
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import attr
  import numpy
  import torch
  import torch.nn
  import yaml
  from glide_text2im.tokenizer.simple_tokenizer import SimpleTokenizer
  from .encoders import ImageEncoder, TextEncoder
label_desc: Use image node_id 2 for calling a global function with example usage: create_clip_model(config_path, device, tokenizer) and returns: CLIPModel