code: def mapping_openclip_state_dict(open_model):
      open_state_dict = open_model.state_dict()
      key_mapping = {
          "positional_embedding": "text_encoder.language_model.embedding.position_embeddings",
          "token_embedding.weight": "text_encoder.language_model.embedding.word_embeddings.weight",
          "ln_final.weight": "text_encoder.language_model.encoder.final_layernorm.weight",
          "ln_final.bias": "text_encoder.language_model.encoder.final_layernorm.bias",
          "text_projection": "text_encoder.head.weight",
      }
      layer_mapping = {
          ".ln_1.weight": ".input_layernorm.weight",
          ".ln_1.bias": ".input_layernorm.bias",
          ".attn.in_proj_weight": ".self_attention.query_key_value.weight",
          ".attn.in_proj_bias": ".self_attention.query_key_value.bias",
          ".attn.out_proj.weight": ".self_attention.dense.weight",
          ".attn.out_proj.bias": ".self_attention.dense.bias",
          ".ln_2.weight": ".post_attention_layernorm.weight",
          ".ln_2.bias": ".post_attention_layernorm.bias",
          ".mlp.c_fc.weight": ".mlp.dense_h_to_4h.weight",
          ".mlp.c_fc.bias": ".mlp.dense_h_to_4h.bias",
          ".mlp.c_proj.weight": ".mlp.dense_4h_to_h.weight",
          ".mlp.c_proj.bias": ".mlp.dense_4h_to_h.bias",
          ".ln_pre.weight": ".preprocess_layernorm.weight",
          ".ln_pre.bias": ".preprocess_layernorm.bias",
          ".ln_post.weight": ".transformer.final_layernorm.weight",
          ".ln_post.bias": ".transformer.final_layernorm.bias",
          ".positional_embedding": ".position_embeddings",
          ".backbone.proj": ".head.weight",
          ".class_embedding": ".cls_token",
          ".backbone.conv1.weight": ".backbone.linear_encoder.weight",
      }
  
      nemo_state_dict = {}
      for key in open_state_dict.keys():
          if key.startswith("transformer.resblocks."):
              key_ = key.replace(
                  "transformer.resblocks.",
                  "text_encoder.language_model.encoder.layers.",
              )
          elif key.startswith("visual.transformer.resblocks."):
              key_ = key.replace(
                  "visual.transformer.resblocks.",
                  "vision_encoder.backbone.transformer.layers.",
              )
          elif key.startswith("visual."):
              key_ = key.replace("visual.", "vision_encoder.backbone.")
          else:
              key_ = key
          for pat in key_mapping:
              if key_ == pat:
                  key_ = key_.replace(pat, key_mapping[pat])
          for pat in layer_mapping:
              if key_.endswith(pat):
                  key_ = key_[: -len(pat)] + layer_mapping[pat]
                  break
          nemo_state_dict[key_] = open_state_dict[key]
  
      nemo_state_dict["text_encoder.head.weight"] = nemo_state_dict[
          "text_encoder.head.weight"
      ].T
      nemo_state_dict["vision_encoder.head.weight"] = nemo_state_dict[
          "vision_encoder.head.weight"
      ].T
      nemo_state_dict[
          "vision_encoder.backbone.cls_token"
      ] = nemo_state_dict["vision_encoder.backbone.cls_token"].reshape(
          1, 1, -1
      )
      w = nemo_state_dict[
          "vision_encoder.backbone.linear_encoder.weight"
      ]
      nemo_state_dict[
          "vision_encoder.backbone.linear_encoder.weight"
      ] = einops.rearrange(
          w,
          "b c p1 p2 -> b (p1 p2 c)",
      )
      nemo_state_dict[
          "vision_encoder.backbone.linear_encoder.bias"
      ] = torch.zeros(w.shape[0])
  
      return nemo_state_dict
  
file_path: NeMo/examples/multimodal/vision_language_foundation/clip/convert_external_clip_to_nemo.py
imports: import os
  from argparse import ArgumentParser
  import einops
  import open_clip
  import torch
  from omegaconf import OmegaConf
  from pytorch_lightning.plugins.environments import TorchElasticEnvironment
  from pytorch_lightning.trainer.trainer import Trainer
  from transformers import CLIPModel
  from nemo.collections.multimodal.models.vision_language_foundation.clip.megatron_clip_models import MegatronCLIPModel
  from nemo.collections.nlp.parts.nlp_overrides import NLPSaveRestoreConnector
  from nemo.utils import AppState, logging
  from nemo.utils.distributed import initialize_distributed
label_desc: Use image node_id 2 for calling a global function with example usage: mapping_openclip_state_dict(open_model) and returns: nemo_state_dict