





from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_lowerCamelCase 					=      logging.get_logger(__name__)

_lowerCamelCase 					=      {
    'shi-labs/nat-mini-in1k-224': 'https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json',
    # See all Nat models at https://huggingface.co/models?filter=nat
}




class 	UpperCamelCase_							(  UpperCamelCase__					,	UpperCamelCase__     ):
							lowerCamelCase_							     =       "nat"

							lowerCamelCase_							     =       {
							    "num_attention_heads": "num_heads",
							    "num_hidden_layers": "num_layers",
							}


							def __init__(				self     :List[Any]				,					__A     :Union[str, Any]=4				,					__A     :Dict=3				,					__A     :str=64				,					__A     :Optional[int]=[3, 4, 6, 5]				,					__A     :Tuple=[2, 4, 8, 16]				,					__A     :List[str]=7				,					__A     :Optional[Any]=3.0				,					__A     :Tuple=True				,					__A     :Tuple=0.0				,					__A     :Dict=0.0				,					__A     :Tuple=0.1				,					__A     :str="gelu"				,					__A     :Tuple=0.0_2				,					__A     :str=1E-5				,					__A     :Tuple=0.0				,					__A     :List[str]=None				,					__A     :Optional[Any]=None				,					**__A     :Optional[Any]				,					) -> List[str]:



									"""simple docstring"""



									super().__init__(**__A		)

									SCREAMING_SNAKE_CASE__								=   patch_size
									SCREAMING_SNAKE_CASE__								=   num_channels
									SCREAMING_SNAKE_CASE__								=   embed_dim
									SCREAMING_SNAKE_CASE__								=   depths
									SCREAMING_SNAKE_CASE__								=   len(__A		)
									SCREAMING_SNAKE_CASE__								=   num_heads
									SCREAMING_SNAKE_CASE__								=   kernel_size
									SCREAMING_SNAKE_CASE__								=   mlp_ratio
									SCREAMING_SNAKE_CASE__								=   qkv_bias
									SCREAMING_SNAKE_CASE__								=   hidden_dropout_prob
									SCREAMING_SNAKE_CASE__								=   attention_probs_dropout_prob
									SCREAMING_SNAKE_CASE__								=   drop_path_rate
									SCREAMING_SNAKE_CASE__								=   hidden_act
									SCREAMING_SNAKE_CASE__								=   layer_norm_eps
									SCREAMING_SNAKE_CASE__								=   initializer_range
									# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
									# this indicates the channel dimension after the last stage of the model
									SCREAMING_SNAKE_CASE__								=   int(embed_dim * 2 ** (len(__A		) - 1)		)
									SCREAMING_SNAKE_CASE__								=   layer_scale_init_value
									SCREAMING_SNAKE_CASE__								=   ["""stem"""] + [f'''stage{idx}''' for idx in range(1				,					len(__A		) + 1		)]
									SCREAMING_SNAKE_CASE__						,    SCREAMING_SNAKE_CASE__								=   get_aligned_output_features_output_indices(
									    out_features=__A				,					out_indices=__A				,					stage_names=self.stage_names		)





'''simple docstring'''
import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin
class   __UpperCAmelCase				(     lowerCAmelCase			,unittest.TestCase				):



					'''simple docstring'''





					_UpperCamelCase							=		CTRLTokenizer
					_UpperCamelCase							=		False
					_UpperCamelCase							=		False



					def     __snake_case						(	self     :						str)    ->							List[Any]:
								super().setUp()

								# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
								A_									= ['adapt', 're@@', 'a@@', 'apt', 'c@@', 't', '<unk>']
								A_									= dict(zip(_lowercase      ,       range(len(_lowercase))))
								A_									= ['#version: 0.2', 'a p', 'ap t</w>', 'r e', 'a d', 'ad apt</w>', '']
								A_									= {'unk_token': '<unk>'}

								A_									= os.path.join(self.tmpdirname      ,       VOCAB_FILES_NAMES['vocab_file'])
								A_									= os.path.join(self.tmpdirname      ,       VOCAB_FILES_NAMES['merges_file'])
								with open(self.vocab_file      ,       'w'      ,       encoding='utf-8') as fp:
											fp.write(json.dumps(_lowercase) + '\n')
								with open(self.merges_file      ,       'w'      ,       encoding='utf-8') as fp:
											fp.write('\n'.join(_lowercase))



					def     __snake_case						(	self     :						Optional[int]      ,       **_lowercase     :						Optional[int])    ->							Union[str, Any]:
								kwargs.update(self.special_tokens_map)
								return CTRLTokenizer.from_pretrained(self.tmpdirname      ,       **_lowercase)



					def     __snake_case						(	self     :						List[Any]      ,       _lowercase     :						Union[str, Any])    ->							Dict:
								A_									= 'adapt react readapt apt'
								A_									= 'adapt react readapt apt'
								return input_text, output_text



					def     __snake_case						(	self     :						Any)    ->							Any:
								A_									= CTRLTokenizer(self.vocab_file      ,       self.merges_file      ,       **self.special_tokens_map)
								A_									= 'adapt react readapt apt'
								A_									= 'adapt re@@ a@@ c@@ t re@@ adapt apt'.split()
								A_									= tokenizer.tokenize(_lowercase)
								self.assertListEqual(_lowercase      ,       _lowercase)

								A_									= tokens + [tokenizer.unk_token]

								A_									= [0, 1, 2, 4, 5, 1, 0, 3, 6]
								self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowercase)      ,       _lowercase)




