






'''simple docstring'''



import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
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_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase      ,      _lowerCAmelCase      ,      unittest.TestCase     ):
      __a  					=IFInpaintingSuperResolutionPipeline
      __a  					=TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
      __a  					=TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"original_image"}     )
      __a  					=PipelineTesterMixin.required_optional_params - {"latents"}




      def  __UpperCamelCase							(  self      )							->Any:



         '''simple docstring'''
         return self._get_superresolution_dummy_components()




      def  __UpperCamelCase							(  self ,   lowerCamelCase ,   lowerCamelCase=0      )							->Dict:



         '''simple docstring'''
         if str(lowerCamelCase      ).startswith('mps'      ):
            __a				     =    torch.manual_seed(lowerCamelCase      )
         else:
            __a				     =    torch.Generator(device=lowerCamelCase      ).manual_seed(lowerCamelCase      )

         __a				     =    floats_tensor((1, 3, 16, 16) ,   rng=random.Random(lowerCamelCase      )      ).to(lowerCamelCase      )
         __a				     =    floats_tensor((1, 3, 32, 32) ,   rng=random.Random(lowerCamelCase      )      ).to(lowerCamelCase      )
         __a				     =    floats_tensor((1, 3, 32, 32) ,   rng=random.Random(lowerCamelCase      )      ).to(lowerCamelCase      )

         __a				     =    {
             'prompt': 'A painting of a squirrel eating a burger',
             'image': image,
             'original_image': original_image,
             'mask_image': mask_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      )							->Any:



         '''simple docstring'''
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )




      def  __UpperCamelCase							(  self      )							->int:



         '''simple docstring'''
         self._test_save_load_optional_components()




      @unittest.skipIf(torch_device != 'cuda' ,   reason='float16 requires CUDA'      )
      def  __UpperCamelCase							(  self      )							->str:



         '''simple docstring'''
         super().test_save_load_floataa(expected_max_diff=1e-1      )




      def  __UpperCamelCase							(  self      )							->str:



         '''simple docstring'''
         self._test_attention_slicing_forward_pass(expected_max_diff=1e-2      )




      def  __UpperCamelCase							(  self      )							->Dict:



         '''simple docstring'''
         self._test_save_load_local()






      def  __UpperCamelCase							(  self      )							->str:



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








'''simple docstring'''



from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase      :       Dict      			=      logging.get_logger(__name__)

__UpperCamelCase      :       Optional[int]      			=      {
    """facebook/xmod-base""": """https://huggingface.co/facebook/xmod-base/resolve/main/config.json""",
    """facebook/xmod-large-prenorm""": """https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json""",
    """facebook/xmod-base-13-125k""": """https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-125k""": """https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-195k""": """https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json""",
    """facebook/xmod-base-60-125k""": """https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json""",
    """facebook/xmod-base-60-265k""": """https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json""",
    """facebook/xmod-base-75-125k""": """https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json""",
    """facebook/xmod-base-75-269k""": """https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json""",
}
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):
      __a  					="xmod"




      def __init__(  self ,   lowerCamelCase=3_0522 ,   lowerCamelCase=768 ,   lowerCamelCase=12 ,   lowerCamelCase=12 ,   lowerCamelCase=3072 ,   lowerCamelCase="gelu" ,   lowerCamelCase=0.1 ,   lowerCamelCase=0.1 ,   lowerCamelCase=512 ,   lowerCamelCase=2 ,   lowerCamelCase=0.02 ,   lowerCamelCase=1e-12 ,   lowerCamelCase=1 ,   lowerCamelCase=0 ,   lowerCamelCase=2 ,   lowerCamelCase="absolute" ,   lowerCamelCase=True ,   lowerCamelCase=None ,   lowerCamelCase=False ,   lowerCamelCase=2 ,   lowerCamelCase=False ,   lowerCamelCase=True ,   lowerCamelCase=True ,   lowerCamelCase=("en_XX",) ,   lowerCamelCase=None ,   **lowerCamelCase ,   )							->Any:



         '''simple docstring'''
         super().__init__(pad_token_id=lowerCamelCase ,   bos_token_id=lowerCamelCase ,   eos_token_id=lowerCamelCase ,   **lowerCamelCase      )

         __a				     =    vocab_size
         __a				     =    hidden_size
         __a				     =    num_hidden_layers
         __a				     =    num_attention_heads
         __a				     =    hidden_act
         __a				     =    intermediate_size
         __a				     =    hidden_dropout_prob
         __a				     =    attention_probs_dropout_prob
         __a				     =    max_position_embeddings
         __a				     =    type_vocab_size
         __a				     =    initializer_range
         __a				     =    layer_norm_eps
         __a				     =    position_embedding_type
         __a				     =    use_cache
         __a				     =    classifier_dropout
         __a				     =    pre_norm
         __a				     =    adapter_reduction_factor
         __a				     =    adapter_layer_norm
         __a				     =    adapter_reuse_layer_norm
         __a				     =    ln_before_adapter
         __a				     =    list(lowerCamelCase      )
         __a				     =    default_language







class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):




      @property
      def  __UpperCamelCase							(  self      )							->Mapping[str, Mapping[int, str]]:



         '''simple docstring'''
         if self.task == "multiple-choice":
            __a				     =    {0: 'batch', 1: 'choice', 2: 'sequence'}
         else:
            __a				     =    {0: 'batch', 1: 'sequence'}
         return OrderedDict(
             [
                 ('input_ids', dynamic_axis),
                 ('attention_mask', dynamic_axis),
             ]      )