


import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

   if is_vision_available():
      from transformers import MaskaFormerImageProcessor

if is_vision_available():
   from PIL import Image
class  SCREAMING_SNAKE_CASE__  :
      def __init__(       self				:       Union[str, Any]     ,							SCREAMING_SNAKE_CASE__				:       List[Any]     ,							SCREAMING_SNAKE_CASE__				:       Dict=2     ,							SCREAMING_SNAKE_CASE__				:       Dict=True     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]=False     ,							SCREAMING_SNAKE_CASE__				:       int=1_0     ,							SCREAMING_SNAKE_CASE__				:       List[Any]=3     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]=3_2 * 8     ,							SCREAMING_SNAKE_CASE__				:       Dict=3_2 * 8     ,							SCREAMING_SNAKE_CASE__				:       List[str]=4     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]=6_4     ,							)		->			str:
             a_					:		Optional[Any]							=  parent
             a_					:		List[Any]							=  batch_size
             a_					:		List[Any]							=  is_training
             a_					:		str							=  use_auxiliary_loss
             a_					:		str							=  num_queries
             a_					:		str							=  num_channels
             a_					:		Union[str, Any]							=  min_size
             a_					:		Union[str, Any]							=  max_size
             a_					:		int							=  num_labels
             a_					:		List[Any]							=  hidden_dim
             a_					:		int							=  hidden_dim
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			int:
             a_					:		Any							=  floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]     ).to(
                 SCREAMING_SNAKE_CASE__     )

             a_					:		int							=  torch.ones([self.batch_size, self.min_size, self.max_size]     ,							device=SCREAMING_SNAKE_CASE__     )

             a_					:		Any							=  (
                 torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]     ,							device=SCREAMING_SNAKE_CASE__     ) > 0.5
             ).float()
             a_					:		int							=  (torch.rand((self.batch_size, self.num_labels)     ,							device=SCREAMING_SNAKE_CASE__     ) > 0.5).long()

             a_					:		Any							=  self.get_config()
             return config, pixel_values, pixel_mask, mask_labels, class_labels
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Union[str, Any]:
             a_					:		Any							=  MaskaFormerConfig(
                 hidden_size=self.hidden_dim     ,							)
             a_					:		Tuple							=  self.num_queries
             a_					:		Tuple							=  self.num_labels

             a_					:		Optional[int]							=  [1, 1, 1, 1]
             a_					:		Union[str, Any]							=  self.num_channels

             a_					:		str							=  6_4
             a_					:		List[Any]							=  1_2_8
             a_					:		Tuple							=  self.hidden_dim
             a_					:		Dict							=  self.hidden_dim
             a_					:		Optional[Any]							=  self.hidden_dim
             return config
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			str:
             a_							,		a_							,		a_							,		a_							,		a_					:		List[str]							=  self.prepare_config_and_inputs()
             a_					:		Dict							=  {'pixel_values': pixel_values, 'pixel_mask': pixel_mask}
             return config, inputs_dict
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       int     )		->			Optional[Any]:
             a_					:		List[str]							=  output.encoder_hidden_states
             a_					:		Any							=  output.pixel_decoder_hidden_states
             a_					:		List[Any]							=  output.transformer_decoder_hidden_states

             self.parent.assertTrue(len(SCREAMING_SNAKE_CASE__     )     ,							len(config.backbone_config.depths     )     )
             self.parent.assertTrue(len(SCREAMING_SNAKE_CASE__     )     ,							len(config.backbone_config.depths     )     )
             self.parent.assertTrue(len(SCREAMING_SNAKE_CASE__     )     ,							config.decoder_layers     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     ,							SCREAMING_SNAKE_CASE__				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       List[Any]     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       List[str]=False     )		->			Optional[int]:
             with torch.no_grad():
                    a_					:		int							=  MaskaFormerModel(config=SCREAMING_SNAKE_CASE__     )
                    model.to(SCREAMING_SNAKE_CASE__     )
                    model.eval()

                    a_					:		Dict							=  model(pixel_values=SCREAMING_SNAKE_CASE__     ,							pixel_mask=SCREAMING_SNAKE_CASE__     )
                    a_					:		Union[str, Any]							=  model(SCREAMING_SNAKE_CASE__     ,							output_hidden_states=SCREAMING_SNAKE_CASE__     )

             self.parent.assertEqual(
                 output.transformer_decoder_last_hidden_state.shape     ,							(self.batch_size, self.num_queries, self.hidden_dim)     ,							)
             # let's ensure the other two hidden state exists
             self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None     )
             self.parent.assertTrue(output.encoder_last_hidden_state is not None     )

             if output_hidden_states:
                    self.check_output_hidden_state(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )

      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       str     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]     ,							SCREAMING_SNAKE_CASE__				:       Dict     )		->			str:
             a_					:		Dict							=  MaskaFormerForUniversalSegmentation(config=SCREAMING_SNAKE_CASE__     )
             model.to(SCREAMING_SNAKE_CASE__     )
             model.eval()

             def comm_check_on_output(SCREAMING_SNAKE_CASE__				:       List[Any]     ):
                    # let's still check that all the required stuff is there
                    self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None     )
                    self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None     )
                    self.parent.assertTrue(result.encoder_last_hidden_state is not None     )
                    # okay, now we need to check the logits shape
                    # due to the encoder compression, masks have a //4 spatial size
                    self.parent.assertEqual(
                        result.masks_queries_logits.shape     ,							(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)     ,							)
                    # + 1 for null class
                    self.parent.assertEqual(
                        result.class_queries_logits.shape     ,							(self.batch_size, self.num_queries, self.num_labels + 1)     )

             with torch.no_grad():
                    a_					:		str							=  model(pixel_values=SCREAMING_SNAKE_CASE__     ,							pixel_mask=SCREAMING_SNAKE_CASE__     )
                    a_					:		str							=  model(SCREAMING_SNAKE_CASE__     )

                    comm_check_on_output(SCREAMING_SNAKE_CASE__     )

                    a_					:		Tuple							=  model(
                        pixel_values=SCREAMING_SNAKE_CASE__     ,							pixel_mask=SCREAMING_SNAKE_CASE__     ,							mask_labels=SCREAMING_SNAKE_CASE__     ,							class_labels=SCREAMING_SNAKE_CASE__     )

             comm_check_on_output(SCREAMING_SNAKE_CASE__     )

             self.parent.assertTrue(result.loss is not None     )
             self.parent.assertEqual(result.loss.shape     ,							torch.Size([1]     )     )
