

import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


A_	:			List[str]  	=					False



class    _a						(unittest.TestCase    ):


					'''simple docstring'''






					pass



@nightly
@require_torch_gpu
class    _a						(unittest.TestCase    ):


					'''simple docstring'''






					def   __A      (			self      ):
						# clean up the VRAM after each test
						super().tearDown()
						gc.collect()
						torch.cuda.empty_cache()






					def   __A      (			self      ):
						A__							:   Union[str, Any]					       =		VersatileDiffusionTextToImagePipeline.from_pretrained("""shi-labs/versatile-diffusion"""      )
						# remove text_unet
						pipe.remove_unused_weights()
						pipe.to(_a      )
						pipe.set_progress_bar_config(disable=_a      )

						A__							:   Union[str, Any]					       =		"A painting of a squirrel eating a burger "
						A__							:   Optional[Any]					       =		torch.manual_seed(0      )
						A__							:   str					       =		pipe(
						    prompt=_a   ,	generator=_a   ,	guidance_scale=7.5   ,	num_inference_steps=2   ,	output_type="""numpy"""      ).images

						with tempfile.TemporaryDirectory() as tmpdirname:
							pipe.save_pretrained(_a      )
							A__							:   Tuple					       =		VersatileDiffusionTextToImagePipeline.from_pretrained(_a      )
						pipe.to(_a      )
						pipe.set_progress_bar_config(disable=_a      )

						A__							:   int					       =		generator.manual_seed(0      )
						A__							:   Union[str, Any]					       =		pipe(
						    prompt=_a   ,	generator=_a   ,	guidance_scale=7.5   ,	num_inference_steps=2   ,	output_type="""numpy"""      ).images

						assert np.abs(image - new_image      ).sum() < 1e-5, "Models don't have the same forward pass"






					def   __A      (			self      ):
						A__							:   Tuple					       =		VersatileDiffusionTextToImagePipeline.from_pretrained(
						    """shi-labs/versatile-diffusion"""   ,	torch_dtype=torch.floataa      )
						pipe.to(_a      )
						pipe.set_progress_bar_config(disable=_a      )

						A__							:   List[str]					       =		"A painting of a squirrel eating a burger "
						A__							:   Any					       =		torch.manual_seed(0      )
						A__							:   Dict					       =		pipe(
						    prompt=_a   ,	generator=_a   ,	guidance_scale=7.5   ,	num_inference_steps=50   ,	output_type="""numpy"""      ).images

						A__							:   List[Any]					       =		image[0, 253:256, 253:256, -1]

						assert image.shape == (1, 512, 512, 3)
						A__							:   List[str]					       =		np.array([0.3_3_6_7, 0.3_1_6_9, 0.2_6_5_6, 0.3_8_7_0, 0.4_7_9_0, 0.3_7_9_6, 0.4_0_0_9, 0.4_8_7_8, 0.4_7_7_8]      )

						assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-2






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


A_	:			str  	=      logging.get_logger(__name__)

A_	:			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    _a						(__magic_name__    ):


					'''simple docstring'''






					UpperCAmelCase__:       Dict  							=	'''falcon'''
					UpperCAmelCase__:       Any  							=	['''past_key_values''']






					def __init__(			self   ,	A__=6_5024   ,	A__=4544   ,	A__=32   ,	A__=71   ,	A__=1e-5   ,	A__=0.0_2   ,	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__   ,	):
						A__							:   Dict					       =		vocab_size
						# Backward compatibility with n_embed kwarg
						A__							:   Union[str, Any]					       =		kwargs.pop("""n_embed"""   ,	A__      )
						A__							:   Optional[Any]					       =		hidden_size if n_embed is None else n_embed
						A__							:   Any					       =		num_hidden_layers
						A__							:   Any					       =		num_attention_heads
						A__							:   Optional[Any]					       =		layer_norm_epsilon
						A__							:   Tuple					       =		initializer_range
						A__							:   Tuple					       =		use_cache
						A__							:   str					       =		hidden_dropout
						A__							:   List[str]					       =		attention_dropout

						A__							:   List[Any]					       =		bos_token_id
						A__							:   Optional[Any]					       =		eos_token_id
						A__							:   Optional[Any]					       =		num_attention_heads if num_kv_heads is None else num_kv_heads
						A__							:   List[str]					       =		alibi
						A__							:   Tuple					       =		new_decoder_architecture
						A__							:   List[str]					       =		multi_query  # Ignored when new_decoder_architecture is True
						A__							:   List[Any]					       =		parallel_attn
						A__							:   int					       =		bias

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






					@property
					def   __A      (			self      ):
						return self.hidden_size // self.num_attention_heads






					@property
					def   __A      (			self      ):
						return not self.alibi



