




import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase_					    = logging.get_logger(__name__)

lowerCAmelCase_					    = {
    """xlnet-base-cased""": """https://huggingface.co/xlnet-base-cased/resolve/main/config.json""",
    """xlnet-large-cased""": """https://huggingface.co/xlnet-large-cased/resolve/main/config.json""",
}






class  _lowerCAmelCase     (  _lowercase	):
      A__		     =		'xlnet'
      A__		     =		['mems']
      A__		     =		{
          'n_token': 'vocab_size',  # Backward compatibility
          'hidden_size': 'd_model',
          'num_attention_heads': 'n_head',
          'num_hidden_layers': 'n_layer',
      }

      def __init__(   self      ,				__UpperCAmelCase=3_2000      ,				__UpperCAmelCase=1024      ,				__UpperCAmelCase=24      ,				__UpperCAmelCase=16      ,				__UpperCAmelCase=4096      ,				__UpperCAmelCase="gelu"      ,				__UpperCAmelCase=True      ,				__UpperCAmelCase="bi"      ,				__UpperCAmelCase=0.02      ,				__UpperCAmelCase=1e-12      ,				__UpperCAmelCase=0.1      ,				__UpperCAmelCase=512      ,				__UpperCAmelCase=None      ,				__UpperCAmelCase=True      ,				__UpperCAmelCase=False      ,				__UpperCAmelCase=False      ,				__UpperCAmelCase=-1      ,				__UpperCAmelCase=False      ,				__UpperCAmelCase="last"      ,				__UpperCAmelCase=True      ,				__UpperCAmelCase="tanh"      ,				__UpperCAmelCase=0.1      ,				__UpperCAmelCase=5      ,				__UpperCAmelCase=5      ,				__UpperCAmelCase=5      ,				__UpperCAmelCase=1      ,				__UpperCAmelCase=2      ,				**__UpperCAmelCase      ,				):
        lowerCAmelCase__				:  Optional[int]		       =     vocab_size
        lowerCAmelCase__				:  List[Any]		       =     d_model
        lowerCAmelCase__				:  Union[str, Any]		       =     n_layer
        lowerCAmelCase__				:  Any		       =     n_head
        if d_model % n_head != 0:
          raise ValueError(f"""'d_model % n_head' ({d_model % n_head}) should be equal to 0"""		)
        if "d_head" in kwargs:
          if kwargs["d_head"] != d_model // n_head:
            raise ValueError(
                f"""`d_head` ({kwargs["d_head"]}) should be equal to `d_model // n_head` ({d_model // n_head})"""		)
        lowerCAmelCase__				:  Any		       =     d_model // n_head
        lowerCAmelCase__				:  str		       =     ff_activation
        lowerCAmelCase__				:  Any		       =     d_inner
        lowerCAmelCase__				:  List[Any]		       =     untie_r
        lowerCAmelCase__				:  str		       =     attn_type

        lowerCAmelCase__				:  Optional[Any]		       =     initializer_range
        lowerCAmelCase__				:  str		       =     layer_norm_eps

        lowerCAmelCase__				:  List[str]		       =     dropout
        lowerCAmelCase__				:  Any		       =     mem_len
        lowerCAmelCase__				:  Union[str, Any]		       =     reuse_len
        lowerCAmelCase__				:  List[Any]		       =     bi_data
        lowerCAmelCase__				:  Dict		       =     clamp_len
        lowerCAmelCase__				:  int		       =     same_length

        lowerCAmelCase__				:  Optional[Any]		       =     summary_type
        lowerCAmelCase__				:  Optional[int]		       =     summary_use_proj
        lowerCAmelCase__				:  Dict		       =     summary_activation
        lowerCAmelCase__				:  List[Any]		       =     summary_last_dropout
        lowerCAmelCase__				:  int		       =     start_n_top
        lowerCAmelCase__				:  List[Any]		       =     end_n_top

        lowerCAmelCase__				:  int		       =     bos_token_id
        lowerCAmelCase__				:  Dict		       =     pad_token_id
        lowerCAmelCase__				:  List[str]		       =     eos_token_id

        if "use_cache" in kwargs:
          warnings.warn(
              '''The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'''
              ''' instead.'''      ,				__UpperCAmelCase      ,				)
          lowerCAmelCase__				:  Optional[int]		       =     kwargs['''use_cache''']

        lowerCAmelCase__				:  str		       =     use_mems_eval
        lowerCAmelCase__				:  Union[str, Any]		       =     use_mems_train
        super().__init__(pad_token_id=__UpperCAmelCase      ,				bos_token_id=__UpperCAmelCase      ,				eos_token_id=__UpperCAmelCase      ,				**__UpperCAmelCase		)

      @property
      def 	__magic_name__(   self		):
        logger.info(f"""The model {self.model_type} is one of the few models that has no sequence length limit."""		)
        return -1







      @max_position_embeddings.setter
      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        # Message copied from Transformer-XL documentation
        raise NotImplementedError(
            f"""The model {self.model_type} is one of the few models that has no sequence length limit."""		)







from datetime import datetime

import matplotlib.pyplot as plt
import torch



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	str:
  for param in module.parameters():
    lowerCAmelCase__				:  int		       =     False



def      __lowerCAmelCase			(					)     ->	Optional[Any]:
  lowerCAmelCase__				:  List[Any]		       =     '''cuda''' if torch.cuda.is_available() else '''cpu'''
  if torch.backends.mps.is_available() and torch.backends.mps.is_built():
    lowerCAmelCase__				:  Optional[Any]		       =     '''mps'''
  if device == "mps":
    print(
        '''WARNING: MPS currently doesn\'t seem to work, and messes up backpropagation without any visible torch'''
        ''' errors. I recommend using CUDA on a colab notebook or CPU instead if you\'re facing inexplicable issues'''
        ''' with generations.'''      )
  return device



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	List[Any]:
  lowerCAmelCase__				:  str		       =     plt.imshow(UpperCamelCase      )
  fig.axes.get_xaxis().set_visible(UpperCamelCase      )
  fig.axes.get_yaxis().set_visible(UpperCamelCase      )
  plt.show()



def      __lowerCAmelCase			(					)     ->	str:
  lowerCAmelCase__				:  Dict		       =     datetime.now()
  lowerCAmelCase__				:  Optional[int]		       =     current_time.strftime('''%H:%M:%S'''      )
  return timestamp

