'''simple docstring'''




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


__UpperCAmelCase					=logging.get_logger(__name__)

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

__UpperCAmelCase					=[
    "small",
    "small-base",
    "medium",
    "medium-base",
    "intermediate",
    "intermediate-base",
    "large",
    "large-base",
    "xlarge",
    "xlarge-base",
]

__UpperCAmelCase					={
    "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"
        ),
    },
}
__UpperCAmelCase					={f'funnel-transformer/{name}': 5_1_2 for name in _model_names}
__UpperCAmelCase					={f'funnel-transformer/{name}': {"do_lower_case": True} for name in _model_names}




class        a__ (  UpperCAmelCase__					):
     lowerCamelCase    :	int				=VOCAB_FILES_NAMES
     lowerCamelCase    :	Union[str, Any]				=PRETRAINED_VOCAB_FILES_MAP
     lowerCamelCase    :	Any				=PRETRAINED_INIT_CONFIGURATION
     lowerCamelCase    :	List[str]				=FunnelTokenizer
     lowerCamelCase    :	List[Any]				=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     lowerCamelCase    :	int				=2






     def __init__(					self						:						Optional[int]    ,							a						:						List[str]=None    ,							a						:						Optional[int]=None    ,							a						:						str=True    ,							a						:						List[str]="<unk>"    ,							a						:						List[str]="<sep>"    ,							a						:						Union[str, Any]="<pad>"    ,							a						:						Any="<cls>"    ,							a						:						str="<mask>"    ,							a						:						Dict="<s>"    ,							a						:						Tuple="</s>"    ,							a						:						List[Any]=True    ,							a						:						Union[str, Any]=True    ,							a						:						Optional[int]=None    ,							a						:						Union[str, Any]="##"    ,							**a						:						Dict    ,							):





         """simple docstring"""



         super().__init__(
             a    ,							tokenizer_file=a    ,							do_lower_case=a    ,							unk_token=a    ,							sep_token=a    ,							pad_token=a    ,							cls_token=a    ,							mask_token=a    ,							bos_token=a    ,							eos_token=a    ,							clean_text=a    ,							tokenize_chinese_chars=a    ,							strip_accents=a    ,							wordpieces_prefix=a    ,							**a    ,							)

         __lowerCamelCase            =    json.loads(self.backend_tokenizer.normalizer.__getstate__()       )
         if (
             normalizer_state.get('''lowercase'''    ,							a       ) != do_lower_case
             or normalizer_state.get('''strip_accents'''    ,							a       ) != strip_accents
             or normalizer_state.get('''handle_chinese_chars'''    ,							a       ) != tokenize_chinese_chars
         ):
             __lowerCamelCase            =    getattr(a    ,							normalizer_state.pop('''type'''       )       )
             __lowerCamelCase            =    do_lower_case
             __lowerCamelCase            =    strip_accents
             __lowerCamelCase            =    tokenize_chinese_chars
             __lowerCamelCase            =    normalizer_class(**a       )

         __lowerCamelCase            =    do_lower_case






     def   SCREAMING_SNAKE_CASE__  (					self						:						Dict    ,							a						:						List[Any]    ,							a						:						List[str]=None       ):





         """simple docstring"""



         __lowerCamelCase            =    [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   SCREAMING_SNAKE_CASE__  (					self						:						List[Any]    ,							a						:						List[int]    ,							a						:						Optional[List[int]] = None       ):





         """simple docstring"""



         __lowerCamelCase            =    [self.sep_token_id]
         __lowerCamelCase            =    [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   SCREAMING_SNAKE_CASE__  (					self						:						Tuple    ,							a						:						str    ,							a						:						Optional[str] = None       ):





         """simple docstring"""



         __lowerCamelCase            =    self._tokenizer.model.save(a    ,							name=a       )
         return tuple(a       )

'''simple docstring'''




import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch




@require_torch
class        a__ :






     @property
     def   SCREAMING_SNAKE_CASE__  (					self						:						str       ):





         """simple docstring"""



         return self.get_dummy_input()






     @property
     def   SCREAMING_SNAKE_CASE__  (					self						:						str       ):





         """simple docstring"""



         if self.block_type == "down":
             return (4, 32, 16, 16)
         elif self.block_type == "mid":
             return (4, 32, 32, 32)
         elif self.block_type == "up":
             return (4, 32, 64, 64)

         raise ValueError(f"""'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'."""       )






     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[Any]    ,							a						:						List[Any]=True    ,							a						:						Dict=False    ,							a						:						Optional[Any]=False    ,							a						:						List[Any]=False    ,							):





         """simple docstring"""



         __lowerCamelCase            =    4
         __lowerCamelCase            =    32
         __lowerCamelCase            =    (32, 32)

         __lowerCamelCase            =    torch.manual_seed(0       )
         __lowerCamelCase            =    torch.device(a       )
         __lowerCamelCase            =    (batch_size, num_channels) + sizes
         __lowerCamelCase            =    randn_tensor(a    ,							generator=a    ,							device=a       )
         __lowerCamelCase            =    {'''hidden_states''': hidden_states}

         if include_temb:
             __lowerCamelCase            =    1_28
             __lowerCamelCase            =    randn_tensor((batch_size, temb_channels)    ,							generator=a    ,							device=a       )

         if include_res_hidden_states_tuple:
             __lowerCamelCase            =    torch.manual_seed(1       )
             __lowerCamelCase            =    (randn_tensor(a    ,							generator=a    ,							device=a       ),)

         if include_encoder_hidden_states:
             __lowerCamelCase            =    floats_tensor((batch_size, 32, 32)       ).to(a       )

         if include_skip_sample:
             __lowerCamelCase            =    randn_tensor(((batch_size, 3) + sizes)    ,							generator=a    ,							device=a       )

         return dummy_input






     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[int]       ):





         """simple docstring"""



         __lowerCamelCase            =    {
             '''in_channels''': 32,
             '''out_channels''': 32,
             '''temb_channels''': 1_28,
         }
         if self.block_type == "up":
             __lowerCamelCase            =    32

         if self.block_type == "mid":
             init_dict.pop('''out_channels'''       )

         __lowerCamelCase            =    self.dummy_input
         return init_dict, inputs_dict






     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[Any]    ,							a						:						List[str]       ):





         """simple docstring"""



         __lowerCamelCase      ,    __lowerCamelCase            =    self.prepare_init_args_and_inputs_for_common()
         __lowerCamelCase            =    self.block_class(**a       )
         unet_block.to(a       )
         unet_block.eval()

         with torch.no_grad():
             __lowerCamelCase            =    unet_block(**a       )

         if isinstance(a    ,							a       ):
             __lowerCamelCase            =    output[0]

         self.assertEqual(output.shape    ,							self.output_shape       )

         __lowerCamelCase            =    output[0, -1, -3:, -3:]
         __lowerCamelCase            =    torch.tensor(a       ).to(a       )
         assert torch_all_close(output_slice.flatten()    ,							a    ,							atol=5e-3       )






     @unittest.skipIf(torch_device == '''mps'''    ,							'''Training is not supported in mps'''       )
     def   SCREAMING_SNAKE_CASE__  (					self						:						Any       ):





         """simple docstring"""



         __lowerCamelCase      ,    __lowerCamelCase            =    self.prepare_init_args_and_inputs_for_common()
         __lowerCamelCase            =    self.block_class(**a       )
         model.to(a       )
         model.train()
         __lowerCamelCase            =    model(**a       )

         if isinstance(a    ,							a       ):
             __lowerCamelCase            =    output[0]

         __lowerCamelCase            =    torch.device(a       )
         __lowerCamelCase            =    randn_tensor(output.shape    ,							device=a       )
         __lowerCamelCase            =    torch.nn.functional.mse_loss(a    ,							a       )
         loss.backward()
