

import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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__    (				UpperCAmelCase		,     UpperCAmelCase		,     unittest.TestCase    ):







  """simple docstring"""




  UpperCAmelCase__ :	List[str]         =IFSuperResolutionPipeline
  UpperCAmelCase__ :	List[str]         =TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
  UpperCAmelCase__ :	Union[str, Any]         =TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
  UpperCAmelCase__ :	Dict         =PipelineTesterMixin.required_optional_params - {"""latents"""}


  def 	_lowercase (     self      :	List[Any]						)   ->Union[str, Any]:
        """simple docstring"""







        return self._get_superresolution_dummy_components()


  def 	_lowercase (     self      :	List[str]			,			UpperCAmelCase__      :	Tuple			,			UpperCAmelCase__      :	Union[str, Any]=0						)   ->Optional[Any]:
        """simple docstring"""







        if str(UpperCAmelCase__						).startswith("""mps"""						):
              SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				torch.manual_seed(UpperCAmelCase__						)
        else:
              SCREAMING_SNAKE_CASE	: Dict					       =				torch.Generator(device=UpperCAmelCase__						).manual_seed(UpperCAmelCase__						)

        SCREAMING_SNAKE_CASE	: str					       =				floats_tensor((1, 3, 3_2, 3_2)			,			rng=random.Random(UpperCAmelCase__						)						).to(UpperCAmelCase__						)

        SCREAMING_SNAKE_CASE	: int					       =				{
            """prompt""": """A painting of a squirrel eating a burger""",
            """image""": 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 	_lowercase (     self      :	Any						)   ->int:
        """simple docstring"""







        self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3						)


  def 	_lowercase (     self      :	Tuple						)   ->Any:
        """simple docstring"""







        self._test_save_load_optional_components()


  @unittest.skipIf(torch_device != """cuda"""			,			reason="""float16 requires CUDA"""						)
  def 	_lowercase (     self      :	Any						)   ->Union[str, Any]:
        """simple docstring"""







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


  def 	_lowercase (     self      :	Any						)   ->str:
        """simple docstring"""







        self._test_attention_slicing_forward_pass(expected_max_diff=1e-2						)


  def 	_lowercase (     self      :	str						)   ->int:
        """simple docstring"""







        self._test_save_load_local()




  def 	_lowercase (     self      :	Union[str, Any]						)   ->Optional[Any]:
        """simple docstring"""







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







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


UpperCAmelCase__	:       int			      =      {
    """configuration_speech_to_text_2""": ["""SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """Speech2Text2Config"""],
    """processing_speech_to_text_2""": ["""Speech2Text2Processor"""],
    """tokenization_speech_to_text_2""": ["""Speech2Text2Tokenizer"""],
}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__	:       int			      =      [
      """SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Speech2Text2ForCausalLM""",
      """Speech2Text2PreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
  from .processing_speech_to_text_a import SpeechaTextaProcessor
  from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_speech_to_text_a import (
        SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
        SpeechaTextaForCausalLM,
        SpeechaTextaPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__	:       int			      =      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




