




import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class     __lowerCAmelCase (       __magic_name__			,				unittest.TestCase ):

			"""simple docstring"""







			snake_case_   		=       None
			snake_case_   		=       BloomTokenizerFast
			snake_case_   		=       BloomTokenizerFast
			snake_case_   		=       True
			snake_case_   		=       False
			snake_case_   		=       '''tokenizer_file'''
			snake_case_   		=       {'''bos_token''': '''<s>''', '''eos_token''': '''</s>''', '''unk_token''': '''<unk>''', '''pad_token''': '''<pad>'''}


			def       lowercase_    (      self							)    ->      str:



							'''simple docstring'''
							super().setUp()
							__lowerCamelCase		       =    BloomTokenizerFast.from_pretrained('bigscience/tokenizer'							)
							tokenizer.save_pretrained(self.tmpdirname							)


			def       lowercase_    (      self			,						**lowerCamelCase__							)    ->      Optional[int]:



							'''simple docstring'''
							kwargs.update(self.special_tokens_map							)
							return BloomTokenizerFast.from_pretrained(self.tmpdirname			,						**lowerCamelCase__							)


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



							'''simple docstring'''
							__lowerCamelCase		       =    self.get_rust_tokenizer()

							__lowerCamelCase		       =    ['The quick brown fox</s>', 'jumps over the lazy dog</s>']
							__lowerCamelCase		       =    [[2_175, 23_714, 73_173, 144_252, 2], [77, 132_619, 3_478, 368, 109_586, 35_433, 2]]

							__lowerCamelCase		       =    tokenizer.batch_encode_plus(lowerCamelCase__							)['input_ids']
							self.assertListEqual(lowerCamelCase__			,						lowerCamelCase__							)

							__lowerCamelCase		       =    tokenizer.batch_decode(lowerCamelCase__							)
							self.assertListEqual(lowerCamelCase__			,						lowerCamelCase__							)


			def       lowercase_    (      self			,						lowerCamelCase__=6							)    ->      Optional[int]:



							'''simple docstring'''
							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
											with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""							):
															__lowerCamelCase		       =    self.rust_tokenizer_class.from_pretrained(lowerCamelCase__			,						**lowerCamelCase__							)
															# tokenizer_r.pad_token = None # Hotfixing padding = None
															# Simple input
															__lowerCamelCase		       =    'This is a simple input'
															__lowerCamelCase		       =    ['This is a simple input 1', 'This is a simple input 2']
															__lowerCamelCase		       =    ('This is a simple input', 'This is a pair')
															__lowerCamelCase		       =    [
															    ('This is a simple input 1', 'This is a simple input 2'),
															    ('This is a simple pair 1', 'This is a simple pair 2'),
															]

															# Simple input tests
															try:
																			tokenizer_r.encode(lowerCamelCase__			,						max_length=lowerCamelCase__							)
																			tokenizer_r.encode_plus(lowerCamelCase__			,						max_length=lowerCamelCase__							)

																			tokenizer_r.batch_encode_plus(lowerCamelCase__			,						max_length=lowerCamelCase__							)
																			tokenizer_r.encode(lowerCamelCase__			,						max_length=lowerCamelCase__							)
																			tokenizer_r.batch_encode_plus(lowerCamelCase__			,						max_length=lowerCamelCase__							)
															except ValueError:
																			self.fail('Bloom Tokenizer should be able to deal with padding'							)

															__lowerCamelCase		       =    None  # Hotfixing padding = None
															self.assertRaises(lowerCamelCase__			,						tokenizer_r.encode			,						lowerCamelCase__			,						max_length=lowerCamelCase__			,						padding='max_length'							)

															# Simple input
															self.assertRaises(lowerCamelCase__			,						tokenizer_r.encode_plus			,						lowerCamelCase__			,						max_length=lowerCamelCase__			,						padding='max_length'							)

															# Simple input
															self.assertRaises(
															    lowerCamelCase__			,						tokenizer_r.batch_encode_plus			,						lowerCamelCase__			,						max_length=lowerCamelCase__			,						padding='max_length'			,						)

															# Pair input
															self.assertRaises(lowerCamelCase__			,						tokenizer_r.encode			,						lowerCamelCase__			,						max_length=lowerCamelCase__			,						padding='max_length'							)

															# Pair input
															self.assertRaises(lowerCamelCase__			,						tokenizer_r.encode_plus			,						lowerCamelCase__			,						max_length=lowerCamelCase__			,						padding='max_length'							)

															# Pair input
															self.assertRaises(
															    lowerCamelCase__			,						tokenizer_r.batch_encode_plus			,						lowerCamelCase__			,						max_length=lowerCamelCase__			,						padding='max_length'			,						)


			def       lowercase_    (      self							)    ->      Tuple:



							'''simple docstring'''
							__lowerCamelCase		       =    self.get_rust_tokenizer()
							__lowerCamelCase		       =    load_dataset('xnli'			,						'all_languages'			,						split='test'			,						streaming=lowerCamelCase__							)

							__lowerCamelCase		       =    next(iter(lowerCamelCase__							)							)['premise']  # pick up one data
							__lowerCamelCase		       =    list(sample_data.values()							)

							__lowerCamelCase		       =    list(map(tokenizer.encode			,						lowerCamelCase__							)							)
							__lowerCamelCase		       =    [tokenizer.decode(lowerCamelCase__			,						clean_up_tokenization_spaces=lowerCamelCase__							) for x in output_tokens]
							self.assertListEqual(lowerCamelCase__			,						lowerCamelCase__							)






			def       lowercase_    (      self							)    ->      str:



							'''simple docstring'''
							# The test has to be overriden because BLOOM uses ALiBi positional embeddings that does not have
							# any sequence length constraints. This test of the parent class will fail since it relies on the
							# maximum sequence length of the positoonal embeddings.
							self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map							)			,						1							)
							self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()							)[0]							)			,						1							)





