


'''simple docstring'''

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


a_  :				Tuple						= False





class      snake_case    (    unittest.TestCase			):





  """simple docstring"""




  pass





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





  """simple docstring"""




  def   snake_case		(    self     ):







   """simple docstring"""
   # clean up the VRAM after each test
   super().tearDown()
   gc.collect()
   torch.cuda.empty_cache()






  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"     )
   # remove text_unet
   pipe.remove_unused_weights()
   pipe.to(_lowerCamelCase     )
   pipe.set_progress_bar_config(disable=_lowerCamelCase     )

   lowerCamelCase_      =  "A painting of a squirrel eating a burger "
   lowerCamelCase_      =  torch.manual_seed(0     )
   lowerCamelCase_      =  pipe(
       prompt=_lowerCamelCase			,  generator=_lowerCamelCase			,  guidance_scale=7.5			,  num_inference_steps=2			,  output_type="numpy"     ).images

   with tempfile.TemporaryDirectory() as tmpdirname:
    pipe.save_pretrained(_lowerCamelCase     )
    lowerCamelCase_      =  VersatileDiffusionTextToImagePipeline.from_pretrained(_lowerCamelCase     )
   pipe.to(_lowerCamelCase     )
   pipe.set_progress_bar_config(disable=_lowerCamelCase     )

   lowerCamelCase_      =  generator.manual_seed(0     )
   lowerCamelCase_      =  pipe(
       prompt=_lowerCamelCase			,  generator=_lowerCamelCase			,  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   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  VersatileDiffusionTextToImagePipeline.from_pretrained(
       "shi-labs/versatile-diffusion"			,  torch_dtype=torch.floataa     )
   pipe.to(_lowerCamelCase     )
   pipe.set_progress_bar_config(disable=_lowerCamelCase     )

   lowerCamelCase_      =  "A painting of a squirrel eating a burger "
   lowerCamelCase_      =  torch.manual_seed(0     )
   lowerCamelCase_      =  pipe(
       prompt=_lowerCamelCase			,  generator=_lowerCamelCase			,  guidance_scale=7.5			,  num_inference_steps=50			,  output_type="numpy"     ).images

   lowerCamelCase_      =  image[0, 253:256, 253:256, -1]

   assert image.shape == (1, 512, 512, 3)
   lowerCamelCase_      =  np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778]     )

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





"""simple docstring"""



from math import pow
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					)     ->					tuple[int, int]:
  if current_sum == needed_sum:
    # If the sum of the powers is equal to needed_sum, then we have a solution.
    solutions_count += 1
    return current_sum, solutions_count

  _snake_case					     =       int(pow(__lowerCamelCase ,					__lowerCamelCase		)		)
  if current_sum + i_to_n <= needed_sum:
    # If the sum of the powers is less than needed_sum, then continue adding powers.
    current_sum += i_to_n
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
    current_sum -= i_to_n
  if i_to_n < needed_sum:
    # If the power of i is less than needed_sum, then try with the next power.
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
  return current_sum, solutions_count
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int		)     ->					int:
  if not (1 <= needed_sum <= 10_00 and 2 <= power <= 10):
    raise ValueError(
        '''Invalid input\n'''
        '''needed_sum must be between 1 and 1000, power between 2 and 10.'''		)

  return backtrack(__lowerCamelCase ,					__lowerCamelCase ,					1 ,					0 ,					0		)[1]  # Return the solutions_count


if __name__ == "__main__":
 import doctest

 doctest.testmod()



