code: def load_state_dict_from_hf(
      model_id: str, filename: str = HF_WEIGHTS_NAME
  ):
      assert has_hf_hub(True)
      hf_model_id, hf_revision = hf_split(model_id)
  
      # Look for .safetensors alternatives and load from it if it exists
      if _has_safetensors:
          for safe_filename in _get_safe_alternatives(filename):
              try:
                  cached_safe_file = hf_hub_download(
                      repo_id=hf_model_id,
                      filename=safe_filename,
                      revision=hf_revision,
                  )
                  _logger.info(
                      f"[{model_id}] Safe alternative available for '{filename}' "
                      f"(as '{safe_filename}'). Loading weights using safetensors."
                  )
                  return safetensors.torch.load_file(
                      cached_safe_file, device="cpu"
                  )
              except EntryNotFoundError:
                  pass
  
      # Otherwise, load using pytorch.load
      cached_file = hf_hub_download(
          hf_model_id, filename=filename, revision=hf_revision
      )
      _logger.debug(
          f"[{model_id}] Safe alternative not found for '{filename}'. Loading weights using default pytorch."
      )
      return torch.load(cached_file, map_location="cpu")
  
imports: import hashlib
  import json
  import logging
  import os
  from functools import partial
  from pathlib import Path
  from tempfile import TemporaryDirectory
  from typing import Iterable, Optional, Union
  import torch
  from torch.hub import HASH_REGEX, download_url_to_file, urlparse
  from timm import __version__
  from timm.models._pretrained import filter_pretrained_cfg
label_desc: Use image node_id 9 for calling a global function with example usage: load_state_dict_from_hf(model_id, filename) and returns: torch, safetensors