def      a__ (		__UpperCamelCase				):
      if not head:
            return True
      # split the list to two parts
      SCREAMING_SNAKE_CASE_     , SCREAMING_SNAKE_CASE_          =  head.next, head
      while fast and fast.next:
            SCREAMING_SNAKE_CASE_          =  fast.next.next
            SCREAMING_SNAKE_CASE_          =  slow.next
      SCREAMING_SNAKE_CASE_          =  slow.next
      SCREAMING_SNAKE_CASE_          =  None  # Don't forget here! But forget still works!
      # reverse the second part
      SCREAMING_SNAKE_CASE_          =  None
      while second:
            SCREAMING_SNAKE_CASE_          =  second.next
            SCREAMING_SNAKE_CASE_          =  node
            SCREAMING_SNAKE_CASE_          =  second
            SCREAMING_SNAKE_CASE_          =  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_          =  node.next
            SCREAMING_SNAKE_CASE_          =  head.next
      return True


def      a__ (		__UpperCamelCase				):
      if not head or not head.next:
            return True

      # 1. Get the midpoint (slow)
      SCREAMING_SNAKE_CASE_          =  SCREAMING_SNAKE_CASE_          =  SCREAMING_SNAKE_CASE_          =  head
      while fast and fast.next:
            SCREAMING_SNAKE_CASE_     , SCREAMING_SNAKE_CASE_          =  fast.next.next, slow.next

      # 2. Push the second half into the stack
      SCREAMING_SNAKE_CASE_          =  [slow.val]
      while slow.next:
            SCREAMING_SNAKE_CASE_          =  slow.next
            stack.append(slow.val				)

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

      return True





def      a__ (		__UpperCamelCase				):
      if not head or not head.next:
            return True
      SCREAMING_SNAKE_CASE_          =  {}
      SCREAMING_SNAKE_CASE_          =  0
      while head:
            if head.val in d:
                  d[head.val].append(__UpperCamelCase				)
            else:
                  SCREAMING_SNAKE_CASE_          =  [pos]
            SCREAMING_SNAKE_CASE_          =  head.next
            pos += 1
      SCREAMING_SNAKE_CASE_          =  pos - 1
      SCREAMING_SNAKE_CASE_          =  0
      for v in d.values():
            if len(__UpperCamelCase				) % 2 != 0:
                  middle += 1
            else:
                  SCREAMING_SNAKE_CASE_          =  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   lowerCamelCase					(unittest.TestCase					):
  """simple docstring"""







  pass



@nightly
@require_torch_gpu
class   lowerCamelCase					(unittest.TestCase					):
  """simple docstring"""







  def    __A     (							self :       Union[str, Any]   )  ->	List[Any]:
        # clean up the VRAM after each test
        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()







  def    __A     (							self :       str   )  ->	Any:
        SCREAMING_SNAKE_CASE_          =  VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"   )
        # remove text_unet
        pipe.remove_unused_weights()
        pipe.to(__magic_name__   )
        pipe.set_progress_bar_config(disable=__magic_name__   )

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

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

        SCREAMING_SNAKE_CASE_          =  generator.manual_seed(0   )
        SCREAMING_SNAKE_CASE_          =  pipe(
            prompt=__magic_name__  ,     generator=__magic_name__  ,     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 :       int   )  ->	Optional[int]:
        SCREAMING_SNAKE_CASE_          =  VersatileDiffusionTextToImagePipeline.from_pretrained(
            "shi-labs/versatile-diffusion"  ,     torch_dtype=torch.floataa   )
        pipe.to(__magic_name__   )
        pipe.set_progress_bar_config(disable=__magic_name__   )

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

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

        assert image.shape == (1, 512, 512, 3)
        SCREAMING_SNAKE_CASE_          =  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