@require_torch
class  SCREAMING_SNAKE_CASE__  (				lowercase__						,    lowercase__						,    unittest.TestCase			):
      snake_case__				:     Optional[int]        =						(MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
      snake_case__				:     List[Any]        =						{'''feature-extraction''': MaskaFormerModel} if is_torch_available() else {}

      snake_case__				:     Dict        =						False
      snake_case__				:     Optional[int]        =						False
      snake_case__				:     Tuple        =						False
      snake_case__				:     Union[str, Any]        =						False
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			str:
             a_					:		Optional[Any]							=  MaskaFormerModelTester(self     )
             a_					:		Union[str, Any]							=  ConfigTester(self     ,							config_class=SCREAMING_SNAKE_CASE__     ,							has_text_modality=SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			List[str]:
             self.config_tester.run_common_tests()
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			List[Any]:
             a_							,		a_					:		List[Any]							=  self.model_tester.prepare_config_and_inputs_for_common()
             self.model_tester.create_and_check_maskaformer_model(SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     ,							output_hidden_states=SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			Tuple:
             a_					:		List[Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*SCREAMING_SNAKE_CASE__     )
      @unittest.skip(reason='Mask2Former does not use inputs_embeds'     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Tuple:
             pass
      @unittest.skip(reason='Mask2Former does not have a get_input_embeddings method'     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Dict:
             pass
      @unittest.skip(reason='Mask2Former is not a generative model'     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			int:
             pass
      @unittest.skip(reason='Mask2Former does not use token embeddings'     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Dict:
             pass
      @require_torch_multi_gpu
      @unittest.skip(
          reason='Mask2Former has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'     )
      def        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			Tuple:
             pass
      @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			List[str]:
             pass
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			List[str]:
             a_							,		a_					:		Tuple							=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    a_					:		Dict							=  model_class(SCREAMING_SNAKE_CASE__     )
                    a_					:		str							=  inspect.signature(model.forward     )
                    # signature.parameters is an OrderedDict => so arg_names order is deterministic
                    a_					:		Optional[Any]							=  [*signature.parameters.keys()]

                    a_					:		List[str]							=  ['pixel_values']
                    self.assertListEqual(arg_names[:1]     ,							SCREAMING_SNAKE_CASE__     )
      @slow
      def        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			str:
             for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
                    a_					:		Any							=  MaskaFormerModel.from_pretrained(SCREAMING_SNAKE_CASE__     )
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       List[Any]     )		->			str:
             a_					:		List[str]							=  (self.model_tester.min_size,) * 2
             a_					:		Dict							=  {
                 'pixel_values': torch.randn((2, 3, *size)     ,							device=SCREAMING_SNAKE_CASE__     ),
                 'mask_labels': torch.randn((2, 1_0, *size)     ,							device=SCREAMING_SNAKE_CASE__     ),
                 'class_labels': torch.zeros(2     ,							1_0     ,							device=SCREAMING_SNAKE_CASE__     ).long(),
             }
             a_					:		Optional[int]							=  self.model_tester.get_config()

             a_					:		int							=  MaskaFormerForUniversalSegmentation(SCREAMING_SNAKE_CASE__     ).to(SCREAMING_SNAKE_CASE__     )
             a_					:		Tuple							=  model(**SCREAMING_SNAKE_CASE__     )
             self.assertTrue(outputs.loss is not None     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Optional[Any]:
             a_							,		a_					:		int							=  self.model_tester.prepare_config_and_inputs_for_common()
             self.model_tester.create_and_check_maskaformer_model(SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     ,							output_hidden_states=SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Tuple:
             a_							,		a_					:		Optional[Any]							=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    a_					:		Any							=  model_class(SCREAMING_SNAKE_CASE__     ).to(SCREAMING_SNAKE_CASE__     )
                    a_					:		str							=  model(**SCREAMING_SNAKE_CASE__     ,							output_attentions=SCREAMING_SNAKE_CASE__     )
                    self.assertTrue(outputs.attentions is not None     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			Dict:
             if not self.model_tester.is_training:
                    return

             a_					:		Optional[int]							=  self.all_model_classes[1]
             a_							,		a_							,		a_							,		a_							,		a_					:		int							=  self.model_tester.prepare_config_and_inputs()

             a_					:		int							=  model_class(SCREAMING_SNAKE_CASE__     )
             model.to(SCREAMING_SNAKE_CASE__     )
             model.train()

             a_					:		List[str]							=  model(SCREAMING_SNAKE_CASE__     ,							mask_labels=SCREAMING_SNAKE_CASE__     ,							class_labels=SCREAMING_SNAKE_CASE__     ).loss
             loss.backward()

      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			Optional[int]:
             a_					:		Dict							=  self.all_model_classes[1]
             a_							,		a_							,		a_							,		a_							,		a_					:		Tuple							=  self.model_tester.prepare_config_and_inputs()
             a_					:		Dict							=  True
             a_					:		Optional[int]							=  True

             a_					:		List[Any]							=  model_class(SCREAMING_SNAKE_CASE__     ).to(SCREAMING_SNAKE_CASE__     )
             model.train()

             a_					:		Union[str, Any]							=  model(SCREAMING_SNAKE_CASE__     ,							mask_labels=SCREAMING_SNAKE_CASE__     ,							class_labels=SCREAMING_SNAKE_CASE__     )

             a_					:		Union[str, Any]							=  outputs.encoder_hidden_states[0]
             encoder_hidden_states.retain_grad()

             a_					:		Dict							=  outputs.pixel_decoder_hidden_states[0]
             pixel_decoder_hidden_states.retain_grad()

             a_					:		Union[str, Any]							=  outputs.transformer_decoder_hidden_states[0]
             transformer_decoder_hidden_states.retain_grad()

             a_					:		List[str]							=  outputs.attentions[0]
             attentions.retain_grad()

             outputs.loss.backward(retain_graph=SCREAMING_SNAKE_CASE__     )

             self.assertIsNotNone(encoder_hidden_states.grad     )
             self.assertIsNotNone(pixel_decoder_hidden_states.grad     )
             self.assertIsNotNone(transformer_decoder_hidden_states.grad     )
             self.assertIsNotNone(attentions.grad     )
UpperCAmelCase_      : Dict  					=       1e-4







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

       """simple docstring"""

       a_					:		Any							=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'				)
       return image
@require_vision
@slow
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      @cached_property
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Tuple:
             return "facebook/mask2former-swin-small-coco-instance"
      @cached_property
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Tuple:
             return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints     ) if is_vision_available() else None
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			List[Any]:
             a_					:		Tuple							=  MaskaFormerModel.from_pretrained(self.model_checkpoints     ).to(SCREAMING_SNAKE_CASE__     )
             a_					:		Any							=  self.default_image_processor
             a_					:		Union[str, Any]							=  prepare_img()
             a_					:		List[Any]							=  image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors='pt'     ).to(SCREAMING_SNAKE_CASE__     )
             a_					:		List[str]							=  inputs['pixel_values'].shape
             # check size is divisible by 32
             self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0     )
             # check size
             self.assertEqual(SCREAMING_SNAKE_CASE__     ,							(1, 3, 3_8_4, 3_8_4)     )

             with torch.no_grad():
                    a_					:		Union[str, Any]							=  model(**SCREAMING_SNAKE_CASE__     )

             a_					:		Optional[Any]							=  torch.tensor(
                 [[-0.2790, -1.0717, -1.1668], [-0.5128, -0.3128, -0.4987], [-0.5832, 0.1971, -0.0197]]     ).to(SCREAMING_SNAKE_CASE__     )
             self.assertTrue(
                 torch.allclose(
                     outputs.encoder_last_hidden_state[0, 0, :3, :3]     ,							SCREAMING_SNAKE_CASE__     ,							atol=SCREAMING_SNAKE_CASE__     )     )

             a_					:		str							=  torch.tensor(
                 [[0.8973, 1.1847, 1.1776], [1.1934, 1.5040, 1.5128], [1.1153, 1.4486, 1.4951]]     ).to(SCREAMING_SNAKE_CASE__     )
             self.assertTrue(
                 torch.allclose(
                     outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]     ,							SCREAMING_SNAKE_CASE__     ,							atol=SCREAMING_SNAKE_CASE__     )     )

             a_					:		str							=  torch.tensor(
                 [[2.1152, 1.7000, -0.8603], [1.5808, 1.8004, -0.9353], [1.6043, 1.7495, -0.5999]]     ).to(SCREAMING_SNAKE_CASE__     )
             self.assertTrue(
                 torch.allclose(
                     outputs.transformer_decoder_last_hidden_state[0, :3, :3]     ,							SCREAMING_SNAKE_CASE__     ,							atol=SCREAMING_SNAKE_CASE__     )     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Dict:
             a_					:		str							=  MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints     ).to(SCREAMING_SNAKE_CASE__     ).eval()
             a_					:		List[Any]							=  self.default_image_processor
             a_					:		Tuple							=  prepare_img()
             a_					:		Optional[int]							=  image_processor(SCREAMING_SNAKE_CASE__     ,							return_tensors='pt'     ).to(SCREAMING_SNAKE_CASE__     )
             a_					:		Optional[Any]							=  inputs['pixel_values'].shape
             # check size is divisible by 32
             self.assertTrue((inputs_shape[-1] % 3_2) == 0 and (inputs_shape[-2] % 3_2) == 0     )
             # check size
             self.assertEqual(SCREAMING_SNAKE_CASE__     ,							(1, 3, 3_8_4, 3_8_4)     )

             with torch.no_grad():
                    a_					:		Union[str, Any]							=  model(**SCREAMING_SNAKE_CASE__     )
             # masks_queries_logits
             a_					:		Dict							=  outputs.masks_queries_logits
             self.assertEqual(
                 masks_queries_logits.shape     ,							(1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)     )
             a_					:		List[str]							=  [
                 [-8.7839, -9.0056, -8.8121],
                 [-7.4104, -7.0313, -6.5401],
                 [-6.6105, -6.3427, -6.4675],
             ]
             a_					:		Optional[Any]							=  torch.tensor(SCREAMING_SNAKE_CASE__     ).to(SCREAMING_SNAKE_CASE__     )
             self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]     ,							SCREAMING_SNAKE_CASE__     ,							atol=SCREAMING_SNAKE_CASE__     )     )
             # class_queries_logits
             a_					:		Tuple							=  outputs.class_queries_logits
             self.assertEqual(class_queries_logits.shape     ,							(1, model.config.num_queries, model.config.num_labels + 1)     )
             a_					:		Optional[int]							=  torch.tensor(
                 [
                     [1.8324, -8.0835, -4.1922],
                     [0.8450, -9.0050, -3.6053],
                     [0.3045, -7.7293, -3.0275],
                 ]     ).to(SCREAMING_SNAKE_CASE__     )
             self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]     ,							SCREAMING_SNAKE_CASE__     ,							atol=SCREAMING_SNAKE_CASE__     )     )

      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Any:
             a_					:		Tuple							=  MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints     ).to(SCREAMING_SNAKE_CASE__     ).eval()
             a_					:		List[str]							=  self.default_image_processor

             a_					:		List[str]							=  image_processor(
                 [np.zeros((3, 8_0_0, 1_3_3_3)     ), np.zeros((3, 8_0_0, 1_3_3_3)     )]     ,							segmentation_maps=[np.zeros((3_8_4, 3_8_4)     ).astype(np.floataa     ), np.zeros((3_8_4, 3_8_4)     ).astype(np.floataa     )]     ,							return_tensors='pt'     ,							)

             a_					:		Any							=  inputs['pixel_values'].to(SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  [el.to(SCREAMING_SNAKE_CASE__     ) for el in inputs['mask_labels']]
             a_					:		str							=  [el.to(SCREAMING_SNAKE_CASE__     ) for el in inputs['class_labels']]

             with torch.no_grad():
                    a_					:		Tuple							=  model(**SCREAMING_SNAKE_CASE__     )

             self.assertTrue(outputs.loss is not None     )







import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


SCREAMING_SNAKE_CASE_:Dict             =						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_:int             =						{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

SCREAMING_SNAKE_CASE_:Optional[Any]             =						[
    """small""",
    """small-base""",
    """medium""",
    """medium-base""",
    """intermediate""",
    """intermediate-base""",
    """large""",
    """large-base""",
    """xlarge""",
    """xlarge-base""",
]

SCREAMING_SNAKE_CASE_:int             =						{
    """vocab_file""": {
        """funnel-transformer/small""": """https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt""",
        """funnel-transformer/small-base""": """https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt""",
        """funnel-transformer/medium""": """https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt""",
        """funnel-transformer/medium-base""": (
            """https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt"""
        ),
        """funnel-transformer/intermediate""": (
            """https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt"""
        ),
        """funnel-transformer/intermediate-base""": (
            """https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt"""
        ),
        """funnel-transformer/large""": """https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt""",
        """funnel-transformer/large-base""": """https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt""",
        """funnel-transformer/xlarge""": """https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt""",
        """funnel-transformer/xlarge-base""": (
            """https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt"""
        ),
    },
    """tokenizer_file""": {
        """funnel-transformer/small""": """https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json""",
        """funnel-transformer/small-base""": (
            """https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json"""
        ),
        """funnel-transformer/medium""": """https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json""",
        """funnel-transformer/medium-base""": (
            """https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json"""
        ),
        """funnel-transformer/intermediate""": (
            """https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json"""
        ),
        """funnel-transformer/intermediate-base""": (
            """https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json"""
        ),
        """funnel-transformer/large""": """https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json""",
        """funnel-transformer/large-base""": (
            """https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json"""
        ),
        """funnel-transformer/xlarge""": """https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json""",
        """funnel-transformer/xlarge-base""": (
            """https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json"""
        ),
    },
}
SCREAMING_SNAKE_CASE_:int             =						{F"""funnel-transformer/{name}""": 512 for name in _model_names}
SCREAMING_SNAKE_CASE_:Dict             =						{F"""funnel-transformer/{name}""": {"""do_lower_case""": True} for name in _model_names}






class SCREAMING_SNAKE_CASE__     (		SCREAMING_SNAKE_CASE__    ):




    '''simple docstring'''






    __lowerCamelCase			: List[str]					=      VOCAB_FILES_NAMES
    __lowerCamelCase			: Union[str, Any]					=      PRETRAINED_VOCAB_FILES_MAP
    __lowerCamelCase			: str					=      PRETRAINED_INIT_CONFIGURATION
    __lowerCamelCase			: Tuple					=      FunnelTokenizer
    __lowerCamelCase			: str					=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    __lowerCamelCase			: int					=      2






    def __init__(       self,		lowerCamelCase__=None,		lowerCamelCase__=None,		lowerCamelCase__=True,		lowerCamelCase__="<unk>",		lowerCamelCase__="<sep>",		lowerCamelCase__="<pad>",		lowerCamelCase__="<cls>",		lowerCamelCase__="<mask>",		lowerCamelCase__="<s>",		lowerCamelCase__="</s>",		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=None,		lowerCamelCase__="##",		**lowerCamelCase__,		):
        super().__init__(
            lowerCamelCase__,		tokenizer_file=lowerCamelCase__,		do_lower_case=lowerCamelCase__,		unk_token=lowerCamelCase__,		sep_token=lowerCamelCase__,		pad_token=lowerCamelCase__,		cls_token=lowerCamelCase__,		mask_token=lowerCamelCase__,		bos_token=lowerCamelCase__,		eos_token=lowerCamelCase__,		clean_text=lowerCamelCase__,		tokenize_chinese_chars=lowerCamelCase__,		strip_accents=lowerCamelCase__,		wordpieces_prefix=lowerCamelCase__,		**lowerCamelCase__,		)

        A :       List[str]          =   json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
        if (
            normalizer_state.get("""lowercase""",		lowerCamelCase__		) != do_lower_case
            or normalizer_state.get("""strip_accents""",		lowerCamelCase__		) != strip_accents
            or normalizer_state.get("""handle_chinese_chars""",		lowerCamelCase__		) != tokenize_chinese_chars
        ):
            A :       Optional[Any]          =   getattr(lowerCamelCase__,		normalizer_state.pop("""type"""		)		)
            A :       Union[str, Any]          =   do_lower_case
            A :       List[Any]          =   strip_accents
            A :       Optional[int]          =   tokenize_chinese_chars
            A :       Dict          =   normalizer_class(**lowerCamelCase__		)

        A :       List[Any]          =   do_lower_case






    def 			_lowerCAmelCase					(       self,		lowerCamelCase__,		lowerCamelCase__=None		):
        A :       Union[str, Any]          =   [self.cls_token_id] + token_ids_a + [self.sep_token_id]

        if token_ids_a:
            output += token_ids_a + [self.sep_token_id]

        return output






    def 			_lowerCAmelCase					(       self,		lowerCamelCase__,		lowerCamelCase__ = None		):
        A :       Any          =   [self.sep_token_id]
        A :       Any          =   [self.cls_token_id]
        if token_ids_a is None:
            return len(cls		) * [self.cls_token_type_id] + len(token_ids_a + sep		) * [0]
        return len(cls		) * [self.cls_token_type_id] + len(token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]






    def 			_lowerCAmelCase					(       self,		lowerCamelCase__,		lowerCamelCase__ = None		):
        A :       int          =   self._tokenizer.model.save(lowerCamelCase__,		name=lowerCamelCase__		)
        return tuple(lowerCamelCase__		)


