




import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)




class     snake_case__							(unittest.TestCase   ):
				"""simple docstring"""



				def 							__UpperCAmelCase							(      self				:     List[str]							)					->     Dict:
							a    =			["a", "b", "c"]

							# Defaults to last layer if both are None
							a    ,		a    =			get_aligned_output_features_output_indices(__lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase							)
							self.assertEqual(__lowerCamelCase					,      ["c"]							)
							self.assertEqual(__lowerCamelCase					,      [2]							)

							# Out indices set to match out features
							a    ,		a    =			get_aligned_output_features_output_indices(["a", "c"]					,      __lowerCamelCase					,      __lowerCamelCase							)
							self.assertEqual(__lowerCamelCase					,      ["a", "c"]							)
							self.assertEqual(__lowerCamelCase					,      [0, 2]							)

							# Out features set to match out indices
							a    ,		a    =			get_aligned_output_features_output_indices(__lowerCamelCase					,      [0, 2]					,      __lowerCamelCase							)
							self.assertEqual(__lowerCamelCase					,      ["a", "c"]							)
							self.assertEqual(__lowerCamelCase					,      [0, 2]							)

							# Out features selected from negative indices
							a    ,		a    =			get_aligned_output_features_output_indices(__lowerCamelCase					,      [-3, -1]					,      __lowerCamelCase							)
							self.assertEqual(__lowerCamelCase					,      ["a", "c"]							)
							self.assertEqual(__lowerCamelCase					,      [-3, -1]							)





				def 							__UpperCAmelCase							(      self				:     int							)					->     str:
							# Stage names must be set
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(["a", "b"]					,      (0, 1)					,      __lowerCamelCase							)

							# Out features must be a list
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(("a", "b")					,      (0, 1)					,      ["a", "b"]							)

							# Out features must be a subset of stage names
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(["a", "b"]					,      (0, 1)					,      ["a"]							)

							# Out indices must be a list or tuple
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(__lowerCamelCase					,      0					,      ["a", "b"]							)

							# Out indices must be a subset of stage names
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(__lowerCamelCase					,      (0, 1)					,      ["a"]							)

							# Out features and out indices must be the same length
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(["a", "b"]					,      (0,)					,      ["a", "b", "c"]							)

							# Out features should match out indices
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(["a", "b"]					,      (0, 2)					,      ["a", "b", "c"]							)

							# Out features and out indices should be in order
							with self.assertRaises(__lowerCamelCase							):
										verify_out_features_out_indices(["b", "a"]					,      (0, 1)					,      ["a", "b"]							)

							# Check passes with valid inputs
							verify_out_features_out_indices(["a", "b", "d"]					,      (0, 1, -1)					,      ["a", "b", "c", "d"]							)





				def 							__UpperCAmelCase							(      self				:     Optional[int]							)					->     List[str]:
							a    =			BackboneMixin()

							a    =			["a", "b", "c"]
							a    =			["a", "c"]
							a    =			[0, 2]

							# Check that the output features and indices are set correctly
							self.assertEqual(backbone.out_features					,      ["a", "c"]							)
							self.assertEqual(backbone.out_indices					,      [0, 2]							)

							# Check out features and indices are updated correctly
							a    =			["a", "b"]
							self.assertEqual(backbone.out_features					,      ["a", "b"]							)
							self.assertEqual(backbone.out_indices					,      [0, 1]							)

							a    =			[-3, -1]
							self.assertEqual(backbone.out_features					,      ["a", "c"]							)
							self.assertEqual(backbone.out_indices					,      [-3, -1]							)







"""simple docstring"""




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


__lowerCamelCase							 =     logging.get_logger(__name__)

__lowerCamelCase							 =     {
    "transfo-xl-wt103": "https://huggingface.co/transfo-xl-wt103/resolve/main/config.json",
}
class 			UpperCamelCase__(	__A       ):
						lowerCAmelCase__     :  Union[str, Any]  							=						'transfo-xl'
						lowerCAmelCase__     :  Any  							=						['mems']
						lowerCAmelCase__     :  Tuple  							=						{
						    'n_token': 'vocab_size',
						    'hidden_size': 'd_model',
						    'num_attention_heads': 'n_head',
						    'num_hidden_layers': 'n_layer',
						}





						def __init__(				self						,__UpperCAmelCase=26_77_35						,__UpperCAmelCase=[2_00_00, 4_00_00, 20_00_00]						,__UpperCAmelCase=10_24						,__UpperCAmelCase=10_24						,__UpperCAmelCase=16						,__UpperCAmelCase=64						,__UpperCAmelCase=40_96						,__UpperCAmelCase=4						,__UpperCAmelCase=False						,__UpperCAmelCase=18						,__UpperCAmelCase=16_00						,__UpperCAmelCase=10_00						,__UpperCAmelCase=True						,__UpperCAmelCase=True						,__UpperCAmelCase=0						,__UpperCAmelCase=-1						,__UpperCAmelCase=True						,__UpperCAmelCase=0.1						,__UpperCAmelCase=0.0						,__UpperCAmelCase=True						,__UpperCAmelCase="normal"						,__UpperCAmelCase=0.0_1						,__UpperCAmelCase=0.0_1						,__UpperCAmelCase=0.0_2						,__UpperCAmelCase=1e-5						,__UpperCAmelCase=0						,**__UpperCAmelCase						,)    -> Tuple:
													A__		   =							vocab_size
													A__		   =							[]
													self.cutoffs.extend(__UpperCAmelCase   )
													if proj_share_all_but_first:
																				A__		   =							[False] + [True] * len(self.cutoffs   )
													else:
																				A__		   =							[False] + [False] * len(self.cutoffs   )
													A__		   =							d_model
													A__		   =							d_embed
													A__		   =							d_head
													A__		   =							d_inner
													A__		   =							div_val
													A__		   =							pre_lnorm
													A__		   =							n_layer
													A__		   =							n_head
													A__		   =							mem_len
													A__		   =							same_length
													A__		   =							attn_type
													A__		   =							clamp_len
													A__		   =							sample_softmax
													A__		   =							adaptive
													A__		   =							dropout
													A__		   =							dropatt
													A__		   =							untie_r
													A__		   =							init
													A__		   =							init_range
													A__		   =							proj_init_std
													A__		   =							init_std
													A__		   =							layer_norm_epsilon
													super().__init__(eos_token_id=__UpperCAmelCase						,**__UpperCAmelCase   )





						@property
						def  snake_case__		(				self   )    -> Optional[Any]:
													# Message copied from Transformer-XL documentation
													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						,__UpperCAmelCase   )    -> int:
													# 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.'''   )





