


"""simple docstring"""



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


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

__snake_case             =   {
    """vocab_file""": {
        """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """unc-nlp/lxmert-base-uncased""": (
            """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

__snake_case             =   {
    """unc-nlp/lxmert-base-uncased""": 512,
}

__snake_case             =   {
    """unc-nlp/lxmert-base-uncased""": {"""do_lower_case""": True},
}







class _lowerCAmelCase    (				snake_case_     ):
   __UpperCAmelCase			:	Dict							  =  VOCAB_FILES_NAMES
   __UpperCAmelCase			:	str							  =  PRETRAINED_VOCAB_FILES_MAP
   __UpperCAmelCase			:	Any							  =  PRETRAINED_INIT_CONFIGURATION
   __UpperCAmelCase			:	List[Any]							  =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   __UpperCAmelCase			:	Optional[int]							  =  LxmertTokenizer







   def __init__(     self						,     UpperCamelCase__=None						,     UpperCamelCase__=None						,     UpperCamelCase__=True						,     UpperCamelCase__="[UNK]"						,     UpperCamelCase__="[SEP]"						,     UpperCamelCase__="[PAD]"						,     UpperCamelCase__="[CLS]"						,     UpperCamelCase__="[MASK]"						,     UpperCamelCase__=True						,     UpperCamelCase__=None						,     **UpperCamelCase__						,     )     ->		Union[str, Any]:

       '''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__						,     )

       snake_case   :				Dict				 =   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
       ):
           snake_case   :				int				 =   getattr(UpperCamelCase__						,     normalizer_state.pop("type"						)						)
           snake_case   :				List[Any]				 =   do_lower_case
           snake_case   :				int				 =   strip_accents
           snake_case   :				int				 =   tokenize_chinese_chars
           snake_case   :				List[str]				 =   normalizer_class(**UpperCamelCase__						)

       snake_case   :				int				 =   do_lower_case







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						,     UpperCamelCase__=None						)     ->		Union[str, Any]:

       '''simple docstring'''




       snake_case   :				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						,     UpperCamelCase__						,     UpperCamelCase__ = None						)     ->		List[int]:

       '''simple docstring'''




       snake_case   :				Dict				 =   [self.sep_token_id]
       snake_case   :				Union[str, Any]				 =   [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 			lowerCamelCase		(     self						,     UpperCamelCase__						,     UpperCamelCase__ = None						)     ->		Tuple[str]:

       '''simple docstring'''




       snake_case   :				List[str]				 =   self._tokenizer.model.save(UpperCamelCase__						,     name=UpperCamelCase__						)
       return tuple(UpperCamelCase__						)









"""simple docstring"""



import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class _lowerCAmelCase    (				unittest.TestCase     ):







   @property
   def 			lowerCamelCase		(     self						)     ->		str:

       '''simple docstring'''




       torch.manual_seed(0						)
       snake_case   :				int				 =   UNetaDModel(
           block_out_channels=(32, 64)						,     layers_per_block=2						,     sample_size=32						,     in_channels=3						,     out_channels=3						,     down_block_types=("DownBlock2D", "AttnDownBlock2D")						,     up_block_types=("AttnUpBlock2D", "UpBlock2D")						,     )
       return model







   def 			lowerCamelCase		(     self						)     ->		Any:

       '''simple docstring'''




       snake_case   :				Any				 =   self.dummy_uncond_unet
       snake_case   :				Tuple				 =   KarrasVeScheduler()

       snake_case   :				int				 =   KarrasVePipeline(unet=UpperCamelCase__						,     scheduler=UpperCamelCase__						)
       pipe.to(UpperCamelCase__						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case   :				Optional[Any]				 =   torch.manual_seed(0						)
       snake_case   :				List[Any]				 =   pipe(num_inference_steps=2						,     generator=UpperCamelCase__						,     output_type="numpy"						).images

       snake_case   :				Dict				 =   torch.manual_seed(0						)
       snake_case   :				Dict				 =   pipe(num_inference_steps=2						,     generator=UpperCamelCase__						,     output_type="numpy"						,     return_dict=UpperCamelCase__						)[0]

       snake_case   :				Tuple				 =   image[0, -3:, -3:, -1]
       snake_case   :				Tuple				 =   image_from_tuple[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       snake_case   :				int				 =   np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]						)

       assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-2
       assert np.abs(image_from_tuple_slice.flatten() - expected_slice						).max() < 1e-2







@slow
@require_torch
class _lowerCAmelCase    (				unittest.TestCase     ):







   def 			lowerCamelCase		(     self						)     ->		List[Any]:

       '''simple docstring'''




       snake_case   :				Optional[Any]				 =   "google/ncsnpp-celebahq-256"
       snake_case   :				List[str]				 =   UNetaDModel.from_pretrained(UpperCamelCase__						)
       snake_case   :				Optional[Any]				 =   KarrasVeScheduler()

       snake_case   :				Optional[int]				 =   KarrasVePipeline(unet=UpperCamelCase__						,     scheduler=UpperCamelCase__						)
       pipe.to(UpperCamelCase__						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case   :				Dict				 =   torch.manual_seed(0						)
       snake_case   :				Union[str, Any]				 =   pipe(num_inference_steps=20						,     generator=UpperCamelCase__						,     output_type="numpy"						).images

       snake_case   :				int				 =   image[0, -3:, -3:, -1]
       assert image.shape == (1, 256, 256, 3)
       snake_case   :				Any				 =   np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]						)

       assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-2





