

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__    ( A  ,		A  ,		unittest.TestCase ):



 """simple docstring"""







 _lowercase     :					List[str]      =						IFImgaImgSuperResolutionPipeline
 _lowercase     :					Optional[Any]      =						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
 _lowercase     :					str      =						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''} )
 _lowercase     :					Any      =						PipelineTesterMixin.required_optional_params - {'''latents'''}

 def    __magic_name__       (		self :	Union[str, Any]       ):






      '''simple docstring'''




      return self._get_superresolution_dummy_components()

 def    __magic_name__       (		self :	Optional[Any]     ,						A_ :	int     ,						A_ :	int=0       ):






      '''simple docstring'''




      if str(A_       ).startswith("mps"       ):
           _lowerCAmelCase   :					List[str]        =    torch.manual_seed(A_       )
      else:
           _lowerCAmelCase   :					int        =    torch.Generator(device=A_       ).manual_seed(A_       )

      _lowerCAmelCase   :					Union[str, Any]        =    floats_tensor((1, 3, 3_2, 3_2)     ,						rng=random.Random(A_       )       ).to(A_       )
      _lowerCAmelCase   :					Tuple        =    floats_tensor((1, 3, 1_6, 1_6)     ,						rng=random.Random(A_       )       ).to(A_       )

      _lowerCAmelCase   :					List[Any]        =    {
          "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    __magic_name__       (		self :	List[Any]       ):






      '''simple docstring'''




      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3       )

 def    __magic_name__       (		self :	Tuple       ):






      '''simple docstring'''




      self._test_save_load_optional_components()

 @unittest.skipIf(torch_device != "cuda"     ,						reason="float16 requires CUDA"       )
 def    __magic_name__       (		self :	Dict       ):






      '''simple docstring'''




      super().test_save_load_floataa(expected_max_diff=1E-1       )

 def    __magic_name__       (		self :	List[str]       ):






      '''simple docstring'''




      self._test_attention_slicing_forward_pass(expected_max_diff=1E-2       )

 def    __magic_name__       (		self :	int       ):






      '''simple docstring'''




      self._test_save_load_local()


 def    __magic_name__       (		self :	Union[str, Any]       ):






      '''simple docstring'''




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









# Author: OMKAR PATHAK, Nwachukwu Chidiebere

# Use a Python dictionary to construct the graph.
from __future__ import annotations

from pprint import pformat
from typing import Generic, TypeVar

__UpperCAmelCase    				=     TypeVar('T')





class A__    ( Generic[T] ):



 """simple docstring"""







 def __init__(		self :	Optional[int]     ,						A_ :	bool = True       ):






      '''simple docstring'''




      _lowerCAmelCase   :					dict[T, list[T]]        =    {}  # dictionary of lists
      _lowerCAmelCase   :					List[Any]        =    directed

 def    __magic_name__       (		self :	Any     ,						A_ :	T     ,						A_ :	T       ):






      '''simple docstring'''




      if not self.directed:  # For undirected graphs
           # if both source vertex and destination vertex are both present in the
           # adjacency list, add destination vertex to source vertex list of adjacent
           # vertices and add source vertex to destination vertex list of adjacent
           # vertices.
           if source_vertex in self.adj_list and destination_vertex in self.adj_list:
                self.adj_list[source_vertex].append(A_       )
                self.adj_list[destination_vertex].append(A_       )
           # if only source vertex is present in adjacency list, add destination vertex
           # to source vertex list of adjacent vertices, then create a new vertex with
           # destination vertex as key and assign a list containing the source vertex
           # as it's first adjacent vertex.
           elif source_vertex in self.adj_list:
                self.adj_list[source_vertex].append(A_       )
                _lowerCAmelCase   :					List[Any]        =    [source_vertex]
           # if only destination vertex is present in adjacency list, add source vertex
           # to destination vertex list of adjacent vertices, then create a new vertex
           # with source vertex as key and assign a list containing the source vertex
           # as it's first adjacent vertex.
           elif destination_vertex in self.adj_list:
                self.adj_list[destination_vertex].append(A_       )
                _lowerCAmelCase   :					List[str]        =    [destination_vertex]
           # if both source vertex and destination vertex are not present in adjacency
           # list, create a new vertex with source vertex as key and assign a list
           # containing the destination vertex as it's first adjacent vertex also
           # create a new vertex with destination vertex as key and assign a list
           # containing the source vertex as it's first adjacent vertex.
           else:
                _lowerCAmelCase   :					List[str]        =    [destination_vertex]
                _lowerCAmelCase   :					Dict        =    [source_vertex]
      else:  # For directed graphs
           # if both source vertex and destination vertex are present in adjacency
           # list, add destination vertex to source vertex list of adjacent vertices.
           if source_vertex in self.adj_list and destination_vertex in self.adj_list:
                self.adj_list[source_vertex].append(A_       )
           # if only source vertex is present in adjacency list, add destination
           # vertex to source vertex list of adjacent vertices and create a new vertex
           # with destination vertex as key, which has no adjacent vertex
           elif source_vertex in self.adj_list:
                self.adj_list[source_vertex].append(A_       )
                _lowerCAmelCase   :					Tuple        =    []
           # if only destination vertex is present in adjacency list, create a new
           # vertex with source vertex as key and assign a list containing destination
           # vertex as first adjacent vertex
           elif destination_vertex in self.adj_list:
                _lowerCAmelCase   :					Dict        =    [destination_vertex]
           # if both source vertex and destination vertex are not present in adjacency
           # list, create a new vertex with source vertex as key and a list containing
           # destination vertex as it's first adjacent vertex. Then create a new vertex
           # with destination vertex as key, which has no adjacent vertex
           else:
                _lowerCAmelCase   :					Any        =    [destination_vertex]
                _lowerCAmelCase   :					Union[str, Any]        =    []

      return self


 def __repr__(		self :	List[str]       ):






      '''simple docstring'''




      return pformat(self.adj_list       )






