




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


_lowerCamelCase			:	str							 =     logging.get_logger(__name__)

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

_lowerCamelCase			:	Any							 =     {
    """vocab_file""": {
        """bert-base-uncased""": """https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt""",
        """bert-large-uncased""": """https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt""",
        """bert-base-cased""": """https://huggingface.co/bert-base-cased/resolve/main/vocab.txt""",
        """bert-large-cased""": """https://huggingface.co/bert-large-cased/resolve/main/vocab.txt""",
        """bert-base-multilingual-uncased""": (
            """https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt"""
        ),
        """bert-base-multilingual-cased""": """https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt""",
        """bert-base-chinese""": """https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt""",
        """bert-base-german-cased""": """https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt""",
        """bert-large-uncased-whole-word-masking""": (
            """https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt"""
        ),
        """bert-large-cased-whole-word-masking""": (
            """https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt"""
        ),
        """bert-large-uncased-whole-word-masking-finetuned-squad""": (
            """https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"""
        ),
        """bert-large-cased-whole-word-masking-finetuned-squad""": (
            """https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"""
        ),
        """bert-base-cased-finetuned-mrpc""": (
            """https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt"""
        ),
        """bert-base-german-dbmdz-cased""": """https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt""",
        """bert-base-german-dbmdz-uncased""": (
            """https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt"""
        ),
        """TurkuNLP/bert-base-finnish-cased-v1""": (
            """https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt"""
        ),
        """TurkuNLP/bert-base-finnish-uncased-v1""": (
            """https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt"""
        ),
        """wietsedv/bert-base-dutch-cased""": (
            """https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt"""
        ),
    },
    """tokenizer_file""": {
        """bert-base-uncased""": """https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json""",
        """bert-large-uncased""": """https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json""",
        """bert-base-cased""": """https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json""",
        """bert-large-cased""": """https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json""",
        """bert-base-multilingual-uncased""": (
            """https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json"""
        ),
        """bert-base-multilingual-cased""": (
            """https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json"""
        ),
        """bert-base-chinese""": """https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json""",
        """bert-base-german-cased""": """https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json""",
        """bert-large-uncased-whole-word-masking""": (
            """https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json"""
        ),
        """bert-large-cased-whole-word-masking""": (
            """https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json"""
        ),
        """bert-large-uncased-whole-word-masking-finetuned-squad""": (
            """https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"""
        ),
        """bert-large-cased-whole-word-masking-finetuned-squad""": (
            """https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"""
        ),
        """bert-base-cased-finetuned-mrpc""": (
            """https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json"""
        ),
        """bert-base-german-dbmdz-cased""": (
            """https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json"""
        ),
        """bert-base-german-dbmdz-uncased""": (
            """https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json"""
        ),
        """TurkuNLP/bert-base-finnish-cased-v1""": (
            """https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json"""
        ),
        """TurkuNLP/bert-base-finnish-uncased-v1""": (
            """https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json"""
        ),
        """wietsedv/bert-base-dutch-cased""": (
            """https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json"""
        ),
    },
}

_lowerCamelCase			:	Optional[int]							 =     {
    """bert-base-uncased""": 512,
    """bert-large-uncased""": 512,
    """bert-base-cased""": 512,
    """bert-large-cased""": 512,
    """bert-base-multilingual-uncased""": 512,
    """bert-base-multilingual-cased""": 512,
    """bert-base-chinese""": 512,
    """bert-base-german-cased""": 512,
    """bert-large-uncased-whole-word-masking""": 512,
    """bert-large-cased-whole-word-masking""": 512,
    """bert-large-uncased-whole-word-masking-finetuned-squad""": 512,
    """bert-large-cased-whole-word-masking-finetuned-squad""": 512,
    """bert-base-cased-finetuned-mrpc""": 512,
    """bert-base-german-dbmdz-cased""": 512,
    """bert-base-german-dbmdz-uncased""": 512,
    """TurkuNLP/bert-base-finnish-cased-v1""": 512,
    """TurkuNLP/bert-base-finnish-uncased-v1""": 512,
    """wietsedv/bert-base-dutch-cased""": 512,
}

