code: def convert_open_clip_checkpoint(checkpoint):
      checkpoint = checkpoint["text_encoder"]
      text_model = CLIPTextModel.from_pretrained(
          "openai/clip-vit-large-patch14"
      )
  
      keys = list(checkpoint.keys())
  
      text_model_dict = {}
  
      if "cond_stage_model.model.text_projection" in checkpoint:
          d_model = int(
              checkpoint[
                  "cond_stage_model.model.text_projection"
              ].shape[0]
          )
      else:
          d_model = 1024
  
      for key in keys:
          if (
              "resblocks.23" in key
          ):  # Diffusers drops the final layer and only uses the penultimate layer
              continue
          if key in textenc_conversion_map:
              text_model_dict[textenc_conversion_map[key]] = checkpoint[
                  key
              ]
          # if key.startswith("cond_stage_model.model.transformer."):
          new_key = key[len("transformer.") :]
          if new_key.endswith(".in_proj_weight"):
              new_key = new_key[: -len(".in_proj_weight")]
              new_key = textenc_pattern.sub(
                  lambda m: protected[re.escape(m.group(0))], new_key
              )
              text_model_dict[new_key + ".q_proj.weight"] = checkpoint[
                  key
              ][:d_model, :]
              text_model_dict[new_key + ".k_proj.weight"] = checkpoint[
                  key
              ][d_model : d_model * 2, :]
              text_model_dict[new_key + ".v_proj.weight"] = checkpoint[
                  key
              ][d_model * 2 :, :]
          elif new_key.endswith(".in_proj_bias"):
              new_key = new_key[: -len(".in_proj_bias")]
              new_key = textenc_pattern.sub(
                  lambda m: protected[re.escape(m.group(0))], new_key
              )
              text_model_dict[new_key + ".q_proj.bias"] = checkpoint[
                  key
              ][:d_model]
              text_model_dict[new_key + ".k_proj.bias"] = checkpoint[
                  key
              ][d_model : d_model * 2]
              text_model_dict[new_key + ".v_proj.bias"] = checkpoint[
                  key
              ][d_model * 2 :]
          else:
              if (
                  key
                  != "transformer.text_model.embeddings.position_ids"
              ):
                  new_key = textenc_pattern.sub(
                      lambda m: protected[re.escape(m.group(0))],
                      new_key,
                  )
  
                  text_model_dict[new_key] = checkpoint[key]
  
              if (
                  key
                  == "transformer.text_model.embeddings.token_embedding.weight"
              ):
                  text_model_dict[
                      "text_model.embeddings.token_embedding.weight"
                  ] = checkpoint[key]
  
      text_model_dict.pop(
          "text_model.embeddings.transformer.text_model.embeddings.token_embedding.weight"
      )
  
      text_model.load_state_dict(text_model_dict)
  
      return text_model
  
file_path: diffusers/scripts/convert_gligen_to_diffusers.py
imports: import argparse
  import re
  import torch
  import yaml
  from transformers import CLIPProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
  from diffusers import AutoencoderKL, DDIMScheduler, StableDiffusionGLIGENPipeline, StableDiffusionGLIGENTextImagePipeline, UNet2DConditionModel
  from diffusers.pipelines.stable_diffusion.convert_from_ckpt import assign_to_checkpoint, conv_attn_to_linear, protected, renew_attention_paths, renew_resnet_paths, renew_vae_attention_paths, renew_vae_resnet_paths, shave_segments, textenc_conversion_map, textenc_pattern
label_desc: Use image node_id 1 for calling a global function with example usage: convert_open_clip_checkpoint(checkpoint) and returns: text_model