code: def interpolate_pos_embed(pos_embed_checkpoint, visual_encoder):
      # interpolate position embedding
      embedding_size = pos_embed_checkpoint.shape[-1]
      num_patches = visual_encoder.patch_embed.num_patches
      num_extra_tokens = (
          visual_encoder.pos_embed.shape[-2] - num_patches
      )
      # height (== width) for the checkpoint position embedding
      orig_size = int(
          (pos_embed_checkpoint.shape[-2] - num_extra_tokens) ** 0.5
      )
      # height (== width) for the new position embedding
      new_size = int(num_patches**0.5)
  
      if orig_size != new_size:
          # class_token and dist_token are kept unchanged
          extra_tokens = pos_embed_checkpoint[:, :num_extra_tokens]
          # only the position tokens are interpolated
          pos_tokens = pos_embed_checkpoint[:, num_extra_tokens:]
          pos_tokens = pos_tokens.reshape(
              -1, orig_size, orig_size, embedding_size
          ).permute(0, 3, 1, 2)
          pos_tokens = torch.nn.functional.interpolate(
              pos_tokens,
              size=(new_size, new_size),
              mode="bicubic",
              align_corners=False,
          )
          pos_tokens = pos_tokens.permute(0, 2, 3, 1).flatten(1, 2)
          new_pos_embed = torch.cat((extra_tokens, pos_tokens), dim=1)
          print(
              "reshape position embedding from %d to %d"
              % (orig_size**2, new_size**2)
          )
  
          return new_pos_embed
      else:
          return pos_embed_checkpoint
  
imports: import collections.abc
  import math
  import warnings
  from dataclasses import dataclass
  from functools import partial
  from itertools import repeat
  import omegaconf
  import torch
  import torch.nn
  import torch.nn.functional
  from mmf.common.registry import registry
  from mmf.modules.encoders import Encoder
label_desc: Use image node_id 7 for calling a global function with example usage: interpolate_pos_embed(pos_embed_checkpoint, visual_encoder) and returns: new_pos_embed, pos_embed_checkpoint