code: def checkpoint_filter_fn(state_dict, model: FocalNet):
      state_dict = state_dict.get("model", state_dict)
      if "stem.proj.weight" in state_dict:
          return state_dict
      import re
  
      out_dict = {}
      dest_dict = model.state_dict()
      for k, v in state_dict.items():
          k = re.sub(r"gamma_([0-9])", r"ls\1.gamma", k)
          k = k.replace("patch_embed", "stem")
          k = re.sub(
              r"layers.(\d+).downsample",
              lambda x: f"layers.{int(x.group(1)) + 1}.downsample",
              k,
          )
          if "norm" in k and k not in dest_dict:
              k = re.sub(r"norm([0-9])", r"norm\1_post", k)
          k = k.replace("ln.", "norm.")
          k = k.replace("head", "head.fc")
          if (
              k in dest_dict
              and dest_dict[k].numel() == v.numel()
              and dest_dict[k].shape != v.shape
          ):
              v = v.reshape(dest_dict[k].shape)
          out_dict[k] = v
      return out_dict
  
imports: from functools import partial
  from typing import Callable, Optional, Tuple
  import torch
  import torch.nn
  import torch.utils.checkpoint
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import Mlp, DropPath, LayerNorm2d, trunc_normal_, ClassifierHead, NormMlpClassifierHead
  from ._builder import build_model_with_cfg
  from ._manipulate import named_apply
  from ._registry import generate_default_cfgs, register_model
label_desc: Use image node_id 3 for calling a global function with example usage: checkpoint_filter_fn(state_dict, model) and returns: out_dict, state_dict