

"""simple docstring"""


import json
import os
import unittest

from transformers import BatchEncoding, LEDTokenizer, LEDTokenizerFast
from transformers.models.led.tokenization_led import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class      __a							(__SCREAMING_SNAKE_CASE   ,	unittest.TestCase):






     '''simple docstring'''
     _SCREAMING_SNAKE_CASE						:Optional[int]       = LEDTokenizer
     _SCREAMING_SNAKE_CASE						:List[Any]       = LEDTokenizerFast
     _SCREAMING_SNAKE_CASE						:Union[str, Any]       = True

     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           super().setUp()
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	[
               '''l''',
               '''o''',
               '''w''',
               '''e''',
               '''r''',
               '''s''',
               '''t''',
               '''i''',
               '''d''',
               '''n''',
               '''\u0120''',
               '''\u0120l''',
               '''\u0120n''',
               '''\u0120lo''',
               '''\u0120low''',
               '''er''',
               '''\u0120lowest''',
               '''\u0120newer''',
               '''\u0120wider''',
               '''<unk>''',
           ]
           SCREAMING_SNAKE_CASE__   :      Any      		=	dict(zip(__snake_case	,    range(len(__snake_case  )  )  )  )
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
           SCREAMING_SNAKE_CASE__   :      int      		=	{'''unk_token''': '''<unk>'''}

           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	os.path.join(self.tmpdirname	,    VOCAB_FILES_NAMES["""vocab_file"""]  )
           SCREAMING_SNAKE_CASE__   :      Any      		=	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(__snake_case  ) + """\n"""  )
           with open(self.merges_file	,    """w"""	,    encoding="""utf-8"""  ) as fp:
                 fp.write("""\n""".join(__snake_case  )  )

     def 					_a			(						self	,    **_a  )  ->      Optional[Any]:


           """simple docstring"""


           kwargs.update(self.special_tokens_map  )
           return self.tokenizer_class.from_pretrained(self.tmpdirname	,    **__snake_case  )

     def 					_a			(						self	,    **_a  )  ->      Dict:


           """simple docstring"""


           kwargs.update(self.special_tokens_map  )
           return self.rust_tokenizer_class.from_pretrained(self.tmpdirname	,    **__snake_case  )

     def 					_a			(						self	,    _a  )  ->      Optional[int]:


           """simple docstring"""


           return "lower newer", "lower newer"

     @cached_property
     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           return LEDTokenizer.from_pretrained("""allenai/led-base-16384"""  )

     @cached_property
     def 					_a			(						self  )  ->      str:


           """simple docstring"""


           return LEDTokenizerFast.from_pretrained("""allenai/led-base-16384"""  )

     @require_torch
     def 					_a			(						self  )  ->      Optional[Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Any      		=	['''A long paragraph for summarization.''', '''Another paragraph for summarization.''']
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	[0, 250, 251, 17_818, 13, 39_186, 1_938, 4, 2]

           for tokenizer in [self.default_tokenizer, self.default_tokenizer_fast]:
                 SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	tokenizer(__snake_case	,    max_length=len(__snake_case  )	,    padding=__snake_case	,    return_tensors="""pt"""  )
                 self.assertIsInstance(__snake_case	,    __snake_case  )

                 self.assertEqual((2, 9)	,    batch.input_ids.shape  )
                 self.assertEqual((2, 9)	,    batch.attention_mask.shape  )
                 SCREAMING_SNAKE_CASE__   :      List[Any]      		=	batch.input_ids.tolist()[0]
                 self.assertListEqual(__snake_case	,    __snake_case  )

     @require_torch
     def 					_a			(						self  )  ->      Optional[Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Dict      		=	['''A long paragraph for summarization.''', '''Another paragraph for summarization.''']
           for tokenizer in [self.default_tokenizer, self.default_tokenizer_fast]:
                 SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	tokenizer(__snake_case	,    padding=__snake_case	,    return_tensors="""pt"""  )
                 self.assertIn("""input_ids"""	,    __snake_case  )
                 self.assertIn("""attention_mask"""	,    __snake_case  )
                 self.assertNotIn("""labels"""	,    __snake_case  )
                 self.assertNotIn("""decoder_attention_mask"""	,    __snake_case  )

     @require_torch
     def 					_a			(						self  )  ->      int:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	[
               '''Summary of the text.''',
               '''Another summary.''',
           ]
           for tokenizer in [self.default_tokenizer, self.default_tokenizer_fast]:
                 SCREAMING_SNAKE_CASE__   :      List[Any]      		=	tokenizer(text_target=__snake_case	,    max_length=32	,    padding="""max_length"""	,    return_tensors="""pt"""  )
                 self.assertEqual(32	,    targets["""input_ids"""].shape[1]  )

     @require_torch
     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           for tokenizer in [self.default_tokenizer, self.default_tokenizer_fast]:
                 SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	tokenizer(
                     ["""I am a small frog""" * 1_024, """I am a small frog"""]	,    padding=__snake_case	,    truncation=__snake_case	,    return_tensors="""pt"""  )
                 self.assertIsInstance(__snake_case	,    __snake_case  )
                 self.assertEqual(batch.input_ids.shape	,    (2, 5_122)  )

     @require_torch
     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	['''A long paragraph for summarization.''']
           SCREAMING_SNAKE_CASE__   :      Any      		=	[
               '''Summary of the text.''',
           ]
           for tokenizer in [self.default_tokenizer, self.default_tokenizer_fast]:
                 SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	tokenizer(__snake_case	,    return_tensors="""pt"""  )
                 SCREAMING_SNAKE_CASE__   :      Any      		=	tokenizer(text_target=__snake_case	,    return_tensors="""pt"""  )
                 SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	inputs['''input_ids''']
                 SCREAMING_SNAKE_CASE__   :      Any      		=	targets['''input_ids''']
                 self.assertTrue((input_ids[:, 0] == tokenizer.bos_token_id).all().item()  )
                 self.assertTrue((labels[:, 0] == tokenizer.bos_token_id).all().item()  )
                 self.assertTrue((input_ids[:, -1] == tokenizer.eos_token_id).all().item()  )
                 self.assertTrue((labels[:, -1] == tokenizer.eos_token_id).all().item()  )

     @require_torch
     def 					_a			(						self  )  ->      int:


           """simple docstring"""


           for tokenizer in [self.default_tokenizer, self.default_tokenizer_fast]:
                 SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	['''Summary of the text.''', '''Another summary.''']
                 SCREAMING_SNAKE_CASE__   :      List[Any]      		=	[[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, -1, -1]]

                 SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	tokenizer(__snake_case	,    padding=__snake_case  )
                 SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	[[0] * len(__snake_case  ) for x in encoded_output['''input_ids''']]
                 SCREAMING_SNAKE_CASE__   :      str      		=	tokenizer.pad(__snake_case  )
                 self.assertSequenceEqual(outputs["""global_attention_mask"""]	,    __snake_case  )

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


           """simple docstring"""


           pass





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


           """simple docstring"""


           for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''  ):
                       SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	self.rust_tokenizer_class.from_pretrained(__snake_case	,    **__snake_case  )
                       SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.tokenizer_class.from_pretrained(__snake_case	,    **__snake_case  )
                       SCREAMING_SNAKE_CASE__   :      int      		=	'''A, <mask> AllenNLP sentence.'''
                       SCREAMING_SNAKE_CASE__   :      str      		=	tokenizer_r.encode_plus(__snake_case	,    add_special_tokens=__snake_case	,    return_token_type_ids=__snake_case  )
                       SCREAMING_SNAKE_CASE__   :      str      		=	tokenizer_p.encode_plus(__snake_case	,    add_special_tokens=__snake_case	,    return_token_type_ids=__snake_case  )
                       self.assertEqual(sum(tokens_r["""token_type_ids"""]  )	,    sum(tokens_p["""token_type_ids"""]  )  )
                       self.assertEqual(
                           sum(tokens_r["""attention_mask"""]  ) / len(tokens_r["""attention_mask"""]  )	,    sum(tokens_p["""attention_mask"""]  ) / len(tokens_p["""attention_mask"""]  )	,    )

                       SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	tokenizer_r.convert_ids_to_tokens(tokens_r["""input_ids"""]  )
                       SCREAMING_SNAKE_CASE__   :      Tuple      		=	tokenizer_p.convert_ids_to_tokens(tokens_p["""input_ids"""]  )
                       self.assertSequenceEqual(tokens_p["""input_ids"""]	,    [0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]  )
                       self.assertSequenceEqual(tokens_r["""input_ids"""]	,    [0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]  )

                       self.assertSequenceEqual(
                           __snake_case	,    ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]  )
                       self.assertSequenceEqual(
                           __snake_case	,    ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]  )







