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


lowerCamelCase__     :		Union[str, Any]        = logging.get_logger(__name__)

lowerCamelCase__     :		Optional[Any]        = {
    """s-JoL/Open-Llama-V1""": """https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json""",
}



class    _snake_case (						UpperCAmelCase_				):
 __lowerCAmelCase	:  int	   =      'open-llama'


 def __init__(       self       ,	SCREAMING_SNAKE_CASE_=10_00_00       ,	SCREAMING_SNAKE_CASE_=40_96       ,	SCREAMING_SNAKE_CASE_=1_10_08       ,	SCREAMING_SNAKE_CASE_=32       ,	SCREAMING_SNAKE_CASE_=32       ,	SCREAMING_SNAKE_CASE_="silu"       ,	SCREAMING_SNAKE_CASE_=20_48       ,	SCREAMING_SNAKE_CASE_=0.0_2       ,	SCREAMING_SNAKE_CASE_=1E-6       ,	SCREAMING_SNAKE_CASE_=True       ,	SCREAMING_SNAKE_CASE_=0       ,	SCREAMING_SNAKE_CASE_=1       ,	SCREAMING_SNAKE_CASE_=2       ,	SCREAMING_SNAKE_CASE_=False       ,	SCREAMING_SNAKE_CASE_=True       ,	SCREAMING_SNAKE_CASE_=0.1       ,	SCREAMING_SNAKE_CASE_=0.1       ,	SCREAMING_SNAKE_CASE_=True       ,	SCREAMING_SNAKE_CASE_=True       ,	SCREAMING_SNAKE_CASE_=None       ,	**SCREAMING_SNAKE_CASE_       ,	):


   '''simple docstring'''




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

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



 def   lowercase__  (       self):


   '''simple docstring'''




   if self.rope_scaling is None:
     return

   if not isinstance(self.rope_scaling       ,	SCREAMING_SNAKE_CASE_) 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}')
   lowercase__	: int     		=   self.rope_scaling.get("""type"""       ,	SCREAMING_SNAKE_CASE_)
   lowercase__	: Optional[int]     		=   self.rope_scaling.get("""factor"""       ,	SCREAMING_SNAKE_CASE_)
   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(SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_) or rope_scaling_factor <= 1.0:
     raise ValueError(f'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}')








import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import ViTImageProcessor



class    _snake_case (						unittest.TestCase				):


 def __init__(       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_=13       ,	SCREAMING_SNAKE_CASE_=3       ,	SCREAMING_SNAKE_CASE_=2_24       ,	SCREAMING_SNAKE_CASE_=30       ,	SCREAMING_SNAKE_CASE_=4_00       ,	SCREAMING_SNAKE_CASE_=True       ,	SCREAMING_SNAKE_CASE_=None       ,	SCREAMING_SNAKE_CASE_=True       ,	SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]       ,	SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]       ,	):


   '''simple docstring'''




   lowercase__	: List[str]     		=   size if size is not None else {"""height""": 18, """width""": 18}
   lowercase__	: int     		=   parent
   lowercase__	: Union[str, Any]     		=   batch_size
   lowercase__	: List[str]     		=   num_channels
   lowercase__	: str     		=   image_size
   lowercase__	: int     		=   min_resolution
   lowercase__	: Dict     		=   max_resolution
   lowercase__	: Tuple     		=   do_resize
   lowercase__	: Union[str, Any]     		=   size
   lowercase__	: Any     		=   do_normalize
   lowercase__	: Tuple     		=   image_mean
   lowercase__	: str     		=   image_std



 def   lowercase__  (       self):


   '''simple docstring'''




   return {
       "image_mean": self.image_mean,
       "image_std": self.image_std,
       "do_normalize": self.do_normalize,
       "do_resize": self.do_resize,
       "size": self.size,
   }



