class_docstr: Variational Autoencoder using Adversarial reconstruction loss model.
  
  Args:
      model_config (VAEGANConfig): The Autoencoder configuration setting the main
          parameters of the model.
  
      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.
  
      discriminator (BaseDiscriminator): An instance of BaseDiscriminator (inheriting from
          `torch.nn.Module` which plays the role of discriminator. 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: ["Variational","Autoencoder","using","Adversarial","reconstruction","loss","model",".","Args",":","model_config","(","VAEGANConfig",")",":","The","Autoencoder","configuration","setting","the","main","parameters","of","the","model",".","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",".","discriminator","(","BaseDiscriminator",")",":","An","instance","of","BaseDiscriminator","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","discriminator",".","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`` and ``discriminator``) if a custom encoder (resp. decoder and/or
          discriminator) 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","``","and","``","discriminator","``",")","if","a","custom","encoder","(","resp",".","decoder","and\/or","discriminator",")","was","provided"]
code: def load_from_hf_hub(
      cls, hf_hub_path: str, allow_pickle: bool = 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`` and ``discriminator``) if a custom encoder (resp. decoder and/or
              discriminator) 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...")
  
      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
          or not model_config.uses_default_discriminator
      ) 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
  
          if not model_config.uses_default_discriminator:
              _ = hf_hub_download(
                  repo_id=hf_hub_path, filename="discriminator.pkl"
              )
              discriminator = (
                  cls._load_custom_discriminator_from_folder(dir_path)
              )
  
          else:
              discriminator = None
  
          logger.info(f"Successfully downloaded {cls.__name__} model!")
  
          model = cls(
              model_config,
              encoder=encoder,
              decoder=decoder,
              discriminator=discriminator,
          )
          model.load_state_dict(model_weights)
  
          return model
  
imports: import inspect
  import logging
  import os
  import warnings
  from copy import deepcopy
  from typing import Optional
  import cloudpickle
  import torch
  import torch.nn.functional
  from ...customexception import BadInheritanceError
  from ...data.datasets import BaseDataset
  from ..base.base_utils import CPU_Unpickler, ModelOutput, hf_hub_is_available
  from ..nn import BaseDecoder, BaseDiscriminator, BaseEncoder
  from ..nn.default_architectures import Discriminator_MLP
  from ..vae import VAE
  from .vae_gan_config import VAEGANConfig
label_desc: Use image node_id 9 for calling the VAEGAN obj's underlying member method code with example usage: obj.load_from_hf_hub(cls, hf_hub_path, allow_pickle) and returns: model