code: def checkpoint_filter_fn(
      state_dict,
      model,
      interpolation="bicubic",
      antialias=True,
  ):
      """convert patch embedding weight from manual patchify + linear proj to conv"""
      out_dict = {}
      state_dict = state_dict.get("model_ema", state_dict)
      state_dict = state_dict.get("model", state_dict)
      state_dict = state_dict.get("module", state_dict)
      state_dict = state_dict.get("state_dict", state_dict)
      # prefix for loading OpenCLIP compatible weights
      if "visual.trunk.pos_embed" in state_dict:
          prefix = "visual.trunk."
      elif "visual.pos_embed" in state_dict:
          prefix = "visual."
      else:
          prefix = ""
      mim_weights = prefix + "mask_token" in state_dict
      no_qkv = prefix + "blocks.0.attn.q_proj.weight" in state_dict
  
      len_prefix = len(prefix)
      for k, v in state_dict.items():
          if prefix:
              if k.startswith(prefix):
                  k = k[len_prefix:]
              else:
                  continue
  
          if "rope" in k:
              # fixed embedding no need to load buffer from checkpoint
              continue
  
          if "patch_embed.proj.weight" in k:
              _, _, H, W = model.patch_embed.proj.weight.shape
              if v.shape[-1] != W or v.shape[-2] != H:
                  v = resample_patch_embed(
                      v,
                      (H, W),
                      interpolation=interpolation,
                      antialias=antialias,
                      verbose=True,
                  )
          elif (
              k == "pos_embed"
              and v.shape[1] != model.pos_embed.shape[1]
          ):
              # To resize pos embedding when using model at different size from pretrained weights
              num_prefix_tokens = (
                  0
                  if getattr(model, "no_embed_class", False)
                  else getattr(model, "num_prefix_tokens", 1)
              )
              v = resample_abs_pos_embed(
                  v,
                  new_size=model.patch_embed.grid_size,
                  num_prefix_tokens=num_prefix_tokens,
                  interpolation=interpolation,
                  antialias=antialias,
                  verbose=True,
              )
  
          k = k.replace("mlp.ffn_ln", "mlp.norm")
          k = k.replace("attn.inner_attn_ln", "attn.norm")
          k = k.replace("mlp.w12", "mlp.fc1")
          k = k.replace("mlp.w1", "mlp.fc1_g")
          k = k.replace("mlp.w2", "mlp.fc1_x")
          k = k.replace("mlp.w3", "mlp.fc2")
          if no_qkv:
              k = k.replace("q_bias", "q_proj.bias")
              k = k.replace("v_bias", "v_proj.bias")
  
          if mim_weights and k in (
              "mask_token",
              "lm_head.weight",
              "lm_head.bias",
              "norm.weight",
              "norm.bias",
          ):
              if k == "norm.weight" or k == "norm.bias":
                  # try moving norm -> fc norm on fine-tune, probably a better starting point than new init
                  k = k.replace("norm", "fc_norm")
              else:
                  # skip pretrain mask token & head weights
                  continue
  
          out_dict[k] = v
  
      return out_dict
  
imports: import math
  from typing import Callable, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.utils.checkpoint import checkpoint
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, OPENAI_CLIP_MEAN, OPENAI_CLIP_STD
  from timm.layers import PatchEmbed, Mlp, GluMlp, SwiGLU, LayerNorm, DropPath, PatchDropout, RotaryEmbeddingCat, apply_rot_embed_cat, apply_keep_indices_nlc, trunc_normal_, resample_patch_embed, resample_abs_pos_embed, to_2tuple, use_fused_attn
  from ._builder import build_model_with_cfg
  from ._registry import generate_default_cfgs, register_model
label_desc: Use image node_id 1 for calling a global function with example usage: checkpoint_filter_fn(state_dict, model, interpolation, antialias) and returns: out_dict