code: def save_config_for_hf(
      model,
      config_path: str,
      model_config: Optional[dict] = None,
      model_args: Optional[dict] = None,
  ):
      model_config = model_config or {}
      hf_config = {}
      pretrained_cfg = filter_pretrained_cfg(
          model.pretrained_cfg, remove_source=True, remove_null=True
      )
      # set some values at root config level
      hf_config["architecture"] = pretrained_cfg.pop("architecture")
      hf_config["num_classes"] = model_config.pop(
          "num_classes", model.num_classes
      )
  
      # NOTE these attr saved for informational purposes, do not impact model build
      hf_config["num_features"] = model_config.pop(
          "num_features", model.num_features
      )
      global_pool_type = model_config.pop(
          "global_pool", getattr(model, "global_pool", None)
      )
      if isinstance(global_pool_type, str) and global_pool_type:
          hf_config["global_pool"] = global_pool_type
  
      # Save class label info
      if "labels" in model_config:
          _logger.warning(
              "'labels' as a config field for is deprecated. Please use 'label_names' and 'label_descriptions'."
              " Renaming provided 'labels' field to 'label_names'."
          )
          model_config.setdefault(
              "label_names", model_config.pop("labels")
          )
  
      label_names = model_config.pop("label_names", None)
      if label_names:
          assert isinstance(label_names, (dict, list, tuple))
          # map label id (classifier index) -> unique label name (ie synset for ImageNet, MID for OpenImages)
          # can be a dict id: name if there are id gaps, or tuple/list if no gaps.
          hf_config["label_names"] = label_names
  
      label_descriptions = model_config.pop("label_descriptions", None)
      if label_descriptions:
          assert isinstance(label_descriptions, dict)
          # maps label names -> descriptions
          hf_config["label_descriptions"] = label_descriptions
  
      if model_args:
          hf_config["model_args"] = model_args
  
      hf_config["pretrained_cfg"] = pretrained_cfg
      hf_config.update(model_config)
  
      with config_path.open("w") as f:
          json.dump(hf_config, f, indent=2)
  
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 10 for calling a global function with example usage: save_config_for_hf(model, config_path, model_config, model_args) without return types