


'''simple docstring'''




import os
import tempfile
import unittest
import uuid
from pathlib import Path

from transformers.testing_utils import get_tests_dir, require_soundfile, require_torch, require_vision
from transformers.tools.agent_types import AgentAudio, AgentImage, AgentText
from transformers.utils import is_soundfile_availble, is_torch_available, is_vision_available


if is_torch_available():
							import torch

if is_soundfile_availble():
							import soundfile as sf

if is_vision_available():
							from PIL import Image

def 			__UpperCamelCase    (    _A    :				List[Any]=""				)    ->      str:




	"""simple docstring"""





	lowerCAmelCase					:    Tuple      							= tempfile.mkdtemp()
	return os.path.join(_A					,   str(uuid.uuida()				) + suffix				)



@require_soundfile
@require_torch
class  lowerCAmelCase				(				unittest.TestCase							):



	def 				lowercase     (					self    ):
		lowerCAmelCase					:    Union[str, Any]      							= torch.rand(12 ,					dtype=torch.floataa    ) - 0.5
		lowerCAmelCase					:    Tuple      							= AgentAudio(snake_case__    )
		lowerCAmelCase					:    List[Any]      							= str(agent_type.to_string()    )

		# Ensure that the tensor and the agent_type's tensor are the same
		self.assertTrue(torch.allclose(snake_case__ ,					agent_type.to_raw() ,					atol=1e-4    )    )

		del agent_type

		# Ensure the path remains even after the object deletion
		self.assertTrue(os.path.exists(snake_case__    )    )

		# Ensure that the file contains the same value as the original tensor
		lowerCAmelCase					:    int      							= sf.read(snake_case__    )
		self.assertTrue(torch.allclose(snake_case__ ,					torch.tensor(snake_case__    ) ,					atol=1e-4    )    )



	def 				lowercase     (					self    ):
		lowerCAmelCase					:    Tuple      							= torch.rand(12 ,					dtype=torch.floataa    ) - 0.5
		lowerCAmelCase					:    str      							= get_new_path(suffix='.wav'    )
		sf.write(snake_case__ ,					snake_case__ ,					1_6000    )

		lowerCAmelCase					:    List[str]      							= AgentAudio(snake_case__    )

		self.assertTrue(torch.allclose(snake_case__ ,					agent_type.to_raw() ,					atol=1e-4    )    )
		self.assertEqual(agent_type.to_string() ,					snake_case__    )



@require_vision
@require_torch
class  lowerCAmelCase				(				unittest.TestCase							):



	def 				lowercase     (					self    ):
		lowerCAmelCase					:    str      							= torch.randint(0 ,					256 ,					(64, 64, 3)    )
		lowerCAmelCase					:    List[Any]      							= AgentImage(snake_case__    )
		lowerCAmelCase					:    int      							= str(agent_type.to_string()    )

		# Ensure that the tensor and the agent_type's tensor are the same
		self.assertTrue(torch.allclose(snake_case__ ,					agent_type._tensor ,					atol=1e-4    )    )

		self.assertIsInstance(agent_type.to_raw() ,					Image.Image    )

		# Ensure the path remains even after the object deletion
		del agent_type
		self.assertTrue(os.path.exists(snake_case__    )    )



	def 				lowercase     (					self    ):
		lowerCAmelCase					:    List[str]      							= Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'
		lowerCAmelCase					:    int      							= Image.open(snake_case__    )
		lowerCAmelCase					:    Optional[int]      							= AgentImage(snake_case__    )

		self.assertTrue(path.samefile(agent_type.to_string()    )    )
		self.assertTrue(image == agent_type.to_raw()    )

		# Ensure the path remains even after the object deletion
		del agent_type
		self.assertTrue(os.path.exists(snake_case__    )    )



	def 				lowercase     (					self    ):
		lowerCAmelCase					:    Any      							= Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'
		lowerCAmelCase					:    Optional[Any]      							= Image.open(snake_case__    )
		lowerCAmelCase					:    str      							= AgentImage(snake_case__    )

		self.assertFalse(path.samefile(agent_type.to_string()    )    )
		self.assertTrue(image == agent_type.to_raw()    )

		# Ensure the path remains even after the object deletion
		del agent_type
		self.assertTrue(os.path.exists(snake_case__    )    )



class  lowerCAmelCase				(				unittest.TestCase							):



	def 				lowercase     (					self    ):
		lowerCAmelCase					:    Optional[int]      							= 'Hey!'
		lowerCAmelCase					:    int      							= AgentText(snake_case__    )

		self.assertEqual(snake_case__ ,					agent_type.to_string()    )
		self.assertEqual(snake_case__ ,					agent_type.to_raw()    )
		self.assertEqual(snake_case__ ,					snake_case__    )




'''simple docstring'''




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


_lowerCAmelCase  :		str		     =	logging.get_logger(__name__)

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



class  lowerCAmelCase				(				a							):
	_lowerCamelCase   :					Union[str, Any]			      = """open-llama"""



	def __init__(					self ,					snake_case__=10_0000 ,					snake_case__=4096 ,					snake_case__=1_1008 ,					snake_case__=32 ,					snake_case__=32 ,					snake_case__="silu" ,					snake_case__=2048 ,					snake_case__=0.0_2 ,					snake_case__=1e-6 ,					snake_case__=True ,					snake_case__=0 ,					snake_case__=1 ,					snake_case__=2 ,					snake_case__=False ,					snake_case__=True ,					snake_case__=0.1 ,					snake_case__=0.1 ,					snake_case__=True ,					snake_case__=True ,					snake_case__=None ,					**snake_case__ ,					):
		lowerCAmelCase					:    Tuple      							= vocab_size
		lowerCAmelCase					:    Optional[Any]      							= max_position_embeddings
		lowerCAmelCase					:    List[Any]      							= hidden_size
		lowerCAmelCase					:    List[Any]      							= intermediate_size
		lowerCAmelCase					:    Tuple      							= num_hidden_layers
		lowerCAmelCase					:    List[Any]      							= num_attention_heads
		lowerCAmelCase					:    List[Any]      							= hidden_act
		lowerCAmelCase					:    Union[str, Any]      							= initializer_range
		lowerCAmelCase					:    str      							= rms_norm_eps
		lowerCAmelCase					:    Optional[int]      							= use_cache
		lowerCAmelCase					:    Dict      							= kwargs.pop(
		    'use_memorry_efficient_attention' ,					snake_case__    )
		lowerCAmelCase					:    Optional[int]      							= hidden_dropout_prob
		lowerCAmelCase					:    Optional[Any]      							= attention_dropout_prob
		lowerCAmelCase					:    Union[str, Any]      							= use_stable_embedding
		lowerCAmelCase					:    Tuple      							= shared_input_output_embedding
		lowerCAmelCase					:    Tuple      							= rope_scaling
		self._rope_scaling_validation()

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



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

		if not isinstance(self.rope_scaling ,					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}"    )
		lowerCAmelCase					:    List[Any]      							= self.rope_scaling.get('type' ,					snake_case__    )
		lowerCAmelCase					:    List[str]      							= self.rope_scaling.get('factor' ,					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(snake_case__ ,					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}"    )
