class_docstr: Handles the `task name -> model class` and `architecture -> configuration` mappings.
docstr: Determines the framework to use for the export.
  
  The priority is in the following order:
      1. User input via `framework`.
      2. If local checkpoint is provided, use the same framework as the checkpoint.
      3. If model repo, try to infer the framework from the cache if available, else from the Hub.
      4. If could not infer, use available framework in environment, with priority given to PyTorch.
  
  Args:
      model_name_or_path (`Union[str, Path]`):
          Can be either the model id of a model repo on the Hugging Face Hub, or a path to a local directory
          containing a model.
      subfolder (`str`, defaults to `""`):
          In case the model files are located inside a subfolder of the model directory / repo on the Hugging
          Face Hub, you can specify the subfolder name here.
      framework (`Optional[str]`, *optional*):
          The framework to use for the export. See above for priority if none provided.
  
  Returns:
      `str`: The framework to use for the export.
docstr_tok: ["Determines","the","framework","to","use","for","the","export",".","The","priority","is","in","the","following","order",":","1",".","User","input","via","`","framework","`",".","2",".","If","local","checkpoint","is","provided",",","use","the","same","framework","as","the","checkpoint",".","3",".","If","model","repo",",","try","to","infer","the","framework","from","the","cache","if","available",",","else","from","the","Hub",".","4",".","If","could","not","infer",",","use","available","framework","in","environment",",","with","priority","given","to","PyTorch",".","Args",":","model_name_or_path","(","`","Union","[","str",",","Path","]","`",")",":","Can","be","either","the","model","id","of","a","model","repo","on","the","Hugging","Face","Hub",",","or","a","path","to","a","local","directory","containing","a","model",".","subfolder","(","`","str","`",",","defaults","to","`","``","''","`",")",":","In","case","the","model","files","are","located","inside","a","subfolder","of","the","model","directory","\/","repo","on","the","Hugging","Face","Hub",",","you","can","specify","the","subfolder","name","here",".","framework","(","`","Optional","[","str","]","`",",","*","optional","*",")",":","The","framework","to","use","for","the","export",".","See","above","for","priority","if","none","provided",".","Returns",":","`","str","`",":","The","framework","to","use","for","the","export","."]
code: def determine_framework(
      model_name_or_path: Union[str, Path],
      subfolder: str = "",
      framework: Optional[str] = None,
      cache_dir: str = huggingface_hub.constants.HUGGINGFACE_HUB_CACHE,
  ) -> str:
      """
      Determines the framework to use for the export.
  
      The priority is in the following order:
          1. User input via `framework`.
          2. If local checkpoint is provided, use the same framework as the checkpoint.
          3. If model repo, try to infer the framework from the cache if available, else from the Hub.
          4. If could not infer, use available framework in environment, with priority given to PyTorch.
  
      Args:
          model_name_or_path (`Union[str, Path]`):
              Can be either the model id of a model repo on the Hugging Face Hub, or a path to a local directory
              containing a model.
          subfolder (`str`, defaults to `""`):
              In case the model files are located inside a subfolder of the model directory / repo on the Hugging
              Face Hub, you can specify the subfolder name here.
          framework (`Optional[str]`, *optional*):
              The framework to use for the export. See above for priority if none provided.
  
      Returns:
          `str`: The framework to use for the export.
  
      """
      if framework is not None:
          return framework
  
      all_files, request_exception = TasksManager.get_model_files(
          model_name_or_path, subfolder, cache_dir
      )
  
      pt_weight_name = Path(WEIGHTS_NAME).stem
      pt_weight_extension = Path(WEIGHTS_NAME).suffix
      safe_weight_name = Path(SAFE_WEIGHTS_NAME).stem
      safe_weight_extension = Path(SAFE_WEIGHTS_NAME).suffix
      is_pt_weight_file = [
          (
              file.startswith(pt_weight_name)
              and file.endswith(pt_weight_extension)
          )
          or (
              file.startswith(safe_weight_name)
              and file.endswith(safe_weight_extension)
          )
          for file in all_files
      ]
  
      weight_name = Path(TF2_WEIGHTS_NAME).stem
      weight_extension = Path(TF2_WEIGHTS_NAME).suffix
      is_tf_weight_file = [
          file.startswith(weight_name)
          and file.endswith(weight_extension)
          for file in all_files
      ]
  
      if any(is_pt_weight_file):
          framework = "pt"
      elif any(is_tf_weight_file):
          framework = "tf"
      elif "model_index.json" in all_files and any(
          file.endswith((pt_weight_extension, safe_weight_extension))
          for file in all_files
      ):
          # stable diffusion case
          framework = "pt"
      elif "config_sentence_transformers.json" in all_files:
          # Sentence Transformers libary relies on PyTorch.
          framework = "pt"
      else:
          if request_exception is not None:
              raise RequestsConnectionError(
                  f"The framework could not be automatically inferred. If using the command-line, please provide the argument --framework (pt,tf) Detailed error: {request_exception}"
              )
          else:
              raise FileNotFoundError(
                  "Cannot determine framework from given checkpoint location."
                  f" There should be a {Path(WEIGHTS_NAME).stem}*{Path(WEIGHTS_NAME).suffix} for PyTorch"
                  f" or {Path(TF2_WEIGHTS_NAME).stem}*{Path(TF2_WEIGHTS_NAME).suffix} for TensorFlow."
              )
  
      if is_torch_available():
          framework = framework or "pt"
      elif is_tf_available():
          framework = framework or "tf"
      else:
          raise EnvironmentError(
              "Neither PyTorch nor TensorFlow found in environment. Cannot export model."
          )
  
      logger.info(
          f"Framework not specified. Using {framework} to export the model."
      )
  
      return framework
  
imports: import importlib
  import inspect
  import itertools
  import json
  import os
  from functools import partial
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
  import huggingface_hub
  from packaging import version
  from requests.exceptions import ConnectionError
  from transformers import AutoConfig, PretrainedConfig, is_tf_available, is_torch_available
  from transformers.utils import SAFE_WEIGHTS_NAME, TF2_WEIGHTS_NAME, WEIGHTS_NAME, logging
  from ..utils import CONFIG_NAME
  from ..utils.import_utils import is_onnx_available
label_desc: Use image node_id 9 for calling the TasksManager obj's underlying member method code with example usage: obj.determine_framework(model_name_or_path, subfolder, framework, cache_dir) and returns: framework, framework