




'''simple docstring'''



def   lowercase__(			__UpperCamelCase:					str    ):

      """simple docstring"""






      if not head:
            return True
      # split the list to two parts
      SCREAMING_SNAKE_CASE   :      List[Any]    					=						head.next, head
      while fast and fast.next:
            SCREAMING_SNAKE_CASE   :      List[str]    					=						fast.next.next
            SCREAMING_SNAKE_CASE   :      Any    					=						slow.next
      SCREAMING_SNAKE_CASE   :      Dict    					=						slow.next
      SCREAMING_SNAKE_CASE   :      int    					=						None  # Don't forget here! But forget still works!
      # reverse the second part
      SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						None
      while second:
            SCREAMING_SNAKE_CASE   :      Tuple    					=						second.next
            SCREAMING_SNAKE_CASE   :      Tuple    					=						node
            SCREAMING_SNAKE_CASE   :      Any    					=						second
            SCREAMING_SNAKE_CASE   :      Tuple    					=						nxt
      # compare two parts
      # second part has the same or one less node
      while node:
            if node.val != head.val:
                  return False
            SCREAMING_SNAKE_CASE   :      Any    					=						node.next
            SCREAMING_SNAKE_CASE   :      Optional[int]    					=						head.next
      return True




def   lowercase__(			__UpperCamelCase:					Tuple    ):

      """simple docstring"""






      if not head or not head.next:
            return True

      # 1. Get the midpoint (slow)
      SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						head
      while fast and fast.next:
            SCREAMING_SNAKE_CASE   :      int    					=						fast.next.next, slow.next

      # 2. Push the second half into the stack
      SCREAMING_SNAKE_CASE   :      Optional[int]    					=						[slow.val]
      while slow.next:
            SCREAMING_SNAKE_CASE   :      List[Any]    					=						slow.next
            stack.append(slow.val    )

      # 3. Comparison
      while stack:
            if stack.pop() != cur.val:
                  return False
            SCREAMING_SNAKE_CASE   :      Dict    					=						cur.next

      return True





def   lowercase__(			__UpperCamelCase:					Union[str, Any]    ):

      """simple docstring"""






      if not head or not head.next:
            return True
      SCREAMING_SNAKE_CASE   :      int    					=						{}
      SCREAMING_SNAKE_CASE   :      str    					=						0
      while head:
            if head.val in d:
                  d[head.val].append(__UpperCamelCase    )
            else:
                  SCREAMING_SNAKE_CASE   :      List[Any]    					=						[pos]
            SCREAMING_SNAKE_CASE   :      int    					=						head.next
            pos += 1
      SCREAMING_SNAKE_CASE   :      str    					=						pos - 1
      SCREAMING_SNAKE_CASE   :      Dict    					=						0
      for v in d.values():
            if len(__UpperCamelCase    ) % 2 != 0:
                  middle += 1
            else:
                  SCREAMING_SNAKE_CASE   :      int    					=						0
                  for i in range(0      ,len(__UpperCamelCase    )    ):
                        if v[i] + v[len(__UpperCamelCase    ) - 1 - step] != checksum:
                              return False
                        step += 1
            if middle > 1:
                  return False
      return True



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  :      List[str]            =    False

class 					_lowercase    (     unittest.TestCase			):






    '''simple docstring'''
    pass





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






    '''simple docstring'''




    def      _a    (    self ):
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()




    def      _a    (    self ):
       lowerCAmelCase_:							List[str]       =	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_:							Tuple       =	"A painting of a squirrel eating a burger "
       lowerCAmelCase_:							List[str]       =	torch.manual_seed(0 )
       lowerCAmelCase_:							Dict       =	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_:							int       =	VersatileDiffusionTextToImagePipeline.from_pretrained(lowerCamelCase__ )
       pipe.to(lowerCamelCase__ )
       pipe.set_progress_bar_config(disable=lowerCamelCase__ )

       lowerCAmelCase_:							List[str]       =	generator.manual_seed(0 )
       lowerCAmelCase_:							Dict       =	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      _a    (    self ):
       lowerCAmelCase_:							Optional[int]       =	VersatileDiffusionTextToImagePipeline.from_pretrained(
           "shi-labs/versatile-diffusion"       ,						torch_dtype=torch.floataa )
       pipe.to(lowerCamelCase__ )
       pipe.set_progress_bar_config(disable=lowerCamelCase__ )

       lowerCAmelCase_:							str       =	"A painting of a squirrel eating a burger "
       lowerCAmelCase_:							int       =	torch.manual_seed(0 )
       lowerCAmelCase_:							List[str]       =	pipe(
           prompt=lowerCamelCase__       ,						generator=lowerCamelCase__       ,						guidance_scale=7.5       ,						num_inference_steps=50       ,						output_type="numpy" ).images

       lowerCAmelCase_:							List[Any]       =	image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       lowerCAmelCase_:							Optional[int]       =	np.array([0.3_3_6_7, 0.3_1_6_9, 0.2_6_5_6, 0.3_8_7_0, 0.4_7_9_0, 0.3_7_9_6, 0.4_0_0_9, 0.4_8_7_8, 0.4_7_7_8] )

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