

"""simple docstring"""

import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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				:			int          =	IFSuperResolutionPipeline
       __UpperCamelCase				:			Tuple          =	TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
       __UpperCamelCase				:			List[Any]          =	TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
       __UpperCamelCase				:			str          =	PipelineTesterMixin.required_optional_params - {'latents'}






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        return self._get_superresolution_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__      :							List[Any]    =							torch.Generator(device=snake_case      ).manual_seed(snake_case      )

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

        lowerCAmelCase__      :							int    =							{
            "prompt": "A painting of a squirrel eating a burger",
            "image": 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      ):





        """simple docstring"""

        self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )






       def  SCREAMING_SNAKE_CASE_  (      self      ):





        """simple docstring"""

        self._test_save_load_optional_components()






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






       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"""

from itertools import product



def 			SCREAMING_SNAKE_CASE       (   lowercase__ = 1_5      ) ->	int:
 lowerCAmelCase__      :							float    =							0.0
 lowerCAmelCase__      :							float
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							int
 lowerCAmelCase__      :							tuple[int, ...]

 for series in product(range(2      )				,				repeat=lowercase__      ):
  lowerCAmelCase__      :							Optional[int]    =							series.count(1      )
  lowerCAmelCase__      :							Dict    =							num_turns - num_blue
  if num_red >= num_blue:
   continue
  lowerCAmelCase__      :							Dict    =							1.0
  for ind, col in enumerate(lowercase__				,				2      ):
   if col == 0:
    prob *= (ind - 1) / ind
   else:
    prob *= 1 / ind

  total_prob += prob

 return int(1 / total_prob      )


if __name__ == "__main__":
    print(f"{solution() = }")






