code: def twod_interpolate_position_embeddings_hook(
      model_cfg,
      class_token_present,
      state_dict,
      prefix,
      local_metadata,
      strict,
      missing_keys,
      unexpected_keys,
      error_msgs,
  ):
      num_patches_per_dim_h = model_cfg.img_h // model_cfg.patch_dim
      num_patches_per_dim_w = model_cfg.img_w // model_cfg.patch_dim
      num_patches = num_patches_per_dim_h * num_patches_per_dim_w
      hidden_size = model_cfg.hidden_size
      class_token_length = model_cfg.get("class_token_length", 8)
  
      key = prefix + "weight"
  
      assert key in state_dict, f"{key} not in {state_dict.keys()}"
      if key in state_dict:
          input_param = state_dict[key]
  
          input_seq_len = input_param.shape[0]
          assert isPerfectSquare(input_seq_len) or isPerfectSquare(
              input_seq_len - class_token_length
          )
          input_has_class_token = not isPerfectSquare(input_seq_len)
          num_tok_input = (
              input_seq_len - class_token_length
              if input_has_class_token
              else input_seq_len
          )
          num_tok_output = num_patches
          output_has_class_token = class_token_present
  
          # update input_param and load it to state_dict[key]
          if input_has_class_token:
              input_param_tok = input_param[:class_token_length, :]
              input_param_grid = input_param[class_token_length:, :]
          else:
              input_param_tok = torch.zeros(
                  class_token_length,
                  hidden_size,
                  device=input_param.device,
              )
              input_param_grid = input_param
  
          assert input_param.shape[1] == hidden_size
  
          if num_tok_input != num_tok_output:
              gs_input = int(math.sqrt(num_tok_input))
              gs_new = (num_patches_per_dim_h, num_patches_per_dim_w)
  
              input_param_grid = input_param_grid.transpose(
                  0, 1
              ).contiguous()
              input_param_grid = input_param_grid.reshape(
                  (1, -1, gs_input, gs_input)
              )
              input_param_grid = input_param_grid.float()
              scale_factor = (
                  gs_new[0] / gs_input,
                  gs_new[1] / gs_input,
              )
  
              input_param_grid = F.interpolate(
                  input_param_grid,
                  scale_factor=scale_factor,
                  mode="bilinear",
              )
  
              input_param_grid = input_param_grid.half()
              input_param_grid = input_param_grid.reshape(
                  (-1, num_tok_output)
              )
              input_param_grid = input_param_grid.transpose(
                  0, 1
              ).contiguous()
  
              assert input_param_grid.shape[1] == hidden_size
  
          input_param = input_param_grid
          assert (
              input_param.shape[0] == num_tok_output
              and input_param.shape[1] == hidden_size
          )
  
          if output_has_class_token:
              input_param = torch.cat(
                  (input_param_tok, input_param), dim=0
              )
  
          state_dict[key] = input_param
  
imports: import math
  from functools import partial
  import einops
  import torch
  import torch.nn.functional
  from nemo.collections.nlp.modules.common.megatron.fused_layer_norm import get_layer_norm
  from nemo.collections.nlp.modules.common.megatron.module import MegatronModule
  from nemo.collections.nlp.modules.common.megatron.utils import ApexGuardDefaults, init_method_normal, scaled_init_method_normal
  from nemo.collections.vision.modules.common.megatron.vision_transformer import ParallelVisionTransformer
label_desc: Use image node_id 2 for calling a global function with example usage: twod_interpolate_position_embeddings_hook(model_cfg, class_token_present, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) without return types