
from ...configuration_utils import PretrainedConfig
from ...utils import logging


_UpperCAmelCase					: int      =       logging.get_logger(__name__)

_UpperCAmelCase					: List[Any]      =       {
    "tiiuae/falcon-40b": "https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json",
    "tiiuae/falcon-7b": "https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json",
}


class 				lowercase					(		_SCREAMING_SNAKE_CASE   ):
		__lowercase       :       Any	     =				"falcon"
		__lowercase       :       Optional[int]	     =				["past_key_values"]



		def __init__( self				,      A_=65_024				,      A_=4_544				,      A_=32				,      A_=71				,      A_=1e-5				,      A_=0.02				,      A_=True				,      A_=0.0				,      A_=0.0				,      A_=None				,      A_=False				,      A_=False				,      A_=True				,      A_=True				,      A_=False				,      A_=11				,      A_=11				,      **A_				,      )  ->					Union[str, Any]:
				"""simple docstring"""
				UpperCamelCase		=     vocab_size
				# Backward compatibility with n_embed kwarg
				UpperCamelCase		=     kwargs.pop('n_embed'				,      A_       )
				UpperCamelCase		=     hidden_size if n_embed is None else n_embed
				UpperCamelCase		=     num_hidden_layers
				UpperCamelCase		=     num_attention_heads
				UpperCamelCase		=     layer_norm_epsilon
				UpperCamelCase		=     initializer_range
				UpperCamelCase		=     use_cache
				UpperCamelCase		=     hidden_dropout
				UpperCamelCase		=     attention_dropout

				UpperCamelCase		=     bos_token_id
				UpperCamelCase		=     eos_token_id
				UpperCamelCase		=     num_attention_heads if num_kv_heads is None else num_kv_heads
				UpperCamelCase		=     alibi
				UpperCamelCase		=     new_decoder_architecture
				UpperCamelCase		=     multi_query  # Ignored when new_decoder_architecture is True
				UpperCamelCase		=     parallel_attn
				UpperCamelCase		=     bias

				super().__init__(bos_token_id=A_				,      eos_token_id=A_				,      **A_       )



		@property
		def __UpperCamelCase ( self       )  ->					Optional[int]:
				"""simple docstring"""
				return self.hidden_size // self.num_attention_heads



		@property
		def __UpperCamelCase ( self       )  ->					Union[str, Any]:
				"""simple docstring"""
				return not self.alibi


import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
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 				lowercase					(		_SCREAMING_SNAKE_CASE  ,   _SCREAMING_SNAKE_CASE  ,   unittest.TestCase   ):
		__lowercase       :       int	     =				IFInpaintingPipeline
		__lowercase       :       str	     =				TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
		__lowercase       :       Optional[int]	     =				TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
		__lowercase       :       Optional[int]	     =				PipelineTesterMixin.required_optional_params - {"latents"}



		def __UpperCamelCase ( self       )  ->					List[str]:
				"""simple docstring"""
				return self._get_dummy_components()



		def __UpperCamelCase ( self				,      A_				,      A_=0       )  ->					List[Any]:
				"""simple docstring"""
				if str(A_       ).startswith('mps'       ):
						UpperCamelCase		=     torch.manual_seed(A_       )
				else:
						UpperCamelCase		=     torch.Generator(device=A_       ).manual_seed(A_       )

				UpperCamelCase		=     floats_tensor((1, 3, 32, 32)				,      rng=random.Random(A_       )       ).to(A_       )
				UpperCamelCase		=     floats_tensor((1, 3, 32, 32)				,      rng=random.Random(A_       )       ).to(A_       )

				UpperCamelCase		=     {
				    'prompt': 'A painting of a squirrel eating a burger',
				    'image': 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       )  ->					str:
				"""simple docstring"""
				self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3       )



		def __UpperCamelCase ( self       )  ->					str:
				"""simple docstring"""
				self._test_save_load_optional_components()



		@unittest.skipIf(torch_device != 'cuda'				,      reason='float16 requires CUDA'       )
		def __UpperCamelCase ( self       )  ->					str:
				"""simple docstring"""
				# 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]:
				"""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       )  ->					Dict:
				"""simple docstring"""
				self._test_inference_batch_single_identical(
				    expected_max_diff=1e-2				,      )
