
import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


lowerCamelCase      =False




class 				_lowerCamelCase (      unittest.TestCase ):





					"""simple docstring"""







					pass




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





					"""simple docstring"""







					def    __SCREAMING_SNAKE_CASE			(							self  )  ->   str:




											"""simple docstring"""







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






					def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Dict:




											"""simple docstring"""







											UpperCamelCase__    :   Tuple					=				VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion'''  )
											# remove text_unet
											pipe.remove_unused_weights()
											pipe.to(__SCREAMING_SNAKE_CASE  )
											pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE  )

											UpperCamelCase__    :   Optional[Any]					=				'''A painting of a squirrel eating a burger '''
											UpperCamelCase__    :   Optional[Any]					=				torch.manual_seed(0  )
											UpperCamelCase__    :   Tuple					=				pipe(
											    prompt=__SCREAMING_SNAKE_CASE						,						generator=__SCREAMING_SNAKE_CASE						,						guidance_scale=7.5						,						num_inference_steps=2						,						output_type='''numpy'''  ).images

											with tempfile.TemporaryDirectory() as tmpdirname:
																	pipe.save_pretrained(__SCREAMING_SNAKE_CASE  )
																	UpperCamelCase__    :   Dict					=				VersatileDiffusionTextToImagePipeline.from_pretrained(__SCREAMING_SNAKE_CASE  )
											pipe.to(__SCREAMING_SNAKE_CASE  )
											pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE  )

											UpperCamelCase__    :   Any					=				generator.manual_seed(0  )
											UpperCamelCase__    :   str					=				pipe(
											    prompt=__SCREAMING_SNAKE_CASE						,						generator=__SCREAMING_SNAKE_CASE						,						guidance_scale=7.5						,						num_inference_steps=2						,						output_type='''numpy'''  ).images

											assert np.abs(image - new_image  ).sum() < 1e-5, "Models don't have the same forward pass"






					def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Tuple:




											"""simple docstring"""







											UpperCamelCase__    :   Dict					=				VersatileDiffusionTextToImagePipeline.from_pretrained(
											    '''shi-labs/versatile-diffusion'''						,						torch_dtype=torch.floataa  )
											pipe.to(__SCREAMING_SNAKE_CASE  )
											pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE  )

											UpperCamelCase__    :   Union[str, Any]					=				'''A painting of a squirrel eating a burger '''
											UpperCamelCase__    :   Dict					=				torch.manual_seed(0  )
											UpperCamelCase__    :   Any					=				pipe(
											    prompt=__SCREAMING_SNAKE_CASE						,						generator=__SCREAMING_SNAKE_CASE						,						guidance_scale=7.5						,						num_inference_steps=5_0						,						output_type='''numpy'''  ).images

											UpperCamelCase__    :   Union[str, Any]					=				image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											UpperCamelCase__    :   Tuple					=				np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]  )

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




def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ = 5_0_0_0_0_0_0_0		):
      UpperCamelCase__    :   Any					=				set()
      UpperCamelCase__    :   Any					=				int((limit - 2_4) ** (1 / 2)		)

      UpperCamelCase__    :   Dict					=				set(range(3 ,		prime_square_limit + 1 ,		2		)		)
      primes.add(2		)
      for p in range(3 ,		prime_square_limit + 1 ,		2		):
            if p not in primes:
                  continue
            primes.difference_update(set(range(p * p ,		prime_square_limit + 1 ,		UpperCamelCase__		)		)		)

      for primea in primes:
            UpperCamelCase__    :   Dict					=				primea * primea
            for primea in primes:
                  UpperCamelCase__    :   str					=				primea * primea * primea
                  if square + cube >= limit - 1_6:
                        break
                  for primea in primes:
                        UpperCamelCase__    :   Dict					=				primea * primea * primea * primea
                        UpperCamelCase__    :   Tuple					=				square + cube + tetr
                        if total >= limit:
                              break
                        ret.add(UpperCamelCase__		)

      return len(UpperCamelCase__		)


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


