code: def split_and_convert_process(i, saved_dir, factor, key, args, val):
      if (
          key.find("input_layernorm.weight") != -1
          or key.find("input_layernorm.bias") != -1
          or key.find("attention.dense.bias") != -1
          or key.find("post_attention_layernorm.weight") != -1
          or key.find("post_attention_layernorm.bias") != -1
          or key.find("mlp.dense_4h_to_h.bias") != -1
          or key.find("final_layernorm.weight") != -1
          or key.find("final_layernorm.bias") != -1
      ):
          # shared weights, only need to convert the weights of rank 0
          if i == 0:
              saved_path = saved_dir + "/model." + key + ".bin"
              val.tofile(saved_path)
  
      elif (
          key.find("attention.dense.weight") != -1
          or key.find("mlp.dense_4h_to_h.weight") != -1
      ):
          split_vals = np.split(val, factor, axis=0)
          for j in range(factor):
              saved_path = (
                  saved_dir
                  + "/model."
                  + key
                  + ".%d.bin" % (i * factor + j)
              )
              split_vals[j].tofile(saved_path)
  
      elif (
          key.find("mlp.dense_h_to_4h.weight") != -1
          or key.find("mlp.dense_h_to_4h.bias") != -1
      ):
          split_vals = np.split(val, factor, axis=-1)
          for j in range(factor):
              saved_path = (
                  saved_dir
                  + "/model."
                  + key
                  + ".%d.bin" % (i * factor + j)
              )
              split_vals[j].tofile(saved_path)
  
      elif key.find("attention.query_key_value.bias") != -1:
          local_dim = (int)(val.shape[-1] / 3)
  
          val = val.reshape(3, local_dim)
          split_vals = np.split(val, factor, axis=-1)
  
          for j in range(factor):
              saved_path = (
                  saved_dir
                  + "/model."
                  + key
                  + ".%d.bin" % (i * factor + j)
              )
              split_vals[j].tofile(saved_path)
  
      elif key.find("attention.query_key_value.weight") != -1:
          hidden_dim = val.shape[0]
          local_dim = (int)(val.shape[-1] / 3)
  
          val = val.reshape(hidden_dim, 3, local_dim)
          split_vals = np.split(val, factor, axis=-1)
  
          for j in range(factor):
              saved_path = (
                  saved_dir
                  + "/model."
                  + key
                  + ".%d.bin" % (i * factor + j)
              )
              split_vals[j].tofile(saved_path)
  
      else:
          logger.warning("[ERROR] cannot find key '{}'".format(key))
  
file_path: nebuly/optimization/nebullvm/nebullvm/operations/optimizations/compilers/faster_transformer/gpt/utils/huggingface_gpt_convert.py
imports: import argparse
  import configparser
  import os
  import sys
  from loguru import logger
  import numpy
  from transformers import GPT2Model
  from nebullvm.optional_modules.torch import torch
label_desc: Use image node_id 2 for calling a global function with example usage: split_and_convert_process(i, saved_dir, factor, key, args, val) without return types