class_docstr: Takes a trained model and makes predictions on new data.
  
  This is a base class which handles some common boilerplate.
  It intentionally has an interface similar to ``Brain`` - these base
  classes handle similar things.
  
  Subclasses of Pretrained should implement the actual logic of how
  the pretrained system runs, and add methods with descriptive names
  (e.g. transcribe_file() for ASR).
  
  Pretrained is a torch.nn.Module so that methods like .to() or .eval() can
  work. Subclasses should provide a suitable forward() implementation: by
  convention, it should be a method that takes a batch of audio signals and
  runs the full model (as applicable).
  
  Arguments
  ---------
  modules : dict of str:torch.nn.Module pairs
      The Torch modules that make up the learned system. These can be treated
      in special ways (put on the right device, frozen, etc.). These are available
      as attributes under ``self.mods``, like self.mods.model(x)
  hparams : dict
      Each key:value pair should consist of a string key and a hyperparameter
      that is used within the overridden methods. These will
      be accessible via an ``hparams`` attribute, using "dot" notation:
      e.g., self.hparams.model(x).
  run_opts : dict
      Options parsed from command line. See ``speechbrain.parse_arguments()``.
      List that are supported here:
       * device
       * data_parallel_count
       * data_parallel_backend
       * distributed_launch
       * distributed_backend
       * jit
       * jit_module_keys
       * compule
       * compile_module_keys
       * compile_mode
       * compile_using_fullgraph
       * compile_using_dynamic_shape_tracing
  freeze_params : bool
      To freeze (requires_grad=False) parameters or not. Normally in inference
      you want to freeze the params. Also calls .eval() on all modules.
class_docstr_tok: ["Takes","a","trained","model","and","makes","predictions","on","new","data",".","This","is","a","base","class","which","handles","some","common","boilerplate",".","It","intentionally","has","an","interface","similar","to","``","Brain","``","-","these","base","classes","handle","similar","things",".","Subclasses","of","Pretrained","should","implement","the","actual","logic","of","how","the","pretrained","system","runs",",","and","add","methods","with","descriptive","names","(","e.g",".","transcribe_file","(",")","for","ASR",")",".","Pretrained","is","a","torch.nn.Module","so","that","methods","like",".to","(",")","or",".eval","(",")","can","work",".","Subclasses","should","provide","a","suitable","forward","(",")","implementation",":","by","convention",",","it","should","be","a","method","that","takes","a","batch","of","audio","signals","and","runs","the","full","model","(","as","applicable",")",".","Arguments","--","--","--","--","-","modules",":","dict","of","str",":","torch.nn.Module","pairs","The","Torch","modules","that","make","up","the","learned","system",".","These","can","be","treated","in","special","ways","(","put","on","the","right","device",",","frozen",",","etc.",")",".","These","are","available","as","attributes","under","``","self.mods","``",",","like","self.mods.model","(","x",")","hparams",":","dict","Each","key",":","value","pair","should","consist","of","a","string","key","and","a","hyperparameter","that","is","used","within","the","overridden","methods",".","These","will","be","accessible","via","an","``","hparams","``","attribute",",","using","``","dot","''","notation",":","e.g.",",","self.hparams.model","(","x",")",".","run_opts",":","dict","Options","parsed","from","command","line",".","See","``","speechbrain.parse_arguments","(",")","``",".","List","that","are","supported","here",":","*","device","*","data_parallel_count","*","data_parallel_backend","*","distributed_launch","*","distributed_backend","*","jit","*","jit_module_keys","*","compule","*","compile_module_keys","*","compile_mode","*","compile_using_fullgraph","*","compile_using_dynamic_shape_tracing","freeze_params",":","bool","To","freeze","(","requires_grad=False",")","parameters","or","not",".","Normally","in","inference","you","want","to","freeze","the","params",".","Also","calls",".eval","(",")","on","all","modules","."]
docstr: Fetch and load based from outside source based on HyperPyYAML file
  
  The source can be a location on the filesystem or online/huggingface
  
  You can use the pymodule_file to include any custom implementations
  that are needed: if that file exists, then its location is added to
  sys.path before Hyperparams YAML is loaded, so it can be referenced
  in the YAML.
  
  The hyperparams file should contain a "modules" key, which is a
  dictionary of torch modules used for computation.
  
  The hyperparams file should contain a "pretrainer" key, which is a
  speechbrain.utils.parameter_transfer.Pretrainer
  
  Arguments
  ---------
  source : str
      The location to use for finding the model. See
      ``speechbrain.pretrained.fetching.fetch`` for details.
  hparams_file : str
      The name of the hyperparameters file to use for constructing
      the modules necessary for inference. Must contain two keys:
      "modules" and "pretrainer", as described.
  pymodule_file : str
      A Python file can be fetched. This allows any custom
      implementations to be included. The file's location is added to
      sys.path before the hyperparams YAML file is loaded, so it can be
      referenced in YAML.
      This is optional, but has a default: "custom.py". If the default
      file is not found, this is simply ignored, but if you give a
      different filename, then this will raise in case the file is not
      found.
  overrides : dict
      Any changes to make to the hparams file when it is loaded.
  savedir : str or Path
      Where to put the pretraining material. If not given, will use
      ./pretrained_models/<class-name>-hash(source).
  use_auth_token : bool (default: False)
      If true Hugginface's auth_token will be used to load private models from the HuggingFace Hub,
      default is False because the majority of models are public.
  revision : str
      The model revision corresponding to the HuggingFace Hub model revision.
      This is particularly useful if you wish to pin your code to a particular
      version of a model hosted at HuggingFace.
  download_only : bool (default: False)
      If true, class and instance creation is skipped.
  revision : str
      The model revision corresponding to the HuggingFace Hub model revision.
      This is particularly useful if you wish to pin your code to a particular
      version of a model hosted at HuggingFace.
  huggingface_cache_dir : str
      Path to HuggingFace cache; if None -> "~/.cache/huggingface" (default: None)
