code: def checkpoint_filter_fn(state_dict, model):
      """Remap FB checkpoints -> timm"""
      if (
          "head.norm.weight" in state_dict
          or "norm_pre.weight" in state_dict
      ):
          return state_dict  # non-FB checkpoint
  
      # models were released as train checkpoints... :/
      if "model_ema" in state_dict:
          state_dict = state_dict["model_ema"]
      elif "model" in state_dict:
          state_dict = state_dict["model"]
      elif "state_dict" in state_dict:
          state_dict = state_dict["state_dict"]
  
      out_dict = {}
      import re
  
      for k, v in state_dict.items():
          k = k.replace("downsample_layers.0.", "stem.")
          k = re.sub(
              r"stages.([0-9]+).([0-9]+)", r"stages.\1.blocks.\2", k
          )
          k = re.sub(
              r"downsample_layers.([0-9]+).([0-9]+)",
              r"stages.\1.downsample.\2",
              k,
          )
          k = k.replace("dwconv", "conv_dw")
          k = k.replace("pwconv", "mlp.fc")
          k = k.replace("head.", "head.fc.")
          if k.startswith("norm."):
              k = k.replace("norm", "head.norm")
          if v.ndim == 2 and "head" not in k:
              model_shape = model.state_dict()[k].shape
              v = v.reshape(model_shape)
          out_dict[k] = v
      return out_dict
  
imports: import math
  from collections import OrderedDict
  from functools import partial
  from typing import Tuple
  import torch
  import torch.nn.functional
  from torch import nn
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import trunc_normal_tf_, DropPath, LayerNorm2d, Mlp, SelectAdaptivePool2d, create_conv2d, use_fused_attn, NormMlpClassifierHead, ClassifierHead
  from ._builder import build_model_with_cfg
  from ._features_fx import register_notrace_module
  from ._manipulate import named_apply, checkpoint_seq
  from ._registry import register_model, generate_default_cfgs
label_desc: Use image node_id 2 for calling a global function with example usage: checkpoint_filter_fn(state_dict, model) and returns: out_dict, state_dict