
"""simple docstring"""



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


a       :						Optional[int]       		=		logging.get_logger(__name__)

a       :						Tuple       		=		{
    '''transfo-xl-wt103''': '''https://huggingface.co/transfo-xl-wt103/resolve/main/config.json''',
}




class 		a_    (			_UpperCAmelCase						):
    a   :					List[str]			     =					'transfo-xl'
    a   :					Tuple			     =					['mems']
    a   :					List[Any]			     =					{
        'n_token': 'vocab_size',
        'hidden_size': 'd_model',
        'num_attention_heads': 'n_head',
        'num_hidden_layers': 'n_layer',
    }







    def __init__(      self      :							Tuple  ,       __UpperCamelCase      :							Any=26_77_35  ,       __UpperCamelCase      :							Dict=[2_00_00, 4_00_00, 20_00_00]  ,       __UpperCamelCase      :							Optional[int]=10_24  ,       __UpperCamelCase      :							Union[str, Any]=10_24  ,       __UpperCamelCase      :							Any=16  ,       __UpperCamelCase      :							Tuple=64  ,       __UpperCamelCase      :							List[Any]=40_96  ,       __UpperCamelCase      :							Union[str, Any]=4  ,       __UpperCamelCase      :							str=False  ,       __UpperCamelCase      :							Any=18  ,       __UpperCamelCase      :							Union[str, Any]=16_00  ,       __UpperCamelCase      :							Dict=10_00  ,       __UpperCamelCase      :							Tuple=True  ,       __UpperCamelCase      :							Optional[Any]=True  ,       __UpperCamelCase      :							Tuple=0  ,       __UpperCamelCase      :							List[str]=-1  ,       __UpperCamelCase      :							Dict=True  ,       __UpperCamelCase      :							Optional[int]=0.1  ,       __UpperCamelCase      :							Union[str, Any]=0.0  ,       __UpperCamelCase      :							List[Any]=True  ,       __UpperCamelCase      :							int="normal"  ,       __UpperCamelCase      :							List[Any]=0.0_1  ,       __UpperCamelCase      :							Union[str, Any]=0.0_1  ,       __UpperCamelCase      :							Optional[int]=0.0_2  ,       __UpperCamelCase      :							Optional[Any]=1e-5  ,       __UpperCamelCase      :							Tuple=0  ,       **__UpperCamelCase      :							Optional[Any]  ,       )		->Tuple:






        '''simple docstring'''






        _UpperCAmelCase        = vocab_size
        _UpperCAmelCase        = []
        self.cutoffs.extend(__UpperCamelCase  )
        if proj_share_all_but_first:
            _UpperCAmelCase        = [False] + [True] * len(self.cutoffs  )
        else:
            _UpperCAmelCase        = [False] + [False] * len(self.cutoffs  )
        _UpperCAmelCase        = d_model
        _UpperCAmelCase        = d_embed
        _UpperCAmelCase        = d_head
        _UpperCAmelCase        = d_inner
        _UpperCAmelCase        = div_val
        _UpperCAmelCase        = pre_lnorm
        _UpperCAmelCase        = n_layer
        _UpperCAmelCase        = n_head
        _UpperCAmelCase        = mem_len
        _UpperCAmelCase        = same_length
        _UpperCAmelCase        = attn_type
        _UpperCAmelCase        = clamp_len
        _UpperCAmelCase        = sample_softmax
        _UpperCAmelCase        = adaptive
        _UpperCAmelCase        = dropout
        _UpperCAmelCase        = dropatt
        _UpperCAmelCase        = untie_r
        _UpperCAmelCase        = init
        _UpperCAmelCase        = init_range
        _UpperCAmelCase        = proj_init_std
        _UpperCAmelCase        = init_std
        _UpperCAmelCase        = layer_norm_epsilon
        super().__init__(eos_token_id=__UpperCamelCase  ,       **__UpperCamelCase  )







    @property
    def   _snake_case       (      self      :							Tuple  )		->List[str]:






        '''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   _snake_case       (      self      :							Union[str, Any]  ,       __UpperCamelCase      :							int  )		->Union[str, Any]:






        '''simple docstring'''






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

"""simple docstring"""



import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
 import torch

 from transformers.generation import DisjunctiveConstraint




@require_torch
class 		a_    (			unittest.TestCase						):







    def   _snake_case       (      self      :							Union[str, Any]  )		->Any:






        '''simple docstring'''






        _UpperCAmelCase        = [[1, 2, 4], [1, 2, 3, 4]]
        _UpperCAmelCase        = DisjunctiveConstraint(__UpperCamelCase  )
        self.assertTrue(isinstance(dc.token_ids  ,       __UpperCamelCase  )  )

        with self.assertRaises(__UpperCamelCase  ):
            DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]  )  )

        with self.assertRaises(__UpperCamelCase  ):
            DisjunctiveConstraint([torch.LongTensor([1, 2, 4]  ), torch.LongTensor([1, 2, 3, 4, 5]  )]  )







    def   _snake_case       (      self      :							Optional[int]  )		->Dict:






        '''simple docstring'''






        _UpperCAmelCase        = [[1, 2], [1, 2, 3, 4]]

        with self.assertRaises(__UpperCamelCase  ):
            DisjunctiveConstraint(__UpperCamelCase  )  # fails here







    def   _snake_case       (      self      :							Optional[int]  )		->Dict:






        '''simple docstring'''






        _UpperCAmelCase        = [[1, 2, 3], [1, 2, 4]]

        _UpperCAmelCase        = DisjunctiveConstraint(__UpperCamelCase  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(1  )
        _UpperCAmelCase        = stepped is True and completed is False and reset is False
        self.assertTrue(__UpperCamelCase  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.current_seq == [1]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(2  )
        _UpperCAmelCase        = stepped is True and completed is False and reset is False
        self.assertTrue(__UpperCamelCase  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.current_seq == [1, 2]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(3  )
        _UpperCAmelCase        = stepped is True and completed is True and reset is False
        self.assertTrue(__UpperCamelCase  )
        self.assertTrue(dc.completed  )  # Completed!
        self.assertTrue(dc.current_seq == [1, 2, 3]  )







    def   _snake_case       (      self      :							List[Any]  )		->Any:






        '''simple docstring'''






        _UpperCAmelCase        = [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

        _UpperCAmelCase        = DisjunctiveConstraint(__UpperCamelCase  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(1  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.current_seq == [1]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(2  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.current_seq == [1, 2]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(4  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.current_seq == [1, 2, 4]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(5  )
        self.assertTrue(dc.completed  )  # Completed!
        self.assertTrue(dc.current_seq == [1, 2, 4, 5]  )

        dc.reset()

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(1  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.remaining() == 3  )
        self.assertTrue(dc.current_seq == [1]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(2  )
        self.assertTrue(not dc.completed  )
        self.assertTrue(dc.remaining() == 2  )
        self.assertTrue(dc.current_seq == [1, 2]  )

        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = dc.update(5  )
        self.assertTrue(dc.completed  )  # Completed!
        self.assertTrue(dc.remaining() == 0  )
        self.assertTrue(dc.current_seq == [1, 2, 5]  )