
"""simple docstring"""



from manim import *





class 				a			(					lowercase      ):



      def  __snake_case							(   self      ):
          UpperCAmelCase__	:      Optional[Any]     							=					Rectangle(height=0.5     ,	width=0.5      )
          UpperCAmelCase__	:      Dict     							=					Rectangle(height=0.46     ,	width=0.46      ).set_stroke(width=0      )

          UpperCAmelCase__	:      Optional[Any]     							=					[mem.copy() for i in range(6      )]
          UpperCAmelCase__	:      Optional[int]     							=					[mem.copy() for i in range(6      )]
          UpperCAmelCase__	:      Optional[int]     							=					VGroup(*UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0      )
          UpperCAmelCase__	:      List[Any]     							=					VGroup(*UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0      )
          UpperCAmelCase__	:      Any     							=					VGroup(UpperCamelCase_     ,	UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0      )
          UpperCAmelCase__	:      Any     							=					Text('CPU'     ,	font_size=24      )
          UpperCAmelCase__	:      List[str]     							=					Group(UpperCamelCase_     ,	UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0.5     ,	aligned_edge=UpperCamelCase_      )
          cpu.move_to([-2.5, -0.5, 0]      )
          self.add(UpperCamelCase_      )

          UpperCAmelCase__	:      Union[str, Any]     							=					[mem.copy() for i in range(1      )]
          UpperCAmelCase__	:      Tuple     							=					VGroup(*UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0      )
          UpperCAmelCase__	:      Tuple     							=					Text('GPU'     ,	font_size=24      )
          UpperCAmelCase__	:      Any     							=					Group(UpperCamelCase_     ,	UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0.5     ,	aligned_edge=UpperCamelCase_      )
          gpu.align_to(UpperCamelCase_     ,	UpperCamelCase_      )
          gpu.set_x(gpu.get_x() - 1      )

          self.add(UpperCamelCase_      )

          UpperCAmelCase__	:      List[str]     							=					[mem.copy() for i in range(6      )]
          UpperCAmelCase__	:      Any     							=					VGroup(*UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0      )

          UpperCAmelCase__	:      str     							=					Text('Model'     ,	font_size=24      )
          UpperCAmelCase__	:      Optional[int]     							=					Group(UpperCamelCase_     ,	UpperCamelCase_      ).arrange(UpperCamelCase_     ,	buff=0.5     ,	aligned_edge=UpperCamelCase_      )
          model.move_to([3, -1.0, 0]      )

          self.play(
              Create(UpperCamelCase_     ,	run_time=1      )     ,	Create(UpperCamelCase_     ,	run_time=1      )     ,	Create(UpperCamelCase_     ,	run_time=1      )     ,	)

          UpperCAmelCase__	:      List[Any]     							=					MarkupText(
              F'''First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.'''     ,	font_size=24     ,	)

          UpperCAmelCase__	:      Tuple     							=					Square(side_length=2.2      )
          key.move_to([-5, 2, 0]      )

          UpperCAmelCase__	:      List[Any]     							=					MarkupText(
              F'''<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'''     ,	font_size=18     ,	)

          key_text.move_to([-5, 2.4, 0]      )

          step_a.move_to([2, 2, 0]      )
          self.play(Write(UpperCamelCase_     ,	run_time=2.5      )     ,	Write(UpperCamelCase_      )     ,	Write(UpperCamelCase_      )      )

          self.add(UpperCamelCase_      )

          UpperCAmelCase__	:      List[str]     							=					[]
          UpperCAmelCase__	:      Optional[int]     							=					[]
          UpperCAmelCase__	:      int     							=					[]
          for i, rect in enumerate(UpperCamelCase_      ):
              UpperCAmelCase__	:      Union[str, Any]     							=					Rectangle(height=0.46     ,	width=0.46      ).set_stroke(width=0.0      ).set_fill(UpperCamelCase_     ,	opacity=0.7      )
              cpu_target.move_to(UpperCamelCase_      )
              cpu_target.generate_target()
              UpperCAmelCase__	:      Optional[int]     							=					0.46 / 4
              UpperCAmelCase__	:      Optional[int]     							=					0.46 / 3

              if i == 0:
                  cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT      )     ,	buff=0.02     ,	direction=UpperCamelCase_      )
                  cpu_target.target.set_x(cpu_target.target.get_x() + 0.1      )
              elif i == 3:
                  cpu_target.target.next_to(cpu_targs[0].target     ,	direction=UpperCamelCase_     ,	buff=0.0      )
              else:
                  cpu_target.target.next_to(cpu_targs[i - 1].target     ,	direction=UpperCamelCase_     ,	buff=0.0      )
              cpu_targs.append(UpperCamelCase_      )

              first_animations.append(rect.animate(run_time=0.5      ).set_stroke(UpperCamelCase_      )      )
              second_animations.append(MoveToTarget(UpperCamelCase_     ,	run_time=1.5      )      )

          self.play(*UpperCamelCase_      )
          self.play(*UpperCamelCase_      )

          self.wait()



"""simple docstring"""



import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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      ):
      UpperCamelCase							:   int           =     IFImgaImgSuperResolutionPipeline
      UpperCamelCase							:   Union[str, Any]           =     TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
      UpperCamelCase							:   Tuple           =     TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"""original_image"""}      )
      UpperCamelCase							:   Union[str, Any]           =     PipelineTesterMixin.required_optional_params - {"""latents"""}



      def  __snake_case							(   self      ):
          return self._get_superresolution_dummy_components()



      def  __snake_case							(   self     ,	UpperCamelCase_     ,	UpperCamelCase_=0      ):
          if str(UpperCamelCase_      ).startswith('mps'      ):
              UpperCAmelCase__	:      Optional[int]     							=					torch.manual_seed(UpperCamelCase_      )
          else:
              UpperCAmelCase__	:      int     							=					torch.Generator(device=UpperCamelCase_      ).manual_seed(UpperCamelCase_      )

          UpperCAmelCase__	:      Union[str, Any]     							=					floats_tensor((1, 3, 32, 32)     ,	rng=random.Random(UpperCamelCase_      )      ).to(UpperCamelCase_      )
          UpperCAmelCase__	:      Tuple     							=					floats_tensor((1, 3, 16, 16)     ,	rng=random.Random(UpperCamelCase_      )      ).to(UpperCamelCase_      )

          UpperCAmelCase__	:      int     							=					{
              'prompt': 'A painting of a squirrel eating a burger',
              'image': image,
              'original_image': original_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  __snake_case							(   self      ):
          self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3      )



      def  __snake_case							(   self      ):
          self._test_save_load_optional_components()



      @unittest.skipIf(torch_device != 'cuda'     ,	reason='float16 requires CUDA'      )
      def  __snake_case							(   self      ):
          # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
          super().test_save_load_floataa(expected_max_diff=1E-1      )



      def  __snake_case							(   self      ):
          self._test_attention_slicing_forward_pass(expected_max_diff=1E-2      )



      def  __snake_case							(   self      ):
          self._test_save_load_local()



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

