

"""simple docstring"""


import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion_safe import StableDiffusionPipelineSafe as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import require_torch_gpu

class      __a							(unittest.TestCase):






     '''simple docstring'''

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


           """simple docstring"""


           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()

     @property
     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Tuple      		=	1
           SCREAMING_SNAKE_CASE__   :      Dict      		=	3
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	(32, 32)

           SCREAMING_SNAKE_CASE__   :      Any      		=	floats_tensor((batch_size, num_channels) + sizes	,    rng=random.Random(0  )  ).to(_a  )
           return image

     @property
     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           torch.manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	UNetaDConditionModel(
               block_out_channels=(32, 64)	,    layers_per_block=2	,    sample_size=32	,    in_channels=4	,    out_channels=4	,    down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")	,    up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")	,    cross_attention_dim=32	,    )
           return model

     @property
     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           torch.manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	AutoencoderKL(
               block_out_channels=[32, 64]	,    in_channels=3	,    out_channels=3	,    down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]	,    up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]	,    latent_channels=4	,    )
           return model

     @property
     def 					_a			(						self  )  ->      Any:


           """simple docstring"""


           torch.manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	CLIPTextConfig(
               bos_token_id=0	,    eos_token_id=2	,    hidden_size=32	,    intermediate_size=37	,    layer_norm_eps=1E-0_5	,    num_attention_heads=4	,    num_hidden_layers=5	,    pad_token_id=1	,    vocab_size=1_000	,    )
           return CLIPTextModel(_a  )

     @property
     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           def extract(*_a	,    **_a  ):

                 class      __a							:






                      '''simple docstring'''

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


                            """simple docstring"""


                            SCREAMING_SNAKE_CASE__   :      Dict      		=	torch.ones([0]  )





                      def 					_a			(						self	,    _a  )  ->      List[str]:


                            """simple docstring"""


                            self.pixel_values.to(_a  )
                            return self





                 return Out()

           return extract

     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Any      		=	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	self.dummy_cond_unet
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	DDIMScheduler(
               beta_start=0.00_085	,    beta_end=0.012	,    beta_schedule="""scaled_linear"""	,    clip_sample=_a	,    set_alpha_to_one=_a	,    )

           SCREAMING_SNAKE_CASE__   :      str      		=	self.dummy_vae
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	self.dummy_text_encoder
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""  )

           # make sure here that pndm scheduler skips prk
           SCREAMING_SNAKE_CASE__   :      Dict      		=	StableDiffusionPipeline(
               unet=_a	,    scheduler=_a	,    vae=_a	,    text_encoder=_a	,    tokenizer=_a	,    safety_checker=_a	,    feature_extractor=self.dummy_extractor	,    )
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	sd_pipe.to(_a  )
           sd_pipe.set_progress_bar_config(disable=_a  )

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	"""A painting of a squirrel eating a burger"""

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	torch.Generator(device=_a  ).manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      int      		=	sd_pipe([prompt]	,    generator=_a	,    guidance_scale=6.0	,    num_inference_steps=2	,    output_type="""np"""  )
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	output.images

           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	torch.Generator(device=_a  ).manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      Any      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=6.0	,    num_inference_steps=2	,    output_type="""np"""	,    return_dict=_a	,    )[0]

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	image_from_tuple[0, -3:, -3:, -1]

           assert image.shape == (1, 64, 64, 3)
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	np.array([0.5_756, 0.6_118, 0.5_005, 0.5_041, 0.5_471, 0.4_726, 0.4_976, 0.4_865, 0.4_864]  )

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

     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Any      		=	"""cpu"""  # ensure determinism for the device-dependent torch.Generator
           SCREAMING_SNAKE_CASE__   :      Dict      		=	self.dummy_cond_unet
           SCREAMING_SNAKE_CASE__   :      int      		=	PNDMScheduler(skip_prk_steps=_a  )
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	self.dummy_vae
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.dummy_text_encoder
           SCREAMING_SNAKE_CASE__   :      int      		=	CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""  )

           # make sure here that pndm scheduler skips prk
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	StableDiffusionPipeline(
               unet=_a	,    scheduler=_a	,    vae=_a	,    text_encoder=_a	,    tokenizer=_a	,    safety_checker=_a	,    feature_extractor=self.dummy_extractor	,    )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	sd_pipe.to(_a  )
           sd_pipe.set_progress_bar_config(disable=_a  )

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	"""A painting of a squirrel eating a burger"""
           SCREAMING_SNAKE_CASE__   :      str      		=	torch.Generator(device=_a  ).manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	sd_pipe([prompt]	,    generator=_a	,    guidance_scale=6.0	,    num_inference_steps=2	,    output_type="""np"""  )

           SCREAMING_SNAKE_CASE__   :      int      		=	output.images

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	torch.Generator(device=_a  ).manual_seed(0  )
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=6.0	,    num_inference_steps=2	,    output_type="""np"""	,    return_dict=_a	,    )[0]

           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	image_from_tuple[0, -3:, -3:, -1]

           assert image.shape == (1, 64, 64, 3)
           SCREAMING_SNAKE_CASE__   :      Dict      		=	np.array([0.5_125, 0.5_716, 0.4_828, 0.5_060, 0.5_650, 0.4_768, 0.5_185, 0.4_895, 0.4_993]  )

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

     def 					_a			(						self  )  ->      Any:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Tuple      		=	StableDiffusionPipeline.from_pretrained(
               """hf-internal-testing/tiny-stable-diffusion-lms-pipe"""	,    safety_checker=_a  )
           assert isinstance(_a	,    _a  )
           assert isinstance(pipe.scheduler	,    _a  )
           assert pipe.safety_checker is None

           SCREAMING_SNAKE_CASE__   :      Dict      		=	pipe("""example prompt"""	,    num_inference_steps=2  ).images[0]
           assert image is not None

           # check that there's no error when saving a pipeline with one of the models being None
           with tempfile.TemporaryDirectory() as tmpdirname:
                 pipe.save_pretrained(_a  )
                 SCREAMING_SNAKE_CASE__   :      Dict      		=	StableDiffusionPipeline.from_pretrained(_a  )

           # sanity check that the pipeline still works
           assert pipe.safety_checker is None
           SCREAMING_SNAKE_CASE__   :      Dict      		=	pipe("""example prompt"""	,    num_inference_steps=2  ).images[0]
           assert image is not None





     @unittest.skipIf(torch_device != """cuda"""	,    """This test requires a GPU"""  )
     def 					_a			(						self  )  ->      Union[str, Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      int      		=	self.dummy_cond_unet
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	PNDMScheduler(skip_prk_steps=_a  )
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.dummy_vae
           SCREAMING_SNAKE_CASE__   :      Any      		=	self.dummy_text_encoder
           SCREAMING_SNAKE_CASE__   :      Any      		=	CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""  )

           # put models in fp16
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	unet.half()
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	vae.half()
           SCREAMING_SNAKE_CASE__   :      Dict      		=	bert.half()

           # make sure here that pndm scheduler skips prk
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	StableDiffusionPipeline(
               unet=_a	,    scheduler=_a	,    vae=_a	,    text_encoder=_a	,    tokenizer=_a	,    safety_checker=_a	,    feature_extractor=self.dummy_extractor	,    )
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	sd_pipe.to(_a  )
           sd_pipe.set_progress_bar_config(disable=_a  )

           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	"""A painting of a squirrel eating a burger"""
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	sd_pipe([prompt]	,    num_inference_steps=2	,    output_type="""np"""  ).images

           assert image.shape == (1, 64, 64, 3)