"""simple docstring"""


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


a					:List[Any]    = logging.get_logger(__name__)

a					:Optional[int]    = {
    "microsoft/focalnet-tiny": "https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json",
}

class      __a							(UpperCamelCase_   ,	UpperCamelCase_):






     '''simple docstring'''
     _SCREAMING_SNAKE_CASE						:Any       = """focalnet"""

     def __init__(						self	,    _a=224	,    _a=4	,    _a=3	,    _a=96	,    _a=False	,    _a=[192, 384, 768, 768]	,    _a=[2, 2, 6, 2]	,    _a=[2, 2, 2, 2]	,    _a=[3, 3, 3, 3]	,    _a="gelu"	,    _a=4.0	,    _a=0.0	,    _a=0.1	,    _a=False	,    _a=1E-4	,    _a=False	,    _a=False	,    _a=False	,    _a=0.02	,    _a=1E-5	,    _a=32	,    _a=None	,    _a=None	,    **_a	,    )  ->      Optional[Any]:


           """simple docstring"""


           super().__init__(**_a  )

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	image_size
           SCREAMING_SNAKE_CASE__   :      str      		=	patch_size
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	num_channels
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	embed_dim
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	use_conv_embed
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	hidden_sizes
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	depths
           SCREAMING_SNAKE_CASE__   :      Any      		=	focal_levels
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	focal_windows
           SCREAMING_SNAKE_CASE__   :      Any      		=	hidden_act
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	mlp_ratio
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	hidden_dropout_prob
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	drop_path_rate
           SCREAMING_SNAKE_CASE__   :      str      		=	use_layerscale
           SCREAMING_SNAKE_CASE__   :      int      		=	layerscale_value
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	use_post_layernorm
           SCREAMING_SNAKE_CASE__   :      Any      		=	use_post_layernorm_in_modulation
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	normalize_modulator
           SCREAMING_SNAKE_CASE__   :      str      		=	initializer_range
           SCREAMING_SNAKE_CASE__   :      Any      		=	layer_norm_eps
           SCREAMING_SNAKE_CASE__   :      Any      		=	encoder_stride
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	["""stem"""] + [f'''stage{idx}''' for idx in range(1	,    len(self.depths  ) + 1  )]
           SCREAMING_SNAKE_CASE__		,		SCREAMING_SNAKE_CASE__   :      Dict      		=	get_aligned_output_features_output_indices(
               out_features=_a	,    out_indices=_a	,    stage_names=self.stage_names  )




