code: def load_tf_weights_in_gpt2(model, config, gpt2_checkpoint_path):
      """Load tf checkpoints in a pytorch model"""
      try:
          import re
  
          import tensorflow as tf
      except ImportError:
          logger.error(
              "Loading a TensorFlow model in PyTorch, requires TensorFlow to be installed. Please see "
              "https://www.tensorflow.org/install/ for installation instructions."
          )
          raise
      tf_path = os.path.abspath(gpt2_checkpoint_path)
      logger.info(
          "Converting TensorFlow checkpoint from {}".format(tf_path)
      )
      # Load weights from TF model
      init_vars = tf.train.list_variables(tf_path)
      names = []
      arrays = []
      for name, shape in init_vars:
          logger.info(
              "Loading TF weight {} with shape {}".format(name, shape)
          )
          array = tf.train.load_variable(tf_path, name)
          names.append(name)
          arrays.append(array.squeeze())
  
      for name, array in zip(names, arrays):
          name = name[6:]  # skip "model/"
          name = name.split("/")
          pointer = model
          for m_name in name:
              if re.fullmatch(r"[A-Za-z]+\d+", m_name):
                  scope_names = re.split(r"(\d+)", m_name)
              else:
                  scope_names = [m_name]
              if scope_names[0] == "w" or scope_names[0] == "g":
                  pointer = getattr(pointer, "weight")
              elif scope_names[0] == "b":
                  pointer = getattr(pointer, "bias")
              elif scope_names[0] == "wpe" or scope_names[0] == "wte":
                  pointer = getattr(pointer, scope_names[0])
                  pointer = getattr(pointer, "weight")
              else:
                  pointer = getattr(pointer, scope_names[0])
              if len(scope_names) >= 2:
                  num = int(scope_names[1])
                  pointer = pointer[num]
          try:
              assert (
                  pointer.shape == array.shape
              ), f"Pointer shape {pointer.shape} and array shape {array.shape} mismatched"
          except AssertionError as e:
              e.args += (pointer.shape, array.shape)
              raise
          logger.info("Initialize PyTorch weight {}".format(name))
          pointer.data = torch.from_numpy(array)
      return model
  
imports: import os
  from dataclasses import dataclass
  from typing import List, Optional, Tuple
  import torch
  import torch.nn
  from torch.nn import CrossEntropyLoss, MSELoss
  from transformers.activations import ACT2FN
  from transformers.file_utils import ModelOutput, add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
  from transformers.modeling_outputs import BaseModelOutputWithPastAndCrossAttentions
  from transformers.modeling_utils import Conv1D, PreTrainedModel, SequenceSummary, find_pruneable_heads_and_indices, prune_conv1d_layer
  from transformers.utils import logging
  from transformers.utils.model_parallel_utils import assert_device_map, get_device_map
  from transformers.models.gpt2.configuration_gpt2 import GPT2Config
label_desc: Use image node_id 1 for calling a global function with example usage: load_tf_weights_in_gpt2(model, config, gpt2_checkpoint_path) and returns: model