@nightly
@require_torch_gpu
class      __a							(unittest.TestCase):






     '''simple docstring'''

     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()

     def 					_a			(						self  )  ->      int:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""	,    safety_checker=_a  )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config  )
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	sd_pipe.to(_a  )
           sd_pipe.set_progress_bar_config(disable=_a  )

           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	(
               """portrait of girl with smokey eyes makeup in abandoned hotel, grange clothes, redshift, wide high angle"""
               """ coloured polaroid photograph with flash, kodak film, hyper real, stunning moody cinematography, with"""
               """ anamorphic lenses, by maripol, fallen angels by wong kar - wai, style of suspiria and neon demon and"""
               """ children from bahnhof zoo, detailed """
           )
           SCREAMING_SNAKE_CASE__   :      Any      		=	4_003_660_346
           SCREAMING_SNAKE_CASE__   :      str      		=	7

           # without safety guidance (sld_guidance_scale = 0)
           SCREAMING_SNAKE_CASE__   :      str      		=	torch.manual_seed(_a  )
           SCREAMING_SNAKE_CASE__   :      int      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=_a	,    num_inference_steps=50	,    output_type="""np"""	,    width=512	,    height=512	,    sld_guidance_scale=0	,    )

           SCREAMING_SNAKE_CASE__   :      Tuple      		=	output.images
           SCREAMING_SNAKE_CASE__   :      str      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	[0.2_278, 0.2_231, 0.2_249, 0.2_333, 0.2_303, 0.1_885, 0.2_273, 0.2_144, 0.2_176]

           assert image.shape == (1, 512, 512, 3)

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

           # without safety guidance (strong configuration)
           SCREAMING_SNAKE_CASE__   :      int      		=	torch.manual_seed(_a  )
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=_a	,    num_inference_steps=50	,    output_type="""np"""	,    width=512	,    height=512	,    sld_guidance_scale=2_000	,    sld_warmup_steps=7	,    sld_threshold=0.025	,    sld_momentum_scale=0.5	,    sld_mom_beta=0.7	,    )

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	output.images
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      int      		=	[0.2_383, 0.2_276, 0.236, 0.2_192, 0.2_186, 0.2_053, 0.1_971, 0.1_901, 0.1_719]

           assert image.shape == (1, 512, 512, 3)

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

     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      List[str]      		=	StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""	,    safety_checker=_a  )
           SCREAMING_SNAKE_CASE__   :      Any      		=	LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config  )
           SCREAMING_SNAKE_CASE__   :      int      		=	sd_pipe.to(_a  )
           sd_pipe.set_progress_bar_config(disable=_a  )

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	"""padme amidala taking a bath artwork, safe for work, no nudity"""
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	2_734_971_755
           SCREAMING_SNAKE_CASE__   :      int      		=	7

           SCREAMING_SNAKE_CASE__   :      Dict      		=	torch.manual_seed(_a  )
           SCREAMING_SNAKE_CASE__   :      str      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=_a	,    num_inference_steps=50	,    output_type="""np"""	,    width=512	,    height=512	,    sld_guidance_scale=0	,    )

           SCREAMING_SNAKE_CASE__   :      str      		=	output.images
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      Dict      		=	[0.3_502, 0.3_622, 0.3_396, 0.3_642, 0.3_478, 0.3_318, 0.35, 0.3_348, 0.3_297]

           assert image.shape == (1, 512, 512, 3)

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

           SCREAMING_SNAKE_CASE__   :      str      		=	torch.manual_seed(_a  )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=_a	,    num_inference_steps=50	,    output_type="""np"""	,    width=512	,    height=512	,    sld_guidance_scale=2_000	,    sld_warmup_steps=7	,    sld_threshold=0.025	,    sld_momentum_scale=0.5	,    sld_mom_beta=0.7	,    )

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	output.images
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      Dict      		=	[0.5_531, 0.5_206, 0.4_895, 0.5_156, 0.5_182, 0.4_751, 0.4_802, 0.4_803, 0.4_443]

           assert image.shape == (1, 512, 512, 3)

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





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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Dict      		=	StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""  )
           SCREAMING_SNAKE_CASE__   :      int      		=	sd_pipe.to(_a  )
           sd_pipe.set_progress_bar_config(disable=_a  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	(
               """the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c."""
               """ leyendecker"""
           )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	1_044_355_234
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	12

           SCREAMING_SNAKE_CASE__   :      Any      		=	torch.manual_seed(_a  )
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=_a	,    num_inference_steps=50	,    output_type="""np"""	,    width=512	,    height=512	,    sld_guidance_scale=0	,    )

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	output.images
           SCREAMING_SNAKE_CASE__   :      Dict      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]  )

           assert image.shape == (1, 512, 512, 3)

           assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-7

           SCREAMING_SNAKE_CASE__   :      Any      		=	torch.manual_seed(_a  )
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	sd_pipe(
               [prompt]	,    generator=_a	,    guidance_scale=_a	,    num_inference_steps=50	,    output_type="""np"""	,    width=512	,    height=512	,    sld_guidance_scale=2_000	,    sld_warmup_steps=7	,    sld_threshold=0.025	,    sld_momentum_scale=0.5	,    sld_mom_beta=0.7	,    )

           SCREAMING_SNAKE_CASE__   :      Dict      		=	output.images
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	image[0, -3:, -3:, -1]
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	np.array([0.5_818, 0.6_285, 0.6_835, 0.6_019, 0.625, 0.6_754, 0.6_096, 0.6_334, 0.6_561]  )
           assert image.shape == (1, 512, 512, 3)

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







