


import json
import os
import unittest

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES, XLMTokenizer
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin



class 							A   (	__SCREAMING_SNAKE_CASE			,  unittest.TestCase							):
					'''simple docstring'''






					A__      =			XLMTokenizer
					A__      =			False

					def   lowerCamelCase__					(self   :						List[str]		)						->       Tuple:




							"""simple docstring"""


							super().setUp()

							# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
							lowercase__					      =		[
							    """l""",
							    """o""",
							    """w""",
							    """e""",
							    """r""",
							    """s""",
							    """t""",
							    """i""",
							    """d""",
							    """n""",
							    """w</w>""",
							    """r</w>""",
							    """t</w>""",
							    """lo""",
							    """low""",
							    """er</w>""",
							    """low</w>""",
							    """lowest</w>""",
							    """newer</w>""",
							    """wider</w>""",
							    """<unk>""",
							]
							lowercase__					      =		dict(zip(__UpperCAmelCase				, range(len(__UpperCAmelCase		)		)		)		)
							lowercase__					      =		["""l o 123""", """lo w 1456""", """e r</w> 1789""", """"""]

							lowercase__					      =		os.path.join(self.tmpdirname				, VOCAB_FILES_NAMES["""vocab_file"""]		)
							lowercase__					      =		os.path.join(self.tmpdirname				, VOCAB_FILES_NAMES["""merges_file"""]		)
							with open(self.vocab_file				, """w"""		) as fp:
									fp.write(json.dumps(__UpperCAmelCase		)		)
							with open(self.merges_file				, """w"""		) as fp:
									fp.write("""\n""".join(__UpperCAmelCase		)		)

					def   lowerCamelCase__					(self   :						Union[str, Any]				, _UpperCAmelCase   :						Union[str, Any]		)						->       Tuple:




							"""simple docstring"""


							lowercase__					      =		"""lower newer"""
							lowercase__					      =		"""lower newer"""
							return input_text, output_text

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




							"""simple docstring"""


							lowercase__					      =		XLMTokenizer(self.vocab_file				, self.merges_file		)

							lowercase__					      =		"""lower"""
							lowercase__					      =		["""low""", """er</w>"""]
							lowercase__					      =		tokenizer.tokenize(__UpperCAmelCase		)
							self.assertListEqual(__UpperCAmelCase				, __UpperCAmelCase		)

							lowercase__					      =		tokens + ["""<unk>"""]
							lowercase__					      =		[14, 15, 20]
							self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCAmelCase		)				, __UpperCAmelCase		)


					@slow
					def   lowerCamelCase__					(self   :						Optional[int]		)						->       Tuple:




							"""simple docstring"""


							lowercase__					      =		XLMTokenizer.from_pretrained("""xlm-mlm-en-2048"""		)

							lowercase__					      =		tokenizer.encode("""sequence builders"""				, add_special_tokens=__UpperCAmelCase		)
							lowercase__					      =		tokenizer.encode("""multi-sequence build"""				, add_special_tokens=__UpperCAmelCase		)

							lowercase__					      =		tokenizer.build_inputs_with_special_tokens(__UpperCAmelCase		)
							lowercase__					      =		tokenizer.build_inputs_with_special_tokens(__UpperCAmelCase				, __UpperCAmelCase		)

							assert encoded_sentence == [0] + text + [1]
							assert encoded_pair == [0] + text + [1] + text_a + [1]





import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


A	:		List[str]    =       logging.get_logger(__name__)

A	:		List[Any]    =       {
    'nvidia/segformer-b0-finetuned-ade-512-512': (
        'https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}



class 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






					A__      =			'''segformer'''

					def __init__(self   :						Dict				, _UpperCAmelCase   :						Optional[int]=3				, _UpperCAmelCase   :						Dict=4				, _UpperCAmelCase   :						Union[str, Any]=[2, 2, 2, 2]				, _UpperCAmelCase   :						List[str]=[8, 4, 2, 1]				, _UpperCAmelCase   :						str=[32, 64, 160, 256]				, _UpperCAmelCase   :						Optional[int]=[7, 3, 3, 3]				, _UpperCAmelCase   :						int=[4, 2, 2, 2]				, _UpperCAmelCase   :						str=[1, 2, 5, 8]				, _UpperCAmelCase   :						Optional[int]=[4, 4, 4, 4]				, _UpperCAmelCase   :						List[Any]="gelu"				, _UpperCAmelCase   :						Optional[Any]=0.0				, _UpperCAmelCase   :						Dict=0.0				, _UpperCAmelCase   :						Dict=0.1				, _UpperCAmelCase   :						List[str]=0.02				, _UpperCAmelCase   :						str=0.1				, _UpperCAmelCase   :						Optional[Any]=1E-6				, _UpperCAmelCase   :						Optional[Any]=256				, _UpperCAmelCase   :						Any=255				, **_UpperCAmelCase   :						str				, )						->       Tuple:




							"""simple docstring"""


							super().__init__(**_UpperCAmelCase		)

							if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
									warnings.warn(
									    """Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be"""
									    """ removed, as the behaviour will default to that of reshape_last_stage = True."""				, _UpperCAmelCase				, )

							lowercase__					      =		num_channels
							lowercase__					      =		num_encoder_blocks
							lowercase__					      =		depths
							lowercase__					      =		sr_ratios
							lowercase__					      =		hidden_sizes
							lowercase__					      =		patch_sizes
							lowercase__					      =		strides
							lowercase__					      =		mlp_ratios
							lowercase__					      =		num_attention_heads
							lowercase__					      =		hidden_act
							lowercase__					      =		hidden_dropout_prob
							lowercase__					      =		attention_probs_dropout_prob
							lowercase__					      =		classifier_dropout_prob
							lowercase__					      =		initializer_range
							lowercase__					      =		drop_path_rate
							lowercase__					      =		layer_norm_eps
							lowercase__					      =		decoder_hidden_size
							lowercase__					      =		kwargs.get("""reshape_last_stage"""				, _UpperCAmelCase		)
							lowercase__					      =		semantic_loss_ignore_index






class 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






					A__      =			version.parse('''1.11'''							)

					@property
					def   lowerCamelCase__					(self   :						Optional[int]		)						->       Mapping[str, Mapping[int, str]]:




							"""simple docstring"""


							return OrderedDict(
							    [
							        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
							    ]		)

					@property
					def   lowerCamelCase__					(self   :						Optional[int]		)						->       float:




							"""simple docstring"""


							return 1E-4


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




							"""simple docstring"""


							return 12