@require_torch
@require_vision
class    _snake_case (						UpperCAmelCase_	,    unittest.TestCase				):
 __lowerCAmelCase	:  Optional[Any]	   =      ViTImageProcessor if is_vision_available() else None


 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: str     		=   EfficientFormerImageProcessorTester(self)


 @property
 def   lowercase__  (       self):


   '''simple docstring'''




   return self.image_proc_tester.prepare_image_processor_dict()


 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: Any     		=   self.image_processing_class(**self.image_processor_dict)
   self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,	"""image_mean"""))
   self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,	"""image_std"""))
   self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,	"""do_normalize"""))
   self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,	"""do_resize"""))
   self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_       ,	"""size"""))


 def   lowercase__  (       self):


   '''simple docstring'''




   pass


 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: str     		=   self.image_processing_class(**self.image_processor_dict)
   # create random PIL images
   lowercase__	: List[Any]     		=   prepare_image_inputs(self.image_proc_tester       ,	equal_resolution=SCREAMING_SNAKE_CASE_)
   for image in image_inputs:
     self.assertIsInstance(SCREAMING_SNAKE_CASE_       ,	Image.Image)

   # Test not batched input
   lowercase__	: int     		=   image_processor(image_inputs[0]       ,	return_tensors="""pt""").pixel_values
   self.assertEqual(
       encoded_images.shape       ,	(
           1,
           self.image_proc_tester.num_channels,
           self.image_proc_tester.size["""height"""],
           self.image_proc_tester.size["""width"""],
       )       ,	)

   # Test batched
   lowercase__	: str     		=   image_processor(SCREAMING_SNAKE_CASE_       ,	return_tensors="""pt""").pixel_values
   self.assertEqual(
       encoded_images.shape       ,	(
           self.image_proc_tester.batch_size,
           self.image_proc_tester.num_channels,
           self.image_proc_tester.size["""height"""],
           self.image_proc_tester.size["""width"""],
       )       ,	)


 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: Tuple     		=   self.image_processing_class(**self.image_processor_dict)
   # create random numpy tensors
   lowercase__	: str     		=   prepare_image_inputs(self.image_proc_tester       ,	equal_resolution=SCREAMING_SNAKE_CASE_       ,	numpify=SCREAMING_SNAKE_CASE_)
   for image in image_inputs:
     self.assertIsInstance(SCREAMING_SNAKE_CASE_       ,	np.ndarray)

   # Test not batched input
   lowercase__	: Optional[int]     		=   image_processor(image_inputs[0]       ,	return_tensors="""pt""").pixel_values
   self.assertEqual(
       encoded_images.shape       ,	(
           1,
           self.image_proc_tester.num_channels,
           self.image_proc_tester.size["""height"""],
           self.image_proc_tester.size["""width"""],
       )       ,	)

   # Test batched
   lowercase__	: Dict     		=   image_processor(SCREAMING_SNAKE_CASE_       ,	return_tensors="""pt""").pixel_values
   self.assertEqual(
       encoded_images.shape       ,	(
           self.image_proc_tester.batch_size,
           self.image_proc_tester.num_channels,
           self.image_proc_tester.size["""height"""],
           self.image_proc_tester.size["""width"""],
       )       ,	)



 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: List[str]     		=   self.image_processing_class(**self.image_processor_dict)
   # create random PyTorch tensors
   lowercase__	: Dict     		=   prepare_image_inputs(self.image_proc_tester       ,	equal_resolution=SCREAMING_SNAKE_CASE_       ,	torchify=SCREAMING_SNAKE_CASE_)
   for image in image_inputs:
     self.assertIsInstance(SCREAMING_SNAKE_CASE_       ,	torch.Tensor)

   # Test not batched input
   lowercase__	: int     		=   image_processor(image_inputs[0]       ,	return_tensors="""pt""").pixel_values
   self.assertEqual(
       encoded_images.shape       ,	(
           1,
           self.image_proc_tester.num_channels,
           self.image_proc_tester.size["""height"""],
           self.image_proc_tester.size["""width"""],
       )       ,	)

   # Test batched
   lowercase__	: Any     		=   image_processor(SCREAMING_SNAKE_CASE_       ,	return_tensors="""pt""").pixel_values
   self.assertEqual(
       encoded_images.shape       ,	(
           self.image_proc_tester.batch_size,
           self.image_proc_tester.num_channels,
           self.image_proc_tester.size["""height"""],
           self.image_proc_tester.size["""width"""],
       )       ,	)






