




"""simple docstring"""






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


lowercase__  		=		logging.get_logger(__name__)

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






class lowerCAmelCase__			(  lowercase		):






			'''simple docstring'''



			lowerCamelCase__   =    """open-llama"""
			def __init__(						self						,   lowercase=100000						,   lowercase=4096						,   lowercase=11008						,   lowercase=32						,   lowercase=32						,   lowercase="silu"						,   lowercase=2048						,   lowercase=0.02						,   lowercase=1E-6						,   lowercase=True						,   lowercase=0						,   lowercase=1						,   lowercase=2						,   lowercase=False						,   lowercase=True						,   lowercase=0.1						,   lowercase=0.1						,   lowercase=True						,   lowercase=True						,   lowercase=None						,   **lowercase						,   ):
							_lowerCamelCase  :    List[Any]					=					vocab_size
							_lowerCamelCase  :    str					=					max_position_embeddings
							_lowerCamelCase  :    str					=					hidden_size
							_lowerCamelCase  :    int					=					intermediate_size
							_lowerCamelCase  :    Optional[int]					=					num_hidden_layers
							_lowerCamelCase  :    str					=					num_attention_heads
							_lowerCamelCase  :    Tuple					=					hidden_act
							_lowerCamelCase  :    Any					=					initializer_range
							_lowerCamelCase  :    List[Any]					=					rms_norm_eps
							_lowerCamelCase  :    Optional[int]					=					use_cache
							_lowerCamelCase  :    List[Any]					=					kwargs.pop(
							    'use_memorry_efficient_attention'						,   lowercase						)
							_lowerCamelCase  :    List[str]					=					hidden_dropout_prob
							_lowerCamelCase  :    Any					=					attention_dropout_prob
							_lowerCamelCase  :    Any					=					use_stable_embedding
							_lowerCamelCase  :    Dict					=					shared_input_output_embedding
							_lowerCamelCase  :    str					=					rope_scaling
							self._rope_scaling_validation()

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






			def       A_					(						self						):
							if self.rope_scaling is None:
											return

							if not isinstance(self.rope_scaling						,   lowercase						) 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}'''						)
							_lowerCamelCase  :    Union[str, Any]					=					self.rope_scaling.get('type'						,   lowercase						)
							_lowerCamelCase  :    Optional[Any]					=					self.rope_scaling.get('factor'						,   lowercase						)
							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(lowercase						,   lowercase						) 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

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
			from PIL import Image
else:






			class lowerCAmelCase__			:






						'''simple docstring'''



						@staticmethod
						def       A_					(						*lowercase						,   **lowercase						):
										pass






@is_pipeline_test
@require_vision
class lowerCAmelCase__			(  unittest.TestCase		):






			'''simple docstring'''



			@require_torch
			def       A_					(						self						):
							_lowerCamelCase  :    int					=					pipeline(
							    model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'						,   )
							_lowerCamelCase  :    List[Any]					=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
							_lowerCamelCase  :    List[str]					=					image_classifier(lowercase						,   candidate_labels=['a', 'b', 'c']						)

							# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
							# python and torch versions.
							self.assertIn(
							    nested_simplify(lowercase						)						,   [
							        [{'score': 0.3_33, 'label': 'a'}, {'score': 0.3_33, 'label': 'b'}, {'score': 0.3_33, 'label': 'c'}],
							        [{'score': 0.3_33, 'label': 'a'}, {'score': 0.3_33, 'label': 'c'}, {'score': 0.3_33, 'label': 'b'}],
							    ]						,   )

							_lowerCamelCase  :    Optional[Any]					=					image_classifier([image] * 5						,   candidate_labels=['A', 'B', 'C']						,   batch_size=2						)
							self.assertEqual(
							    nested_simplify(lowercase						)						,   [
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							    ]						,   )
			@require_tf
			def       A_					(						self						):
							_lowerCamelCase  :    Optional[Any]					=					pipeline(
							    model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'						,   framework='tf'						)
							_lowerCamelCase  :    Tuple					=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
							_lowerCamelCase  :    Optional[int]					=					image_classifier(lowercase						,   candidate_labels=['a', 'b', 'c']						)

							self.assertEqual(
							    nested_simplify(lowercase						)						,   [{'score': 0.3_33, 'label': 'a'}, {'score': 0.3_33, 'label': 'b'}, {'score': 0.3_33, 'label': 'c'}]						,   )

							_lowerCamelCase  :    Optional[Any]					=					image_classifier([image] * 5						,   candidate_labels=['A', 'B', 'C']						,   batch_size=2						)
							self.assertEqual(
							    nested_simplify(lowercase						)						,   [
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							        [
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							            {'score': 0.3_33, 'label': ANY(lowercase						)},
							        ],
							    ]						,   )
			@slow
			@require_torch
			def       A_					(						self						):
							_lowerCamelCase  :    Tuple					=					pipeline(
							    task='zero-shot-image-classification'						,   model='openai/clip-vit-base-patch32'						,   )
							# This is an image of 2 cats with remotes and no planes
							_lowerCamelCase  :    Optional[Any]					=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
							_lowerCamelCase  :    Optional[Any]					=					image_classifier(lowercase						,   candidate_labels=['cat', 'plane', 'remote']						)

							self.assertEqual(
							    nested_simplify(lowercase						)						,   [
							        {'score': 0.5_11, 'label': 'remote'},
							        {'score': 0.4_85, 'label': 'cat'},
							        {'score': 0.0_04, 'label': 'plane'},
							    ]						,   )

							_lowerCamelCase  :    Dict					=					image_classifier([image] * 5						,   candidate_labels=['cat', 'plane', 'remote']						,   batch_size=2						)
							self.assertEqual(
							    nested_simplify(lowercase						)						,   [
							        [
							            {'score': 0.5_11, 'label': 'remote'},
							            {'score': 0.4_85, 'label': 'cat'},
							            {'score': 0.0_04, 'label': 'plane'},
							        ],
							    ]
							    * 5						,   )






			@slow
			@require_tf
			def       A_					(						self						):
							_lowerCamelCase  :    List[str]					=					pipeline(
							    task='zero-shot-image-classification'						,   model='openai/clip-vit-base-patch32'						,   framework='tf'						)
							# This is an image of 2 cats with remotes and no planes
							_lowerCamelCase  :    List[str]					=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
							_lowerCamelCase  :    Tuple					=					image_classifier(lowercase						,   candidate_labels=['cat', 'plane', 'remote']						)
							self.assertEqual(
							    nested_simplify(lowercase						)						,   [
							        {'score': 0.5_11, 'label': 'remote'},
							        {'score': 0.4_85, 'label': 'cat'},
							        {'score': 0.0_04, 'label': 'plane'},
							    ]						,   )

							_lowerCamelCase  :    Dict					=					image_classifier([image] * 5						,   candidate_labels=['cat', 'plane', 'remote']						,   batch_size=2						)
							self.assertEqual(
							    nested_simplify(lowercase						)						,   [
							        [
							            {'score': 0.5_11, 'label': 'remote'},
							            {'score': 0.4_85, 'label': 'cat'},
							            {'score': 0.0_04, 'label': 'plane'},
							        ],
							    ]
							    * 5						,   )