

"""simple docstring"""

import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
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_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin






@skip_mps
class  __a				(	__magic_name__					,  __magic_name__					,  unittest.TestCase					):





       """simple docstring"""


       __UpperCamelCase				:			Any          =	IFImgaImgPipeline
       __UpperCamelCase				:			Tuple          =	TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
       __UpperCamelCase				:			Tuple          =	TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
       __UpperCamelCase				:			int          =	PipelineTesterMixin.required_optional_params - {'latents'}






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        return self._get_dummy_components()






       def  SCREAMING_SNAKE_CASE_  (      self ,				snake_case ,				snake_case=0      ):





        """simple docstring"""

        if str(snake_case      ).startswith("mps"      ):
         lowerCAmelCase__      :							Union[str, Any]    =							torch.manual_seed(snake_case      )
        else:
         lowerCAmelCase__      :							Dict    =							torch.Generator(device=snake_case      ).manual_seed(snake_case      )

        lowerCAmelCase__      :							Optional[Any]    =							floats_tensor((1, 3, 32, 32) ,				rng=random.Random(snake_case      )      ).to(snake_case      )

        lowerCAmelCase__      :							List[str]    =							{
            "prompt": "A painting of a squirrel eating a burger",
            "image": image,
            "generator": generator,
            "num_inference_steps": 2,
            "output_type": "numpy",
        }

        return inputs






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        self._test_save_load_optional_components()






       @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      ):





        """simple docstring"""

        self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )






       @unittest.skipIf(torch_device != "cuda" ,				reason="float16 requires CUDA"      )
       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

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






       @unittest.skipIf(torch_device != "cuda" ,				reason="float16 requires CUDA"      )
       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

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






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        self._test_attention_slicing_forward_pass(expected_max_diff=1e-2      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        self._test_save_load_local()






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

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









"""simple docstring"""

import torch
import torch.nn.functional as F

from diffusers import VQDiffusionScheduler

from .test_schedulers import SchedulerCommonTest






class  __a				(	__magic_name__					):





       """simple docstring"""


       __UpperCamelCase				:			Optional[int]          =	(VQDiffusionScheduler,)






       def  SCREAMING_SNAKE_CASE_  (      self ,				**snake_case      ):





        """simple docstring"""

        lowerCAmelCase__      :							str    =							{
            "num_vec_classes": 4_097,
            "num_train_timesteps": 100,
        }

        config.update(**snake_case      )
        return config






       def  SCREAMING_SNAKE_CASE_  (      self ,				snake_case      ):





        """simple docstring"""

        lowerCAmelCase__      :							Optional[int]    =							4
        lowerCAmelCase__      :							Optional[Any]    =							8
        lowerCAmelCase__      :							Union[str, Any]    =							8

        lowerCAmelCase__      :							Optional[Any]    =							torch.randint(0 ,				snake_case ,				(batch_size, height * width)      )

        return sample






       @property
       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        assert False






       def  SCREAMING_SNAKE_CASE_  (      self ,				snake_case      ):





        """simple docstring"""

        def model(snake_case ,				snake_case ,				*snake_case      ):
         lowerCAmelCase__ ,	lowerCAmelCase__      :							str    =							sample.shape
         lowerCAmelCase__      :							Dict    =							torch.rand((batch_size, num_vec_classes - 1, num_latent_pixels)      )
         lowerCAmelCase__      :							int    =							F.log_softmax(logits.double() ,				dim=1      ).float()
         return return_value

        return model






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        for timesteps in [2, 5, 100, 1_000]:
         self.check_over_configs(num_train_timesteps=snake_case      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        for num_vec_classes in [5, 100, 1_000, 4_000]:
         self.check_over_configs(num_vec_classes=snake_case      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        for t in [0, 50, 99]:
         self.check_over_forward(time_step=snake_case      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        pass






