

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__(a_,     a_,     unittest.TestCase       ):
      """simple docstring"""






      _A						:							Any									= IFSuperResolutionPipeline
      _A						:							int									= TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
      _A						:							Optional[Any]									= TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
      _A						:							Any									= PipelineTesterMixin.required_optional_params - {'''latents'''}





      def  UpperCamelCase__				(						self						)    ->   int:
         return self._get_superresolution_dummy_components()





      def  UpperCamelCase__				(						self     ,			_lowercase     ,			_lowercase=0						)    ->   List[Any]:
         if str(_lowercase						).startswith("""mps"""						):
            a_	:	Any          =   torch.manual_seed(_lowercase						)
         else:
            a_	:	Optional[Any]          =   torch.Generator(device=_lowercase						).manual_seed(_lowercase						)

         a_	:	Dict          =   floats_tensor((1, 3, 32, 32)     ,			rng=random.Random(_lowercase						)						).to(_lowercase						)

         a_	:	List[Any]          =   {
             """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  UpperCamelCase__				(						self						)    ->   Union[str, Any]:
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3						)





      def  UpperCamelCase__				(						self						)    ->   Optional[int]:
         self._test_save_load_optional_components()





      @unittest.skipIf(torch_device != """cuda"""     ,			reason="""float16 requires CUDA"""						)
      def  UpperCamelCase__				(						self						)    ->   Any:
         # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
         super().test_save_load_floataa(expected_max_diff=1e-1						)





      def  UpperCamelCase__				(						self						)    ->   Optional[Any]:
         self._test_attention_slicing_forward_pass(expected_max_diff=1e-2						)





      def  UpperCamelCase__				(						self						)    ->   Optional[Any]:
         self._test_save_load_local()





      def  UpperCamelCase__				(						self						)    ->   Dict:
         self._test_inference_batch_single_identical(
             expected_max_diff=1e-2     ,			)





# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__snake_case							:			Any      		= {
    """configuration_convnextv2""": [
        """CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """ConvNextV2Config""",
    ]
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case							:			Dict      		= [
	    """CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """ConvNextV2ForImageClassification""",
	    """ConvNextV2Model""",
	    """ConvNextV2PreTrainedModel""",
	    """ConvNextV2Backbone""",
	]


if TYPE_CHECKING:
	from .configuration_convnextva import (
	    CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    ConvNextVaConfig,
	)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_convnextva import (
		    CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
		    ConvNextVaBackbone,
		    ConvNextVaForImageClassification,
		    ConvNextVaModel,
		    ConvNextVaPreTrainedModel,
		)

else:
	import sys

	__snake_case							:			Dict      		= _LazyModule(__name__, globals()["""__file__"""], _import_structure)


