code: def _load_pretrained(model: TinyViT, url: str) -> TinyViT:
      model_state_dict = model.state_dict()
      state_dict = torch.hub.load_state_dict_from_url(url)
  
      # official checkpoint has "model" key
      if "model" in state_dict:
          state_dict = state_dict["model"]
  
      # https://github.com/microsoft/Cream/blob/8dc38822b99fff8c262c585a32a4f09ac504d693/TinyViT/utils.py#L163
      # bicubic interpolate attention biases
      ab_keys = [
          k for k in state_dict.keys() if "attention_biases" in k
      ]
      for k in ab_keys:
          n_heads1, L1 = state_dict[k].shape
          n_heads2, L2 = model_state_dict[k].shape
          KORNIA_CHECK(
              n_heads1 == n_heads2,
              f"Fail to load {k}. Pre-trained checkpoint should have num_heads={n_heads1}",
          )
  
          if L1 != L2:
              S1 = int(L1**0.5)
              S2 = int(L2**0.5)
              attention_biases = state_dict[k].view(1, n_heads1, S1, S1)
              attention_biases = F.interpolate(
                  attention_biases, size=(S2, S2), mode="bicubic"
              )
              state_dict[k] = attention_biases.view(n_heads2, L2)
  
      if state_dict["head.weight"].shape[0] != model.head.out_features:
          msg = "Number of classes does not match pre-trained checkpoint's. Resetting classification head to zeros"
          warnings.warn(msg)
          state_dict["head.weight"] = torch.zeros_like(
              model.head.weight
          )
          state_dict["head.bias"] = torch.zeros_like(model.head.bias)
  
      model.load_state_dict(state_dict)
      return model
  
imports: from __future__ import annotations
  import itertools
  import warnings
  from typing import Any, Optional
  import torch
  import torch.nn.functional
  from torch import nn
  from torch.utils import checkpoint
  from kornia.contrib.models.common import DropPath, LayerNorm2d, window_partition, window_unpartition
  from kornia.core import Module, Tensor
  from kornia.core.check import KORNIA_CHECK
label_desc: Use image node_id 2 for calling a global function with example usage: _load_pretrained(model, url) and returns: model