


"""simple docstring"""



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


__snake_case             =   logging.get_logger(__name__)

__snake_case             =   {
    """s-JoL/Open-Llama-V1""": """https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json""",
}





class _lowerCAmelCase    (				snake_case_     ):
   __UpperCAmelCase			:	str							  =  '''open-llama'''







   def __init__(     self						,     UpperCamelCase__=10_0000						,     UpperCamelCase__=4096						,     UpperCamelCase__=1_1008						,     UpperCamelCase__=32						,     UpperCamelCase__=32						,     UpperCamelCase__="silu"						,     UpperCamelCase__=2048						,     UpperCamelCase__=0.02						,     UpperCamelCase__=1e-6						,     UpperCamelCase__=True						,     UpperCamelCase__=0						,     UpperCamelCase__=1						,     UpperCamelCase__=2						,     UpperCamelCase__=False						,     UpperCamelCase__=True						,     UpperCamelCase__=0.1						,     UpperCamelCase__=0.1						,     UpperCamelCase__=True						,     UpperCamelCase__=True						,     UpperCamelCase__=None						,     **UpperCamelCase__						,     )     ->		Union[str, Any]:

       '''simple docstring'''




       snake_case   :				Optional[Any]				 =   vocab_size
       snake_case   :				Dict				 =   max_position_embeddings
       snake_case   :				List[Any]				 =   hidden_size
       snake_case   :				Dict				 =   intermediate_size
       snake_case   :				Dict				 =   num_hidden_layers
       snake_case   :				Any				 =   num_attention_heads
       snake_case   :				Optional[int]				 =   hidden_act
       snake_case   :				str				 =   initializer_range
       snake_case   :				List[Any]				 =   rms_norm_eps
       snake_case   :				List[Any]				 =   use_cache
       snake_case   :				List[str]				 =   kwargs.pop(
           "use_memorry_efficient_attention"						,     UpperCamelCase__						)
       snake_case   :				Union[str, Any]				 =   hidden_dropout_prob
       snake_case   :				str				 =   attention_dropout_prob
       snake_case   :				Tuple				 =   use_stable_embedding
       snake_case   :				Optional[Any]				 =   shared_input_output_embedding
       snake_case   :				Union[str, Any]				 =   rope_scaling
       self._rope_scaling_validation()

       super().__init__(
           pad_token_id=UpperCamelCase__						,     bos_token_id=UpperCamelCase__						,     eos_token_id=UpperCamelCase__						,     tie_word_embeddings=UpperCamelCase__						,     **UpperCamelCase__						,     )







   def 			lowerCamelCase		(     self						)     ->		List[str]:

       '''simple docstring'''




       if self.rope_scaling is None:
           return

       if not isinstance(self.rope_scaling						,     UpperCamelCase__						) or len(self.rope_scaling						) != 2:
           raise ValueError(
               "`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, "
               F'got {self.rope_scaling}'						)
       snake_case   :				Any				 =   self.rope_scaling.get("type"						,     UpperCamelCase__						)
       snake_case   :				int				 =   self.rope_scaling.get("factor"						,     UpperCamelCase__						)
       if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
           raise ValueError(
               F'`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'						)
       if rope_scaling_factor is None or not isinstance(UpperCamelCase__						,     UpperCamelCase__						) or rope_scaling_factor <= 1.0:
           raise ValueError(F'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'						)









"""simple docstring"""



import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class _lowerCAmelCase    (				unittest.TestCase     ):







   @property
   def 			lowerCamelCase		(     self						)     ->		str:

       '''simple docstring'''




       torch.manual_seed(0						)
       snake_case   :				int				 =   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						)     ->		Any:

       '''simple docstring'''




       snake_case   :				Any				 =   self.dummy_uncond_unet
       snake_case   :				Tuple				 =   KarrasVeScheduler()

       snake_case   :				int				 =   KarrasVePipeline(unet=UpperCamelCase__						,     scheduler=UpperCamelCase__						)
       pipe.to(UpperCamelCase__						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case   :				Optional[Any]				 =   torch.manual_seed(0						)
       snake_case   :				List[Any]				 =   pipe(num_inference_steps=2						,     generator=UpperCamelCase__						,     output_type="numpy"						).images

       snake_case   :				Dict				 =   torch.manual_seed(0						)
       snake_case   :				Dict				 =   pipe(num_inference_steps=2						,     generator=UpperCamelCase__						,     output_type="numpy"						,     return_dict=UpperCamelCase__						)[0]

       snake_case   :				Tuple				 =   image[0, -3:, -3:, -1]
       snake_case   :				Tuple				 =   image_from_tuple[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       snake_case   :				int				 =   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     ):







   def 			lowerCamelCase		(     self						)     ->		List[Any]:

       '''simple docstring'''




       snake_case   :				Optional[Any]				 =   "google/ncsnpp-celebahq-256"
       snake_case   :				List[str]				 =   UNetaDModel.from_pretrained(UpperCamelCase__						)
       snake_case   :				Optional[Any]				 =   KarrasVeScheduler()

       snake_case   :				Optional[int]				 =   KarrasVePipeline(unet=UpperCamelCase__						,     scheduler=UpperCamelCase__						)
       pipe.to(UpperCamelCase__						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case   :				Dict				 =   torch.manual_seed(0						)
       snake_case   :				Union[str, Any]				 =   pipe(num_inference_steps=20						,     generator=UpperCamelCase__						,     output_type="numpy"						).images

       snake_case   :				int				 =   image[0, -3:, -3:, -1]
       assert image.shape == (1, 256, 256, 3)
       snake_case   :				Any				 =   np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]						)

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





