





import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class 				__lowerCAmelCase       (    UpperCamelCase__						,				unittest.TestCase):
      _lowercase				:					Optional[Any]						=			MgpstrTokenizer
      _lowercase				:					List[Any]						=			False
      _lowercase				:					List[str]						=			{}
      _lowercase				:					List[Any]						=			False







      def    _lowercase  (    self							)   ->						Optional[Any]:



        '''simple docstring'''




        super().setUp()

        # fmt: off
        a__	:					List[str]										=["[GO]", "[s]", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        # fmt: on
        a__	:					Tuple										=dict(zip(lowerCAmelCase__		,      range(len(lowerCAmelCase__							)							)							)							)

        a__	:					Union[str, Any]										=os.path.join(self.tmpdirname		,      VOCAB_FILES_NAMES["vocab_file"]							)
        with open(self.vocab_file		,      "w"		,      encoding="utf-8"							) as fp:
          fp.write(json.dumps(lowerCAmelCase__							) + "\n"							)







      def    _lowercase  (    self		,      **lowerCAmelCase__							)   ->						Tuple:



        '''simple docstring'''




        return MgpstrTokenizer.from_pretrained(self.tmpdirname		,      **lowerCAmelCase__							)







      def    _lowercase  (    self		,      lowerCAmelCase__							)   ->						Optional[Any]:



        '''simple docstring'''




        a__	:					Any										="tester"
        a__	:					Dict										="tester"
        return input_text, output_text







      @unittest.skip("MGP-STR always lower cases letters."							)
      def    _lowercase  (    self							)   ->						Tuple:



        '''simple docstring'''




        pass







      def    _lowercase  (    self							)   ->						Dict:



        '''simple docstring'''




        a__	:					Dict										=self.get_tokenizers(do_lower_case=lowerCAmelCase__							)
        for tokenizer in tokenizers:
          with self.subTest(F'''{tokenizer.__class__.__name__}'''							):
            a__	:					Dict										="[SPECIAL_TOKEN]"

            tokenizer.add_special_tokens({"cls_token": special_token}							)
            a__	:					Optional[int]										=tokenizer.encode([special_token]		,      add_special_tokens=lowerCAmelCase__							)
            self.assertEqual(len(lowerCAmelCase__							)		,      1							)

            a__	:					Optional[int]										=tokenizer.decode(lowerCAmelCase__		,      skip_special_tokens=lowerCAmelCase__							)
            self.assertTrue(special_token not in decoded							)







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



        '''simple docstring'''




        a__	:					List[str]										=self.get_tokenizers()
        for tokenizer in tokenizers:
          with self.subTest(F'''{tokenizer.__class__.__name__}'''							):
            a__					,							a__	:					Optional[int]										=self.get_input_output_texts(lowerCAmelCase__							)

            a__	:					int										=tokenizer.tokenize(lowerCAmelCase__							)
            a__	:					Any										=tokenizer.convert_tokens_to_ids(lowerCAmelCase__							)
            a__	:					Dict										=tokenizer.encode(lowerCAmelCase__		,      add_special_tokens=lowerCAmelCase__							)
            self.assertListEqual(lowerCAmelCase__		,      lowerCAmelCase__							)

            a__	:					List[Any]										=tokenizer.convert_ids_to_tokens(lowerCAmelCase__							)
            self.assertNotEqual(len(lowerCAmelCase__							)		,      0							)
            a__	:					Optional[Any]										=tokenizer.decode(lowerCAmelCase__							)
            self.assertIsInstance(lowerCAmelCase__		,      lowerCAmelCase__							)

            self.assertEqual(text_a.replace(" "		,      ""							)		,      lowerCAmelCase__							)







      @unittest.skip("MGP-STR tokenizer only handles one sequence."							)
      def    _lowercase  (    self							)   ->						Any:



        '''simple docstring'''




        pass







      @unittest.skip("inputs cannot be pretokenized in MgpstrTokenizer"							)
      def    _lowercase  (    self							)   ->						List[Any]:



        '''simple docstring'''




        pass













from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase	:	Dict		     =       logging.get_logger(__name__)

UpperCAmelCase	:	Tuple		     =       {
    """caidas/swin2sr-classicalsr-x2-64""": (
        """https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"""
    ),
}







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Any						=			"""swin2sr"""

      _lowercase				:					Tuple						=			{
          """hidden_size""": """embed_dim""",
          """num_attention_heads""": """num_heads""",
          """num_hidden_layers""": """num_layers""",
      }







      def __init__(    self		,      lowerCAmelCase__=6_4		,      lowerCAmelCase__=1		,      lowerCAmelCase__=3		,      lowerCAmelCase__=1_8_0		,      lowerCAmelCase__=[6, 6, 6, 6, 6, 6]		,      lowerCAmelCase__=[6, 6, 6, 6, 6, 6]		,      lowerCAmelCase__=8		,      lowerCAmelCase__=2.0		,      lowerCAmelCase__=True		,      lowerCAmelCase__=0.0		,      lowerCAmelCase__=0.0		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__="gelu"		,      lowerCAmelCase__=False		,      lowerCAmelCase__=0.02		,      lowerCAmelCase__=1E-5		,      lowerCAmelCase__=2		,      lowerCAmelCase__=1.0		,      lowerCAmelCase__="1conv"		,      lowerCAmelCase__="pixelshuffle"		,      **lowerCAmelCase__		,      )   ->						int:



        '''simple docstring'''




        super().__init__(**lowerCAmelCase__							)

        a__	:					Optional[Any]										=image_size
        a__	:					Dict										=patch_size
        a__	:					Tuple										=num_channels
        a__	:					Union[str, Any]										=embed_dim
        a__	:					Optional[Any]										=depths
        a__	:					List[str]										=len(lowerCAmelCase__							)
        a__	:					Any										=num_heads
        a__	:					Any										=window_size
        a__	:					str										=mlp_ratio
        a__	:					List[str]										=qkv_bias
        a__	:					Dict										=hidden_dropout_prob
        a__	:					List[str]										=attention_probs_dropout_prob
        a__	:					Dict										=drop_path_rate
        a__	:					Optional[Any]										=hidden_act
        a__	:					Union[str, Any]										=use_absolute_embeddings
        a__	:					Optional[Any]										=layer_norm_eps
        a__	:					List[Any]										=initializer_range
        a__	:					int										=upscale
        a__	:					Optional[int]										=img_range
        a__	:					Any										=resi_connection
        a__	:					Optional[Any]										=upsampler






