class_docstr: Base class for Autoencoder based models.
  
  Args:
      model_config (BaseAEConfig): An instance of BaseAEConfig in which any model's parameters is
          made available.
  
      encoder (BaseEncoder): An instance of BaseEncoder (inheriting from `torch.nn.Module` which
          plays the role of encoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
      decoder (BaseDecoder): An instance of BaseDecoder (inheriting from `torch.nn.Module` which
          plays the role of decoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
  .. note::
      For high dimensional data we advice you to provide you own network architectures. With the
      provided MLP you may end up with a ``MemoryError``.
class_docstr_tok: ["Base","class","for","Autoencoder","based","models",".","Args",":","model_config","(","BaseAEConfig",")",":","An","instance","of","BaseAEConfig","in","which","any","model","'s","parameters","is","made","available",".","encoder","(","BaseEncoder",")",":","An","instance","of","BaseEncoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","encoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","decoder","(","BaseDecoder",")",":","An","instance","of","BaseDecoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","decoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","..","note",":",":","For","high","dimensional","data","we","advice","you","to","provide","you","own","network","architectures",".","With","the","provided","MLP","you","may","end","up","with","a","``","MemoryError","``","."]
docstr: Class method to be used to load a pretrained model from the Hugging Face hub
  
  Args:
      hf_hub_path (str): The path where the model should have been be saved on the
          hugginface hub.
  
  .. note::
      This function requires the folder to contain:
  
      - | a ``model_config.json`` and a ``model.pt`` if no custom architectures were provided
  
      **or**
  
      - | a ``model_config.json``, a ``model.pt`` and a ``encoder.pkl`` (resp.
          ``decoder.pkl``) if a custom encoder (resp. decoder) was provided
docstr_tok: ["Class","method","to","be","used","to","load","a","pretrained","model","from","the","Hugging","Face","hub","Args",":","hf_hub_path","(","str",")",":","The","path","where","the","model","should","have","been","be","saved","on","the","hugginface","hub",".","..","note",":",":","This","function","requires","the","folder","to","contain",":","-","|","a","``","model_config.json","``","and","a","``","model.pt","``","if","no","custom","architectures","were","provided","*","*","or","*","*","-","|","a","``","model_config.json","``",",","a","``","model.pt","``","and","a","``","encoder.pkl","``","(","resp",".","``","decoder.pkl","``",")","if","a","custom","encoder","(","resp",".","decoder",")","was","provided"]
code: def load_from_hf_hub(
      cls, hf_hub_path: str, allow_pickle=False
  ):  # pragma: no cover
      """Class method to be used to load a pretrained model from the Hugging Face hub
  
      Args:
          hf_hub_path (str): The path where the model should have been be saved on the
              hugginface hub.
  
      .. note::
          This function requires the folder to contain:
  
          - | a ``model_config.json`` and a ``model.pt`` if no custom architectures were provided
  
          **or**
  
          - | a ``model_config.json``, a ``model.pt`` and a ``encoder.pkl`` (resp.
              ``decoder.pkl``) if a custom encoder (resp. decoder) was provided
      """
  
      if not hf_hub_is_available():
          raise ModuleNotFoundError(
              "`huggingface_hub` package must be installed to load models from the HF hub. "
              "Run `python -m pip install huggingface_hub` and log in to your account with "
              "`huggingface-cli login`."
          )
  
      else:
          from huggingface_hub import hf_hub_download
  
      logger.info(f"Downloading {cls.__name__} files for rebuilding...")
  
      _ = hf_hub_download(
          repo_id=hf_hub_path, filename="environment.json"
      )
      config_path = hf_hub_download(
          repo_id=hf_hub_path, filename="model_config.json"
      )
      dir_path = os.path.dirname(config_path)
  
      _ = hf_hub_download(repo_id=hf_hub_path, filename="model.pt")
  
      model_config = cls._load_model_config_from_folder(dir_path)
  
      if (
          cls.__name__ + "Config" != model_config.name
          and cls.__name__ + "_Config" != model_config.name
      ):
          warnings.warn(
              f"You are trying to load a "
              f"`{ cls.__name__}` while a "
              f"`{model_config.name}` is given."
          )
  
      model_weights = cls._load_model_weights_from_folder(dir_path)
  
      if (
          not model_config.uses_default_encoder
          or not model_config.uses_default_decoder
      ) and not allow_pickle:
          warnings.warn(
              "You are about to download pickled files from the HF hub that may have "
              "been created by a third party and so could potentially harm your computer. If you "
              "are sure that you want to download them set `allow_pickle=true`."
          )
  
      else:
          if not model_config.uses_default_encoder:
              _ = hf_hub_download(
                  repo_id=hf_hub_path, filename="encoder.pkl"
              )
              encoder = cls._load_custom_encoder_from_folder(dir_path)
  
          else:
              encoder = None
  
          if not model_config.uses_default_decoder:
              _ = hf_hub_download(
                  repo_id=hf_hub_path, filename="decoder.pkl"
              )
              decoder = cls._load_custom_decoder_from_folder(dir_path)
  
          else:
              decoder = None
  
          logger.info(f"Successfully downloaded {cls.__name__} model!")
  
          model = cls(model_config, encoder=encoder, decoder=decoder)
          model.load_state_dict(model_weights)
  
          return model
  
imports: import inspect
  import logging
  import os
  import shutil
  import sys
  import tempfile
  import warnings
  from copy import deepcopy
  from http.cookiejar import LoadError
  from typing import Optional
  import cloudpickle
  import torch
  import torch.nn
  from ...customexception import BadInheritanceError
  from ...data.datasets import BaseDataset, DatasetOutput
  from ..auto_model import AutoConfig
  from ..nn import BaseDecoder, BaseEncoder
  from ..nn.default_architectures import Decoder_AE_MLP
  from .base_config import BaseAEConfig, EnvironmentConfig
  from .base_utils import CPU_Unpickler, ModelOutput, hf_hub_is_available, model_card_template
label_desc: Use image node_id 15 for calling the BaseAE obj's underlying member method code with example usage: obj.load_from_hf_hub(cls, hf_hub_path, allow_pickle) and returns: model