code: def from_hparams(
      cls,
      source,
      hparams_file="hyperparams.yaml",
      pymodule_file="custom.py",
      overrides={},
      savedir=None,
      use_auth_token=False,
      revision=None,
      download_only=False,
      huggingface_cache_dir=None,
      **kwargs,
  ):
      """Fetch and load based from outside source based on HyperPyYAML file
  
      The source can be a location on the filesystem or online/huggingface
  
      You can use the pymodule_file to include any custom implementations
      that are needed: if that file exists, then its location is added to
      sys.path before Hyperparams YAML is loaded, so it can be referenced
      in the YAML.
  
      The hyperparams file should contain a "modules" key, which is a
      dictionary of torch modules used for computation.
  
      The hyperparams file should contain a "pretrainer" key, which is a
      speechbrain.utils.parameter_transfer.Pretrainer
  
      Arguments
      ---------
      source : str
          The location to use for finding the model. See
          ``speechbrain.pretrained.fetching.fetch`` for details.
      hparams_file : str
          The name of the hyperparameters file to use for constructing
          the modules necessary for inference. Must contain two keys:
          "modules" and "pretrainer", as described.
      pymodule_file : str
          A Python file can be fetched. This allows any custom
          implementations to be included. The file's location is added to
          sys.path before the hyperparams YAML file is loaded, so it can be
          referenced in YAML.
          This is optional, but has a default: "custom.py". If the default
          file is not found, this is simply ignored, but if you give a
          different filename, then this will raise in case the file is not
          found.
      overrides : dict
          Any changes to make to the hparams file when it is loaded.
      savedir : str or Path
          Where to put the pretraining material. If not given, will use
          ./pretrained_models/<class-name>-hash(source).
      use_auth_token : bool (default: False)
          If true Hugginface's auth_token will be used to load private models from the HuggingFace Hub,
          default is False because the majority of models are public.
      revision : str
          The model revision corresponding to the HuggingFace Hub model revision.
          This is particularly useful if you wish to pin your code to a particular
          version of a model hosted at HuggingFace.
      download_only : bool (default: False)
          If true, class and instance creation is skipped.
      revision : str
          The model revision corresponding to the HuggingFace Hub model revision.
          This is particularly useful if you wish to pin your code to a particular
          version of a model hosted at HuggingFace.
      huggingface_cache_dir : str
          Path to HuggingFace cache; if None -> "~/.cache/huggingface" (default: None)
      """
      if savedir is None:
          clsname = cls.__name__
          savedir = f"./pretrained_models/{clsname}-{hashlib.md5(source.encode('UTF-8', errors='replace')).hexdigest()}"
      hparams_local_path = fetch(
          filename=hparams_file,
          source=source,
          savedir=savedir,
          overwrite=False,
          save_filename=None,
          use_auth_token=use_auth_token,
          revision=revision,
          huggingface_cache_dir=huggingface_cache_dir,
      )
      try:
          pymodule_local_path = fetch(
              filename=pymodule_file,
              source=source,
              savedir=savedir,
              overwrite=False,
              save_filename=None,
              use_auth_token=use_auth_token,
              revision=revision,
              huggingface_cache_dir=huggingface_cache_dir,
          )
          sys.path.append(str(pymodule_local_path.parent))
      except ValueError:
          if pymodule_file == "custom.py":
              # The optional custom Python module file did not exist
              # and had the default name
              pass
          else:
              # Custom Python module file not found, but some other
              # filename than the default was given.
              raise
  
      # Load the modules:
      with open(hparams_local_path) as fin:
          hparams = load_hyperpyyaml(fin, overrides)
  
      # Pretraining:
      pretrainer = hparams["pretrainer"]
      pretrainer.set_collect_in(savedir)
      # For distributed setups, have this here:
      run_on_main(
          pretrainer.collect_files, kwargs={"default_source": source}
      )
      # Load on the CPU. Later the params can be moved elsewhere by specifying
      if not download_only:
          # run_opts={"device": ...}
          pretrainer.load_collected()
  
          # Now return the system
          return cls(hparams["modules"], hparams, **kwargs)
  
imports: import logging
  import hashlib
  import sys
  import warnings
  import torch
  import torchaudio
  from types import SimpleNamespace
  from torch.nn import SyncBatchNorm
  from torch.nn import DataParallel
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.fetching import fetch
  from speechbrain.dataio.preprocess import AudioNormalizer
  from torch.nn.parallel import DistributedDataParallel
  from speechbrain.utils.data_utils import split_path
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.dataio.batch import PaddedBatch, PaddedData
  from speechbrain.utils.data_pipeline import DataPipeline
  from speechbrain.utils.superpowers import import_from_path
label_desc: Use image node_id 7 for calling the Pretrained obj's underlying member method code with example usage: obj.from_hparams(cls, source, hparams_file, pymodule_file, overrides, savedir, use_auth_token, revision, download_only, huggingface_cache_dir) and returns: cls