


import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVePipeline, ScoreSdeVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()





class  lowerCAmelCase__(    unittest.TestCase						):






    '''simple docstring'''





    @property
    def 					_lowerCamelCase (	self				:   List[str]	):





       '''simple docstring'''
       torch.manual_seed(0	)
       UpperCAmelCase_							:      Any						=   UNetaDModel(
           block_out_channels=(32, 64)       ,   layers_per_block=2       ,   sample_size=32       ,   in_channels=3       ,   out_channels=3       ,   down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')       ,   up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')       ,   )
       return model





    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       UpperCAmelCase_							:      Tuple						=   self.dummy_uncond_unet
       UpperCAmelCase_							:      Optional[int]						=   ScoreSdeVeScheduler()

       UpperCAmelCase_							:      str						=   ScoreSdeVePipeline(unet=__snake_case       ,   scheduler=__snake_case	)
       sde_ve.to(__snake_case	)
       sde_ve.set_progress_bar_config(disable=__snake_case	)

       UpperCAmelCase_							:      str						=   torch.manual_seed(0	)
       UpperCAmelCase_							:      Union[str, Any]						=   sde_ve(num_inference_steps=2       ,   output_type='''numpy'''       ,   generator=__snake_case	).images

       UpperCAmelCase_							:      str						=   torch.manual_seed(0	)
       UpperCAmelCase_							:      Dict						=   sde_ve(num_inference_steps=2       ,   output_type='''numpy'''       ,   generator=__snake_case       ,   return_dict=__snake_case	)[
           0
       ]

       UpperCAmelCase_							:      Dict						=   image[0, -3:, -3:, -1]
       UpperCAmelCase_							:      List[str]						=   image_from_tuple[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       UpperCAmelCase_							:      Any						=   np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]	)

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





@slow
@require_torch
class  lowerCAmelCase__(    unittest.TestCase						):






    '''simple docstring'''





    def 					_lowerCamelCase (	self				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   '''google/ncsnpp-church-256'''
       UpperCAmelCase_							:      Dict						=   UNetaDModel.from_pretrained(__snake_case	)

       UpperCAmelCase_							:      List[Any]						=   ScoreSdeVeScheduler.from_pretrained(__snake_case	)

       UpperCAmelCase_							:      Optional[int]						=   ScoreSdeVePipeline(unet=__snake_case       ,   scheduler=__snake_case	)
       sde_ve.to(__snake_case	)
       sde_ve.set_progress_bar_config(disable=__snake_case	)

       UpperCAmelCase_							:      Any						=   torch.manual_seed(0	)
       UpperCAmelCase_							:      Tuple						=   sde_ve(num_inference_steps=10       ,   output_type='''numpy'''       ,   generator=__snake_case	).images

       UpperCAmelCase_							:      Optional[Any]						=   image[0, -3:, -3:, -1]

       assert image.shape == (1, 256, 256, 3)

       UpperCAmelCase_							:      Union[str, Any]						=   np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]	)

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



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


__UpperCamelCase				:  str      					=							logging.get_logger(__name__)

__UpperCamelCase				:  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  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     int			= 'falcon'
    A_  :     int			= ['past_key_values']





    def __init__(	self				:   Optional[Any]       ,   __snake_case				:   Tuple=65_024       ,   __snake_case				:   List[str]=4_544       ,   __snake_case				:   Optional[Any]=32       ,   __snake_case				:   Any=71       ,   __snake_case				:   str=1E-5       ,   __snake_case				:   List[str]=0.02       ,   __snake_case				:   List[Any]=True       ,   __snake_case				:   Dict=0.0       ,   __snake_case				:   Optional[Any]=0.0       ,   __snake_case				:   Any=None       ,   __snake_case				:   List[Any]=False       ,   __snake_case				:   Dict=False       ,   __snake_case				:   Optional[int]=True       ,   __snake_case				:   List[Any]=True       ,   __snake_case				:   Optional[Any]=False       ,   __snake_case				:   Dict=11       ,   __snake_case				:   List[str]=11       ,   **__snake_case				:   int       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      int						=   vocab_size
       # Backward compatibility with n_embed kwarg
       UpperCAmelCase_							:      Union[str, Any]						=   kwargs.pop('''n_embed'''       ,   __snake_case	)
       UpperCAmelCase_							:      str						=   hidden_size if n_embed is None else n_embed
       UpperCAmelCase_							:      Tuple						=   num_hidden_layers
       UpperCAmelCase_							:      Tuple						=   num_attention_heads
       UpperCAmelCase_							:      Optional[int]						=   layer_norm_epsilon
       UpperCAmelCase_							:      int						=   initializer_range
       UpperCAmelCase_							:      Optional[int]						=   use_cache
       UpperCAmelCase_							:      List[Any]						=   hidden_dropout
       UpperCAmelCase_							:      Any						=   attention_dropout

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

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





    @property
    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       return self.hidden_size // self.num_attention_heads





    @property
    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       return not self.alibi