import warnings

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


a_							=      logging.get_logger(__name__)

a_							=      {
    """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 			UpperCAmelCase__    (		snake_case					):



  """simple docstring"""






  lowerCAmelCase__		:	str    		= 'xlnet'
  lowerCAmelCase__		:	Tuple    		= ['mems']
  lowerCAmelCase__		:	Any    		= {
      'n_token': 'vocab_size',  # Backward compatibility
      'hidden_size': 'd_model',
      'num_attention_heads': 'n_head',
      'num_hidden_layers': 'n_layer',
  }






  def __init__(				self:			Dict				,				__lowerCAmelCase:			Optional[int]=32_000				,				__lowerCAmelCase:			int=1_024				,				__lowerCAmelCase:			Any=24				,				__lowerCAmelCase:			Dict=16				,				__lowerCAmelCase:			int=4_096				,				__lowerCAmelCase:			str="gelu"				,				__lowerCAmelCase:			Union[str, Any]=True				,				__lowerCAmelCase:			List[Any]="bi"				,				__lowerCAmelCase:			Tuple=0.02				,				__lowerCAmelCase:			str=1E-12				,				__lowerCAmelCase:			Any=0.1				,				__lowerCAmelCase:			Tuple=512				,				__lowerCAmelCase:			Any=None				,				__lowerCAmelCase:			Optional[int]=True				,				__lowerCAmelCase:			Tuple=False				,				__lowerCAmelCase:			Optional[int]=False				,				__lowerCAmelCase:			Any=-1				,				__lowerCAmelCase:			Optional[Any]=False				,				__lowerCAmelCase:			Optional[Any]="last"				,				__lowerCAmelCase:			List[Any]=True				,				__lowerCAmelCase:			Optional[int]="tanh"				,				__lowerCAmelCase:			List[Any]=0.1				,				__lowerCAmelCase:			Tuple=5				,				__lowerCAmelCase:			Optional[Any]=5				,				__lowerCAmelCase:			str=5				,				__lowerCAmelCase:			int=1				,				__lowerCAmelCase:			List[Any]=2				,				**__lowerCAmelCase:			List[Any]				,				) -> Optional[Any]:




    '''simple docstring'''




    __UpperCAmelCase						    =       vocab_size
    __UpperCAmelCase						    =       d_model
    __UpperCAmelCase						    =       n_layer
    __UpperCAmelCase						    =       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})'''   )
    __UpperCAmelCase						    =       d_model // n_head
    __UpperCAmelCase						    =       ff_activation
    __UpperCAmelCase						    =       d_inner
    __UpperCAmelCase						    =       untie_r
    __UpperCAmelCase						    =       attn_type

    __UpperCAmelCase						    =       initializer_range
    __UpperCAmelCase						    =       layer_norm_eps

    __UpperCAmelCase						    =       dropout
    __UpperCAmelCase						    =       mem_len
    __UpperCAmelCase						    =       reuse_len
    __UpperCAmelCase						    =       bi_data
    __UpperCAmelCase						    =       clamp_len
    __UpperCAmelCase						    =       same_length

    __UpperCAmelCase						    =       summary_type
    __UpperCAmelCase						    =       summary_use_proj
    __UpperCAmelCase						    =       summary_activation
    __UpperCAmelCase						    =       summary_last_dropout
    __UpperCAmelCase						    =       start_n_top
    __UpperCAmelCase						    =       end_n_top

    __UpperCAmelCase						    =       bos_token_id
    __UpperCAmelCase						    =       pad_token_id
    __UpperCAmelCase						    =       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."				,				__lowerCAmelCase				,				)
      __UpperCAmelCase						    =       kwargs["use_cache"]

    __UpperCAmelCase						    =       use_mems_eval
    __UpperCAmelCase						    =       use_mems_train
    super().__init__(pad_token_id=__lowerCAmelCase				,				bos_token_id=__lowerCAmelCase				,				eos_token_id=__lowerCAmelCase				,				**__lowerCAmelCase   )






  @property
  def 	_UpperCAmelCase				(				self:			List[Any]   ) -> List[Any]:




    '''simple docstring'''




    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 	_UpperCAmelCase				(				self:			Union[str, Any]				,				__lowerCAmelCase:			Tuple   ) -> Optional[Any]:




    '''simple docstring'''




    raise NotImplementedError(
        F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''   )




def       __lowerCAmelCase      (						A_   : str					)    ->  Any:
  if not head:
    return True
  # split the list to two parts
  __UpperCAmelCase    ,		__UpperCAmelCase						    =       head.next, head
  while fast and fast.next:
    __UpperCAmelCase						    =       fast.next.next
    __UpperCAmelCase						    =       slow.next
  __UpperCAmelCase						    =       slow.next
  __UpperCAmelCase						    =       None  # Don't forget here! But forget still works!
  # reverse the second part
  __UpperCAmelCase						    =       None
  while second:
    __UpperCAmelCase						    =       second.next
    __UpperCAmelCase						    =       node
    __UpperCAmelCase						    =       second
    __UpperCAmelCase						    =       nxt
  # compare two parts
  # second part has the same or one less node
  while node:
    if node.val != head.val:
      return False
    __UpperCAmelCase						    =       node.next
    __UpperCAmelCase						    =       head.next
  return True




def       __lowerCAmelCase      (						A_   : Optional[Any]					)    ->  Optional[Any]:
  if not head or not head.next:
    return True

  # 1. Get the midpoint (slow)
  __UpperCAmelCase						    =       __UpperCAmelCase						    =       __UpperCAmelCase						    =       head
  while fast and fast.next:
    __UpperCAmelCase    ,		__UpperCAmelCase						    =       fast.next.next, slow.next

  # 2. Push the second half into the stack
  __UpperCAmelCase						    =       [slow.val]
  while slow.next:
    __UpperCAmelCase						    =       slow.next
    stack.append(slow.val					)

  # 3. Comparison
  while stack:
    if stack.pop() != cur.val:
      return False
    __UpperCAmelCase						    =       cur.next

  return True





def       __lowerCAmelCase      (						A_   : int					)    ->  Optional[int]:
  if not head or not head.next:
    return True
  __UpperCAmelCase						    =       {}
  __UpperCAmelCase						    =       0
  while head:
    if head.val in d:
      d[head.val].append(A_					)
    else:
      __UpperCAmelCase						    =       [pos]
    __UpperCAmelCase						    =       head.next
    pos += 1
  __UpperCAmelCase						    =       pos - 1
  __UpperCAmelCase						    =       0
  for v in d.values():
    if len(A_					) % 2 != 0:
      middle += 1
    else:
      __UpperCAmelCase						    =       0
      for i in range(0						,	len(A_					)					):
        if v[i] + v[len(A_					) - 1 - step] != checksum:
          return False
        step += 1
    if middle > 1:
      return False
  return True



