





import os
import unittest

from transformers import FunnelTokenizer, FunnelTokenizerFast
from transformers.models.funnel.tokenization_funnel import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_					,unittest.TestCase ):
       _UpperCAmelCase				:  Optional[int]			   =   FunnelTokenizer
       _UpperCAmelCase				:  Union[str, Any]			   =   FunnelTokenizerFast
       _UpperCAmelCase				:  Union[str, Any]			   =   True
       _UpperCAmelCase				:  Any			   =   True







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

          lowerCamelCase__       :						Dict        =							[
              '''<unk>''',
              '''<cls>''',
              '''<sep>''',
              '''want''',
              '''##want''',
              '''##ed''',
              '''wa''',
              '''un''',
              '''runn''',
              '''##ing''',
              ''',''',
              '''low''',
              '''lowest''',
          ]
          lowerCamelCase__       :						Any        =							os.path.join(self.tmpdirname		, VOCAB_FILES_NAMES['''vocab_file''']      )
          with open(self.vocab_file		, '''w'''		, encoding='''utf-8'''      ) as vocab_writer:
             vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]      )      )







       def 						__lowerCamelCase   (				self					:     Any		, **A					:     Dict      )       ->Union[str, Any]:
          return FunnelTokenizer.from_pretrained(self.tmpdirname		, **A      )







       def 						__lowerCamelCase   (				self					:     List[str]		, **A					:     List[str]      )       ->List[Any]:
          return FunnelTokenizerFast.from_pretrained(self.tmpdirname		, **A      )







       def 						__lowerCamelCase   (				self					:     List[Any]		, A					:     int      )       ->Optional[int]:
          lowerCamelCase__       :						Union[str, Any]        =							'''UNwant\u00E9d,running'''
          lowerCamelCase__       :						Any        =							'''unwanted, running'''
          return input_text, output_text







       def 						__lowerCamelCase   (				self					:     Tuple      )       ->Optional[Any]:
          lowerCamelCase__       :						Optional[int]        =							self.tokenizer_class(self.vocab_file      )

          lowerCamelCase__       :						List[str]        =							tokenizer.tokenize('''UNwant\u00E9d,running'''      )
          self.assertListEqual(A		, ['''un''', '''##want''', '''##ed''', ''',''', '''runn''', '''##ing''']      )
          self.assertListEqual(tokenizer.convert_tokens_to_ids(A      )		, [7, 4, 5, 1_0, 8, 9]      )







       def 						__lowerCamelCase   (				self					:     Optional[int]      )       ->Optional[int]:
          lowerCamelCase__       :						str        =							self.get_tokenizers(do_lower_case=A      )
          for tokenizer in tokenizers:
             lowerCamelCase__       :						List[str]        =							tokenizer('''UNwant\u00E9d,running'''      )
             lowerCamelCase__       :						Dict        =							len(inputs['''input_ids''']      ) - 1
             self.assertListEqual(inputs['''token_type_ids''']		, [2] + [0] * sentence_len      )

             lowerCamelCase__       :						Union[str, Any]        =							tokenizer('''UNwant\u00E9d,running'''		, '''UNwant\u00E9d,running'''      )
             self.assertListEqual(inputs['''token_type_ids''']		, [2] + [0] * sentence_len + [1] * sentence_len      )










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


_A :   Tuple  			=  logging.get_logger(__name__)

_A :   List[str]  			=  {
    '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        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_					,lowerCAmelCase_ ):
       _UpperCAmelCase				:  Dict			   =   "nat"

       _UpperCAmelCase				:  Tuple			   =   {
           "num_attention_heads": "num_heads",
           "num_hidden_layers": "num_layers",
       }







       def __init__(				self					:     List[Any]		, A					:     Union[str, Any]=4		, A					:     str=3		, A					:     List[Any]=6_4		, A					:     Optional[Any]=[3, 4, 6, 5]		, A					:     int=[2, 4, 8, 1_6]		, A					:     Optional[int]=7		, A					:     List[Any]=3.0		, A					:     str=True		, A					:     str=0.0		, A					:     Any=0.0		, A					:     int=0.1		, A					:     Tuple="gelu"		, A					:     List[Any]=0.02		, A					:     str=1e-5		, A					:     Optional[int]=0.0		, A					:     Optional[Any]=None		, A					:     Dict=None		, **A					:     str		, )       ->Union[str, Any]:
          super().__init__(**A      )

          lowerCamelCase__       :						Any        =							patch_size
          lowerCamelCase__       :						Optional[Any]        =							num_channels
          lowerCamelCase__       :						Any        =							embed_dim
          lowerCamelCase__       :						str        =							depths
          lowerCamelCase__       :						Union[str, Any]        =							len(A      )
          lowerCamelCase__       :						int        =							num_heads
          lowerCamelCase__       :						Optional[int]        =							kernel_size
          lowerCamelCase__       :						Optional[int]        =							mlp_ratio
          lowerCamelCase__       :						List[Any]        =							qkv_bias
          lowerCamelCase__       :						Tuple        =							hidden_dropout_prob
          lowerCamelCase__       :						List[str]        =							attention_probs_dropout_prob
          lowerCamelCase__       :						List[Any]        =							drop_path_rate
          lowerCamelCase__       :						Union[str, Any]        =							hidden_act
          lowerCamelCase__       :						Union[str, Any]        =							layer_norm_eps
          lowerCamelCase__       :						List[Any]        =							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
          lowerCamelCase__       :						str        =							int(embed_dim * 2 ** (len(A      ) - 1)      )
          lowerCamelCase__       :						Dict        =							layer_scale_init_value
          lowerCamelCase__       :						Dict        =							['''stem'''] + [F"stage{idx}" for idx in range(1		, len(A      ) + 1      )]
          lowerCamelCase__       ,							lowerCamelCase__       :						str        =							get_aligned_output_features_output_indices(
              out_features=A		, out_indices=A		, stage_names=self.stage_names      )