"""simple docstring"""


import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


__A						   =			logging.get_logger(__name__)

__A						   =			{
    "SenseTime/deformable-detr": "https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json",
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      str         =  """deformable_detr"""
				SCREAMING_SNAKE_CASE_   :      int         =  {
				    """hidden_size""": """d_model""",
				    """num_attention_heads""": """encoder_attention_heads""",
				}

				def __init__(	self							:				int     ,  UpperCamelCase__							:				int=True     ,  UpperCamelCase__							:				str=None     ,  UpperCamelCase__							:				int=3     ,  UpperCamelCase__							:				Dict=3_0_0     ,  UpperCamelCase__							:				Optional[int]=1_0_2_4     ,  UpperCamelCase__							:				int=6     ,  UpperCamelCase__							:				List[Any]=1_0_2_4     ,  UpperCamelCase__							:				List[Any]=8     ,  UpperCamelCase__							:				str=6     ,  UpperCamelCase__							:				str=1_0_2_4     ,  UpperCamelCase__							:				Union[str, Any]=8     ,  UpperCamelCase__							:				Dict=0.0     ,  UpperCamelCase__							:				str=True     ,  UpperCamelCase__							:				List[Any]="relu"     ,  UpperCamelCase__							:				Tuple=2_5_6     ,  UpperCamelCase__							:				Tuple=0.1     ,  UpperCamelCase__							:				Optional[int]=0.0     ,  UpperCamelCase__							:				Dict=0.0     ,  UpperCamelCase__							:				Optional[Any]=0.02     ,  UpperCamelCase__							:				Dict=1.0     ,  UpperCamelCase__							:				Dict=True     ,  UpperCamelCase__							:				Optional[Any]=False     ,  UpperCamelCase__							:				List[str]="sine"     ,  UpperCamelCase__							:				Any="resnet50"     ,  UpperCamelCase__							:				List[Any]=True     ,  UpperCamelCase__							:				Any=False     ,  UpperCamelCase__							:				Optional[int]=4     ,  UpperCamelCase__							:				List[str]=4     ,  UpperCamelCase__							:				Tuple=4     ,  UpperCamelCase__							:				List[str]=False     ,  UpperCamelCase__							:				Optional[int]=3_0_0     ,  UpperCamelCase__							:				int=False     ,  UpperCamelCase__							:				List[Any]=1     ,  UpperCamelCase__							:				Optional[Any]=5     ,  UpperCamelCase__							:				List[Any]=2     ,  UpperCamelCase__							:				str=1     ,  UpperCamelCase__							:				int=1     ,  UpperCamelCase__							:				Dict=5     ,  UpperCamelCase__							:				Tuple=2     ,  UpperCamelCase__							:				Optional[Any]=0.1     ,  UpperCamelCase__							:				Union[str, Any]=0.25     ,  UpperCamelCase__							:				List[Any]=False     ,  **UpperCamelCase__							:				Dict     ,  )->   Optional[int]:



						'''simple docstring'''


						if backbone_config is not None and use_timm_backbone:
								raise ValueError("You can't specify both `backbone_config` and `use_timm_backbone`.")

						if not use_timm_backbone:
								if backbone_config is None:
										logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.")
										__lowerCAmelCase:       List[Any]          =			CONFIG_MAPPING["resnet"](out_features=["stage4"])
								elif isinstance(UpperCamelCase__     ,  UpperCamelCase__):
										__lowerCAmelCase:       int          =			backbone_config.get("model_type")
										__lowerCAmelCase:       List[str]          =			CONFIG_MAPPING[backbone_model_type]
										__lowerCAmelCase:       Any          =			config_class.from_dict(UpperCamelCase__)
						__lowerCAmelCase:       int          =			use_timm_backbone
						__lowerCAmelCase:       Any          =			backbone_config
						__lowerCAmelCase:       Tuple          =			num_channels
						__lowerCAmelCase:       str          =			num_queries
						__lowerCAmelCase:       List[str]          =			max_position_embeddings
						__lowerCAmelCase:       List[Any]          =			d_model
						__lowerCAmelCase:       Union[str, Any]          =			encoder_ffn_dim
						__lowerCAmelCase:       Tuple          =			encoder_layers
						__lowerCAmelCase:       List[str]          =			encoder_attention_heads
						__lowerCAmelCase:       Any          =			decoder_ffn_dim
						__lowerCAmelCase:       Union[str, Any]          =			decoder_layers
						__lowerCAmelCase:       List[Any]          =			decoder_attention_heads
						__lowerCAmelCase:       List[Any]          =			dropout
						__lowerCAmelCase:       Optional[Any]          =			attention_dropout
						__lowerCAmelCase:       Union[str, Any]          =			activation_dropout
						__lowerCAmelCase:       Union[str, Any]          =			activation_function
						__lowerCAmelCase:       Dict          =			init_std
						__lowerCAmelCase:       int          =			init_xavier_std
						__lowerCAmelCase:       str          =			encoder_layerdrop
						__lowerCAmelCase:       Union[str, Any]          =			auxiliary_loss
						__lowerCAmelCase:       List[Any]          =			position_embedding_type
						__lowerCAmelCase:       str          =			backbone
						__lowerCAmelCase:       Tuple          =			use_pretrained_backbone
						__lowerCAmelCase:       int          =			dilation
						# deformable attributes
						__lowerCAmelCase:       Union[str, Any]          =			num_feature_levels
						__lowerCAmelCase:       Optional[Any]          =			encoder_n_points
						__lowerCAmelCase:       Dict          =			decoder_n_points
						__lowerCAmelCase:       Optional[Any]          =			two_stage
						__lowerCAmelCase:       Tuple          =			two_stage_num_proposals
						__lowerCAmelCase:       int          =			with_box_refine
						if two_stage is True and with_box_refine is False:
								raise ValueError("If two_stage is True, with_box_refine must be True.")
						# Hungarian matcher
						__lowerCAmelCase:       str          =			class_cost
						__lowerCAmelCase:       List[str]          =			bbox_cost
						__lowerCAmelCase:       List[str]          =			giou_cost
						# Loss coefficients
						__lowerCAmelCase:       Tuple          =			mask_loss_coefficient
						__lowerCAmelCase:       int          =			dice_loss_coefficient
						__lowerCAmelCase:       Any          =			bbox_loss_coefficient
						__lowerCAmelCase:       str          =			giou_loss_coefficient
						__lowerCAmelCase:       int          =			eos_coefficient
						__lowerCAmelCase:       Tuple          =			focal_alpha
						__lowerCAmelCase:       Optional[Any]          =			disable_custom_kernels
						super().__init__(is_encoder_decoder=UpperCamelCase__     ,  **UpperCamelCase__)

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



						'''simple docstring'''


						return self.encoder_attention_heads

				@property
				def 							lowercase_     (	self							:				Optional[Any])->   int:



						'''simple docstring'''


						return self.d_model




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



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			copy.deepcopy(self.__dict__)
						if self.backbone_config is not None:
								__lowerCAmelCase:       str          =			self.backbone_config.to_dict()
						__lowerCAmelCase:       Tuple          =			self.__class__.model_type
						return output


