


"""simple docstring"""







import warnings

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


a__				:							Tuple						=     logging.get_logger(__name__)

a__				:							Tuple						=     {
    '''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_	( UpperCamelCase):

	"""simple docstring"""





	snake_case__				:  List[Any]    					=			"xlnet"
	snake_case__				:  Tuple    					=			["mems"]
	snake_case__				:  Optional[Any]    					=			{
	    "n_token": "vocab_size",  # Backward compatibility
	    "hidden_size": "d_model",
	    "num_attention_heads": "n_head",
	    "num_hidden_layers": "n_layer",
	}




	def __init__( self			:				str			,			UpperCAmelCase__			:				int=3_2_0_0_0			,			UpperCAmelCase__			:				List[str]=1_0_2_4			,			UpperCAmelCase__			:				Union[str, Any]=2_4			,			UpperCAmelCase__			:				str=1_6			,			UpperCAmelCase__			:				int=4_0_9_6			,			UpperCAmelCase__			:				Dict="gelu"			,			UpperCAmelCase__			:				Optional[int]=True			,			UpperCAmelCase__			:				Dict="bi"			,			UpperCAmelCase__			:				Tuple=0.02			,			UpperCAmelCase__			:				Optional[Any]=1E-12			,			UpperCAmelCase__			:				Any=0.1			,			UpperCAmelCase__			:				Optional[Any]=5_1_2			,			UpperCAmelCase__			:				Optional[int]=None			,			UpperCAmelCase__			:				Dict=True			,			UpperCAmelCase__			:				List[str]=False			,			UpperCAmelCase__			:				Optional[Any]=False			,			UpperCAmelCase__			:				Optional[Any]=-1			,			UpperCAmelCase__			:				Optional[Any]=False			,			UpperCAmelCase__			:				str="last"			,			UpperCAmelCase__			:				List[Any]=True			,			UpperCAmelCase__			:				Dict="tanh"			,			UpperCAmelCase__			:				Optional[Any]=0.1			,			UpperCAmelCase__			:				Dict=5			,			UpperCAmelCase__			:				List[Any]=5			,			UpperCAmelCase__			:				Optional[Any]=5			,			UpperCAmelCase__			:				Optional[int]=1			,			UpperCAmelCase__			:				Dict=2			,			**UpperCAmelCase__			:				str			,			)       ->	Dict:
						__SCREAMING_SNAKE_CASE						   =				vocab_size
						__SCREAMING_SNAKE_CASE						   =				d_model
						__SCREAMING_SNAKE_CASE						   =				n_layer
						__SCREAMING_SNAKE_CASE						   =				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})"""   )
						__SCREAMING_SNAKE_CASE						   =				d_model // n_head
						__SCREAMING_SNAKE_CASE						   =				ff_activation
						__SCREAMING_SNAKE_CASE						   =				d_inner
						__SCREAMING_SNAKE_CASE						   =				untie_r
						__SCREAMING_SNAKE_CASE						   =				attn_type

						__SCREAMING_SNAKE_CASE						   =				initializer_range
						__SCREAMING_SNAKE_CASE						   =				layer_norm_eps

						__SCREAMING_SNAKE_CASE						   =				dropout
						__SCREAMING_SNAKE_CASE						   =				mem_len
						__SCREAMING_SNAKE_CASE						   =				reuse_len
						__SCREAMING_SNAKE_CASE						   =				bi_data
						__SCREAMING_SNAKE_CASE						   =				clamp_len
						__SCREAMING_SNAKE_CASE						   =				same_length

						__SCREAMING_SNAKE_CASE						   =				summary_type
						__SCREAMING_SNAKE_CASE						   =				summary_use_proj
						__SCREAMING_SNAKE_CASE						   =				summary_activation
						__SCREAMING_SNAKE_CASE						   =				summary_last_dropout
						__SCREAMING_SNAKE_CASE						   =				start_n_top
						__SCREAMING_SNAKE_CASE						   =				end_n_top

						__SCREAMING_SNAKE_CASE						   =				bos_token_id
						__SCREAMING_SNAKE_CASE						   =				pad_token_id
						__SCREAMING_SNAKE_CASE						   =				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__			,			)
											__SCREAMING_SNAKE_CASE						   =				kwargs["use_cache"]

						__SCREAMING_SNAKE_CASE						   =				use_mems_eval
						__SCREAMING_SNAKE_CASE						   =				use_mems_train
						super().__init__(pad_token_id=UpperCAmelCase__			,			bos_token_id=UpperCAmelCase__			,			eos_token_id=UpperCAmelCase__			,			**UpperCAmelCase__   )




	@property
	def   UpperCAmelCase_      ( self			:				List[str]   )       ->	str:
						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]			,			UpperCAmelCase__			:				str   )       ->	str:
						# 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."""   )




"""simple docstring"""







import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs




@pytest.mark.parametrize(
    "kwargs, expected"  ,						[
        ({"num_shards": 0, "max_num_jobs": 1}, []),
        ({"num_shards": 10, "max_num_jobs": 1}, [range(10   )]),
        ({"num_shards": 10, "max_num_jobs": 10}, [range(lowerCAmelCase_  ,						i + 1   ) for i in range(10   )]),
        ({"num_shards": 1, "max_num_jobs": 10}, [range(1   )]),
        ({"num_shards": 10, "max_num_jobs": 3}, [range(0  ,						4   ), range(4  ,						7   ), range(7  ,						10   )]),
        ({"num_shards": 3, "max_num_jobs": 10}, [range(0  ,						1   ), range(1  ,						2   ), range(2  ,						3   )]),
    ]  ,						)
def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				_distribute_shards(**lowerCAmelCase_   )
					assert out == expected




@pytest.mark.parametrize(
    "gen_kwargs, max_num_jobs, expected"  ,						[
        ({"foo": 0}, 10, [{"foo": 0}]),
        ({"shards": [0, 1, 2, 3]}, 1, [{"shards": [0, 1, 2, 3]}]),
        ({"shards": [0, 1, 2, 3]}, 4, [{"shards": [0]}, {"shards": [1]}, {"shards": [2]}, {"shards": [3]}]),
        ({"shards": [0, 1]}, 4, [{"shards": [0]}, {"shards": [1]}]),
        ({"shards": [0, 1, 2, 3]}, 2, [{"shards": [0, 1]}, {"shards": [2, 3]}]),
    ]  ,						)
def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				_split_gen_kwargs(lowerCAmelCase_  ,						lowerCAmelCase_   )
					assert out == expected




@pytest.mark.parametrize(
    "gen_kwargs, expected"  ,						[
        ({"foo": 0}, 1),
        ({"shards": [0]}, 1),
        ({"shards": [0, 1, 2, 3]}, 4),
        ({"shards": [0, 1, 2, 3], "foo": 0}, 4),
        ({"shards": [0, 1, 2, 3], "other": (0, 1)}, 4),
        ({"shards": [0, 1, 2, 3], "shards2": [0, 1]}, RuntimeError),
    ]  ,						)
def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					if expected is RuntimeError:
										with pytest.raises(lowerCAmelCase_   ):
															_number_of_shards_in_gen_kwargs(lowerCAmelCase_   )
					else:
										__SCREAMING_SNAKE_CASE						   =				_number_of_shards_in_gen_kwargs(lowerCAmelCase_   )
										assert out == expected