"""simple docstring"""


import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
  from PIL import Image

  from transformers import AlignProcessor, EfficientNetImageProcessor

@require_vision
class      __a							(unittest.TestCase):






     '''simple docstring'''

     def 					_a			(						self  )  ->      int:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	tempfile.mkdtemp()

           SCREAMING_SNAKE_CASE__   :      Dict      		=	[
               """[UNK]""",
               """[CLS]""",
               """[SEP]""",
               """[PAD]""",
               """[MASK]""",
               """want""",
               """##want""",
               """##ed""",
               """wa""",
               """un""",
               """runn""",
               """##ing""",
               """,""",
               """low""",
               """lowest""",
           ]
           SCREAMING_SNAKE_CASE__   :      Dict      		=	os.path.join(self.tmpdirname	,    VOCAB_FILES_NAMES["""vocab_file"""]  )
           with open(self.vocab_file	,    """w"""	,    encoding="""utf-8"""  ) as vocab_writer:
                 vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]  )  )

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	{
               """do_resize""": True,
               """size""": 20,
               """do_center_crop""": True,
               """crop_size""": 18,
               """do_normalize""": True,
               """image_mean""": [0.48_145_466, 0.4_578_275, 0.40_821_073],
               """image_std""": [0.26_862_954, 0.26_130_258, 0.27_577_711],
           }
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	os.path.join(self.tmpdirname	,    _a  )
           with open(self.image_processor_file	,    """w"""	,    encoding="""utf-8"""  ) as fp:
                 json.dump(_a	,    _a  )

     def 					_a			(						self	,    **_a  )  ->      List[Any]:


           """simple docstring"""


           return BertTokenizer.from_pretrained(self.tmpdirname	,    **_a  )

     def 					_a			(						self	,    **_a  )  ->      List[Any]:


           """simple docstring"""


           return BertTokenizerFast.from_pretrained(self.tmpdirname	,    **_a  )

     def 					_a			(						self	,    **_a  )  ->      Any:


           """simple docstring"""


           return EfficientNetImageProcessor.from_pretrained(self.tmpdirname	,    **_a  )

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


           """simple docstring"""


           shutil.rmtree(self.tmpdirname  )

     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Tuple      		=	[np.random.randint(255	,    size=(3, 30, 400)	,    dtype=np.uinta  )]
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	[Image.fromarray(np.moveaxis(_a	,    0	,    -1  )  ) for x in image_inputs]
           return image_inputs

     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.get_tokenizer()
           SCREAMING_SNAKE_CASE__   :      str      		=	self.get_rust_tokenizer()
           SCREAMING_SNAKE_CASE__   :      str      		=	self.get_image_processor()

           SCREAMING_SNAKE_CASE__   :      Tuple      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )
           processor_slow.save_pretrained(self.tmpdirname  )
           SCREAMING_SNAKE_CASE__   :      str      		=	AlignProcessor.from_pretrained(self.tmpdirname	,    use_fast=_a  )

           SCREAMING_SNAKE_CASE__   :      int      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )
           processor_fast.save_pretrained(self.tmpdirname  )
           SCREAMING_SNAKE_CASE__   :      Any      		=	AlignProcessor.from_pretrained(self.tmpdirname  )

           self.assertEqual(processor_slow.tokenizer.get_vocab()	,    tokenizer_slow.get_vocab()  )
           self.assertEqual(processor_fast.tokenizer.get_vocab()	,    tokenizer_fast.get_vocab()  )
           self.assertEqual(tokenizer_slow.get_vocab()	,    tokenizer_fast.get_vocab()  )
           self.assertIsInstance(processor_slow.tokenizer	,    _a  )
           self.assertIsInstance(processor_fast.tokenizer	,    _a  )

           self.assertEqual(processor_slow.image_processor.to_json_string()	,    image_processor.to_json_string()  )
           self.assertEqual(processor_fast.image_processor.to_json_string()	,    image_processor.to_json_string()  )
           self.assertIsInstance(processor_slow.image_processor	,    _a  )
           self.assertIsInstance(processor_fast.image_processor	,    _a  )

     def 					_a			(						self  )  ->      str:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	AlignProcessor(tokenizer=self.get_tokenizer()	,    image_processor=self.get_image_processor()  )
           processor.save_pretrained(self.tmpdirname  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	self.get_tokenizer(bos_token="""(BOS)"""	,    eos_token="""(EOS)"""  )
           SCREAMING_SNAKE_CASE__   :      Dict      		=	self.get_image_processor(do_normalize=_a	,    padding_value=1.0  )

           SCREAMING_SNAKE_CASE__   :      Dict      		=	AlignProcessor.from_pretrained(
               self.tmpdirname	,    bos_token="""(BOS)"""	,    eos_token="""(EOS)"""	,    do_normalize=_a	,    padding_value=1.0  )

           self.assertEqual(processor.tokenizer.get_vocab()	,    tokenizer_add_kwargs.get_vocab()  )
           self.assertIsInstance(processor.tokenizer	,    _a  )

           self.assertEqual(processor.image_processor.to_json_string()	,    image_processor_add_kwargs.to_json_string()  )
           self.assertIsInstance(processor.image_processor	,    _a  )

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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	self.get_image_processor()
           SCREAMING_SNAKE_CASE__   :      str      		=	self.get_tokenizer()

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	self.prepare_image_inputs()

           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	image_processor(_a	,    return_tensors="""np"""  )
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	processor(images=_a	,    return_tensors="""np"""  )

           for key in input_image_proc.keys():
                 self.assertAlmostEqual(input_image_proc[key].sum()	,    input_processor[key].sum()	,    delta=1E-2  )

     def 					_a			(						self  )  ->      Any:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      int      		=	self.get_image_processor()
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	self.get_tokenizer()

           SCREAMING_SNAKE_CASE__   :      Any      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	"""lower newer"""

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	processor(text=_a  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	tokenizer(_a	,    padding="""max_length"""	,    max_length=64  )

           for key in encoded_tok.keys():
                 self.assertListEqual(encoded_tok[key]	,    encoded_processor[key]  )

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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      str      		=	self.get_image_processor()
           SCREAMING_SNAKE_CASE__   :      int      		=	self.get_tokenizer()

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	"""lower newer"""
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	self.prepare_image_inputs()

           SCREAMING_SNAKE_CASE__   :      Any      		=	processor(text=_a	,    images=_a  )

           self.assertListEqual(list(inputs.keys()  )	,    ["""input_ids""", """token_type_ids""", """attention_mask""", """pixel_values"""]  )

           # test if it raises when no input is passed
           with pytest.raises(_a  ):
                 processor()

     def 					_a			(						self  )  ->      Any:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Any      		=	self.get_image_processor()
           SCREAMING_SNAKE_CASE__   :      Dict      		=	self.get_tokenizer()

           SCREAMING_SNAKE_CASE__   :      Tuple      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	processor.batch_decode(_a  )
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	tokenizer.batch_decode(_a  )

           self.assertListEqual(_a	,    _a  )





     def 					_a			(						self  )  ->      str:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      List[str]      		=	self.get_image_processor()
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.get_tokenizer()

           SCREAMING_SNAKE_CASE__   :      Dict      		=	AlignProcessor(tokenizer=_a	,    image_processor=_a  )

           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	"""lower newer"""
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	self.prepare_image_inputs()

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	processor(text=_a	,    images=_a  )

           self.assertListEqual(list(inputs.keys()  )	,    processor.model_input_names  )




