docstr: Returns:
      `OptimizedModel`: The loaded optimized model.
docstr_tok: ["Returns",":","`","OptimizedModel","`",":","The","loaded","optimized","model","."]
code: def from_pretrained(
      cls,
      model_id: Union[str, Path],
      export: bool = False,
      force_download: bool = False,
      use_auth_token: Optional[str] = None,
      cache_dir: Optional[str] = None,
      subfolder: str = "",
      config: Optional[PretrainedConfig] = None,
      local_files_only: bool = False,
      trust_remote_code: bool = False,
      revision: Optional[str] = None,
      **kwargs,
  ) -> "OptimizedModel":
      """
      Returns:
          `OptimizedModel`: The loaded optimized model.
      """
      if isinstance(model_id, Path):
          model_id = model_id.as_posix()
  
      from_transformers = kwargs.pop("from_transformers", None)
      if from_transformers is not None:
          logger.warning(
              "The argument `from_transformers` is deprecated, and will be removed in optimum 2.0.  Use `export` instead"
          )
          export = from_transformers
  
      if len(model_id.split("@")) == 2:
          if revision is not None:
              logger.warning(
                  f"The argument `revision` was set to {revision} but will be ignored for {model_id.split('@')[1]}"
              )
          model_id, revision = model_id.split("@")
  
      library_name = TasksManager.infer_library_from_model(
          model_id, subfolder, revision, cache_dir
      )
  
      if library_name == "timm":
          config = PretrainedConfig.from_pretrained(
              model_id, subfolder, revision
          )
  
      if config is None:
          if (
              os.path.isdir(os.path.join(model_id, subfolder))
              and cls.config_name == CONFIG_NAME
          ):
              if CONFIG_NAME in os.listdir(
                  os.path.join(model_id, subfolder)
              ):
                  config = AutoConfig.from_pretrained(
                      os.path.join(model_id, subfolder, CONFIG_NAME),
                      trust_remote_code=trust_remote_code,
                  )
              elif CONFIG_NAME in os.listdir(model_id):
                  config = AutoConfig.from_pretrained(
                      os.path.join(model_id, CONFIG_NAME),
                      trust_remote_code=trust_remote_code,
                  )
                  logger.info(
                      f"config.json not found in the specified subfolder {subfolder}. Using the top level config.json."
                  )
              else:
                  raise OSError(
                      f"config.json not found in {model_id} local folder"
                  )
          else:
              config = cls._load_config(
                  model_id,
                  revision=revision,
                  cache_dir=cache_dir,
                  use_auth_token=use_auth_token,
                  force_download=force_download,
                  subfolder=subfolder,
                  trust_remote_code=trust_remote_code,
              )
      elif isinstance(config, (str, os.PathLike)):
          config = cls._load_config(
              config,
              revision=revision,
              cache_dir=cache_dir,
              use_auth_token=use_auth_token,
              force_download=force_download,
              subfolder=subfolder,
              trust_remote_code=trust_remote_code,
          )
  
      if not export and trust_remote_code:
          logger.warning(
              "The argument `trust_remote_code` is to be used along with export=True. It will be ignored."
          )
      elif export and trust_remote_code is None:
          trust_remote_code = False
  
      from_pretrained_method = (
          cls._from_transformers if export else cls._from_pretrained
      )
  
      return from_pretrained_method(
          model_id=model_id,
          config=config,
          revision=revision,
          cache_dir=cache_dir,
          force_download=force_download,
          use_auth_token=use_auth_token,
          subfolder=subfolder,
          local_files_only=local_files_only,
          trust_remote_code=trust_remote_code,
          **kwargs,
      )
  
imports: import logging
  import os
  import subprocess
  from abc import ABC, abstractmethod
  from pathlib import Path
  from typing import TYPE_CHECKING, Optional, Union
  from huggingface_hub import HfApi, HfFolder
  from transformers import AutoConfig, PretrainedConfig, add_start_docstrings
  from .exporters import TasksManager
  from .utils import CONFIG_NAME
label_desc: Use image node_id 13 for calling the OptimizedModel obj's underlying member method code with example usage: obj.from_pretrained(cls, model_id, export, force_download, use_auth_token, cache_dir, subfolder, config, local_files_only, trust_remote_code, revision) and returns: from_pretrained_method