






"""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       (						lowercase_    ,					lowercase_    ,					unittest.TestCase   ):





   '''simple docstring'''






   UpperCamelCase__      					=    IFSuperResolutionPipeline
   UpperCamelCase__      					=    TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
   UpperCamelCase__      					=    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
   UpperCamelCase__      					=    PipelineTesterMixin.required_optional_params - {"""latents"""}





   def __lowercase    (   self)	-> Any:




          '''simple docstring'''




          return self._get_superresolution_dummy_components()





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_=0)	-> Optional[Any]:




          '''simple docstring'''




          if str(UpperCAmelCase_).startswith("mps"):
                 lowercase__:    Dict        =      torch.manual_seed(UpperCAmelCase_)
          else:
                 lowercase__:    Dict        =      torch.Generator(device=UpperCAmelCase_).manual_seed(UpperCAmelCase_)

          lowercase__:    str        =      floats_tensor((1, 3, 32, 32)			,				rng=random.Random(UpperCAmelCase_)).to(UpperCAmelCase_)

          lowercase__:    Union[str, Any]        =      {
              "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 __lowercase    (   self)	-> str:




          '''simple docstring'''




          self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3)





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




          '''simple docstring'''




          self._test_save_load_optional_components()





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




          '''simple docstring'''




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





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          self._test_attention_slicing_forward_pass(expected_max_diff=1E-2)





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




          '''simple docstring'''




          self._test_save_load_local()





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




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














"""simple docstring"""





UpperCamelCase			=      {
    """0""": 1,
    """1""": 1,
    """2""": 2,
    """3""": 6,
    """4""": 24,
    """5""": 1_20,
    """6""": 7_20,
    """7""": 50_40,
    """8""": 4_03_20,
    """9""": 36_28_80,
}

UpperCamelCase			=      {1_45: 1_45}

UpperCamelCase			=      {
    1_45: 0,
    1_69: 3,
    3_63_01: 3,
    14_54: 3,
    8_71: 2,
    4_53_61: 2,
    8_72: 2,
}






def     A(  snake_case_		):
       """simple docstring"""





       if n in CACHE_SUM_DIGIT_FACTORIALS:
              return CACHE_SUM_DIGIT_FACTORIALS[n]
       lowercase__:    Any        =      sum(DIGIT_FACTORIALS[let] for let in str(snake_case_		)		)
       lowercase__:    Optional[Any]        =      ret
       return ret






def     A(  snake_case_						,       snake_case_ = None		):
       """simple docstring"""





       lowercase__:    Optional[int]        =      previous or set()
       if n in CHAIN_LENGTH_CACHE:
              return CHAIN_LENGTH_CACHE[n]
       lowercase__:    Tuple        =      sum_digit_factorials(snake_case_		)
       if next_number in previous:
              lowercase__:    List[Any]        =      0
              return 0
       else:
              previous.add(snake_case_		)
              lowercase__:    Optional[int]        =      1 + chain_length(snake_case_						,       snake_case_		)
              lowercase__:    Any        =      ret
              return ret






def     A(  snake_case_ = 60						,       snake_case_ = 1000000		):
       """simple docstring"""





       return sum(1 for i in range(1						,       snake_case_		) if chain_length(snake_case_		) == num_terms		)


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