_lowerCamelCase			:	List[str]							 =     {
    """bert-base-uncased""": {"""do_lower_case""": True},
    """bert-large-uncased""": {"""do_lower_case""": True},
    """bert-base-cased""": {"""do_lower_case""": False},
    """bert-large-cased""": {"""do_lower_case""": False},
    """bert-base-multilingual-uncased""": {"""do_lower_case""": True},
    """bert-base-multilingual-cased""": {"""do_lower_case""": False},
    """bert-base-chinese""": {"""do_lower_case""": False},
    """bert-base-german-cased""": {"""do_lower_case""": False},
    """bert-large-uncased-whole-word-masking""": {"""do_lower_case""": True},
    """bert-large-cased-whole-word-masking""": {"""do_lower_case""": False},
    """bert-large-uncased-whole-word-masking-finetuned-squad""": {"""do_lower_case""": True},
    """bert-large-cased-whole-word-masking-finetuned-squad""": {"""do_lower_case""": False},
    """bert-base-cased-finetuned-mrpc""": {"""do_lower_case""": False},
    """bert-base-german-dbmdz-cased""": {"""do_lower_case""": False},
    """bert-base-german-dbmdz-uncased""": {"""do_lower_case""": True},
    """TurkuNLP/bert-base-finnish-cased-v1""": {"""do_lower_case""": False},
    """TurkuNLP/bert-base-finnish-uncased-v1""": {"""do_lower_case""": True},
    """wietsedv/bert-base-dutch-cased""": {"""do_lower_case""": False},
}


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   VOCAB_FILES_NAMES
    UpperCAmelCase__													=   PRETRAINED_VOCAB_FILES_MAP
    UpperCAmelCase__													=   PRETRAINED_INIT_CONFIGURATION
    UpperCAmelCase__													=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    UpperCAmelCase__													=   BertTokenizer


    def __init__(    self   :			str      ,				UpperCAmelCase__   :			Optional[Any]=None      ,				UpperCAmelCase__   :			Optional[int]=None      ,				UpperCAmelCase__   :			Optional[int]=True      ,				UpperCAmelCase__   :			str="[UNK]"      ,				UpperCAmelCase__   :			Optional[Any]="[SEP]"      ,				UpperCAmelCase__   :			Any="[PAD]"      ,				UpperCAmelCase__   :			str="[CLS]"      ,				UpperCAmelCase__   :			str="[MASK]"      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Tuple=None      ,				**UpperCAmelCase__   :			Tuple      ,				)		->Tuple:





           '''simple docstring'''

           super().__init__(
               UpperCAmelCase__      ,				tokenizer_file=UpperCAmelCase__      ,				do_lower_case=UpperCAmelCase__      ,				unk_token=UpperCAmelCase__      ,				sep_token=UpperCAmelCase__      ,				pad_token=UpperCAmelCase__      ,				cls_token=UpperCAmelCase__      ,				mask_token=UpperCAmelCase__      ,				tokenize_chinese_chars=UpperCAmelCase__      ,				strip_accents=UpperCAmelCase__      ,				**UpperCAmelCase__      ,				)

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

           A__   				=					do_lower_case


    def  SCREAMING_SNAKE_CASE							(    self   :			List[str]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Tuple=None)		->Tuple:





           '''simple docstring'''

           A__   				=					[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   :			Any      ,				UpperCAmelCase__   :			List[int]      ,				UpperCAmelCase__   :			Optional[List[int]] = None)		->List[int]:





           '''simple docstring'''

           A__   				=					[self.sep_token_id]
           A__   				=					[self.cls_token_id]
           if token_ids_a is None:
                  return len(cls + token_ids_a + sep) * [0]
           return len(cls + token_ids_a + sep) * [0] + len(token_ids_a + sep) * [1]





    def  SCREAMING_SNAKE_CASE							(    self   :			Any      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Optional[str] = None)		->Tuple[str]:





           '''simple docstring'''

           A__   				=					self._tokenizer.model.save(UpperCAmelCase__      ,				name=UpperCAmelCase__)
           return tuple(UpperCAmelCase__)








import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin


@skip_mps
class        UpperCamelCase_					(				UpperCAmelCase__	,      UpperCAmelCase__	,      unittest.TestCase  ):

    '''simple docstring'''






    UpperCAmelCase__													=   IFInpaintingPipeline
    UpperCAmelCase__													=   TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'''width''', '''height'''}
    UpperCAmelCase__													=   TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
    UpperCAmelCase__													=   PipelineTesterMixin.required_optional_params - {'''latents'''}


    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->Dict:





           '''simple docstring'''

           return self._get_dummy_components()


    def  SCREAMING_SNAKE_CASE							(    self   :			int      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			int=0)		->int:





           '''simple docstring'''

           if str(UpperCAmelCase__).startswith('''mps'''):
                  A__   				=					torch.manual_seed(UpperCAmelCase__)
           else:
                  A__   				=					torch.Generator(device=UpperCAmelCase__).manual_seed(UpperCAmelCase__)

           A__   				=					floats_tensor((1, 3, 32, 32)      ,				rng=random.Random(UpperCAmelCase__)).to(UpperCAmelCase__)
           A__   				=					floats_tensor((1, 3, 32, 32)      ,				rng=random.Random(UpperCAmelCase__)).to(UpperCAmelCase__)

           A__   				=					{
               '''prompt''': '''A painting of a squirrel eating a burger''',
               '''image''': image,
               '''mask_image''': mask_image,
               '''generator''': generator,
               '''num_inference_steps''': 2,
               '''output_type''': '''numpy''',
           }

           return inputs


    @unittest.skipIf(
        torch_device != '''cuda''' or not is_xformers_available()      ,				reason='''XFormers attention is only available with CUDA and `xformers` installed'''      ,				)
    def  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->List[Any]:





           '''simple docstring'''

           self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->int:





           '''simple docstring'''

           self._test_save_load_optional_components()


    @unittest.skipIf(torch_device != '''cuda'''      ,				reason='''float16 requires CUDA''')
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any])		->List[str]:





           '''simple docstring'''

           super().test_save_load_floataa(expected_max_diff=1e-1)


    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->List[Any]:





           '''simple docstring'''

           self._test_attention_slicing_forward_pass(expected_max_diff=1e-2)


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





           '''simple docstring'''

           self._test_save_load_local()





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





           '''simple docstring'''

           self._test_inference_batch_single_identical(
               expected_max_diff=1e-2      ,				)


