





'''simple docstring'''



from typing import List, Optional

import numpy as np

from ...processing_utils import ProcessorMixin
from ...utils import to_numpy






class 							__lowercase    ( lowerCAmelCase__  ):







	'''simple docstring'''

	a      :			Optional[int]     =    "EncodecFeatureExtractor"
	a      :			List[str]     =    ("T5Tokenizer", "T5TokenizerFast")


	def __init__(self       ,_lowerCamelCase       ,_lowerCamelCase	)							->							str:







				'''simple docstring'''





				super().__init__(_lowerCamelCase       ,_lowerCamelCase	)
				__lowercase			  =							self.feature_extractor
				__lowercase			  =							False


	def   _UpperCAmelCase       (self       ,_lowerCamelCase=None       ,_lowerCamelCase=None       ,_lowerCamelCase=True	)							->							List[Any]:







				'''simple docstring'''





				return self.tokenizer.get_decoder_prompt_ids(task=_lowerCamelCase       ,language=_lowerCamelCase       ,no_timestamps=_lowerCamelCase	)


	def __call__(self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Union[str, Any]:







				'''simple docstring'''





				if self._in_target_context_manager:
							return self.current_processor(*_lowerCamelCase       ,**_lowerCamelCase	)

				__lowercase			  =							kwargs.pop('''audio'''       ,_lowerCamelCase	)
				__lowercase			  =							kwargs.pop('''sampling_rate'''       ,_lowerCamelCase	)
				__lowercase			  =							kwargs.pop('''text'''       ,_lowerCamelCase	)
				if len(_lowerCamelCase	) > 0:
							__lowercase			  =							args[0]
							__lowercase			  =							args[1:]

				if audio is None and text is None:
							raise ValueError('''You need to specify either an `audio` or `text` input to process.'''	)

				if text is not None:
							__lowercase			  =							self.tokenizer(_lowerCamelCase       ,**_lowerCamelCase	)

				if audio is not None:
							__lowercase			  =							self.feature_extractor(_lowerCamelCase       ,*_lowerCamelCase       ,sampling_rate=_lowerCamelCase       ,**_lowerCamelCase	)

				if audio is None:
							return inputs

				elif text is None:
							return audio_inputs

				else:
							__lowercase			  =							audio_inputs['''input_values''']
							if "padding_mask" in audio_inputs:
										__lowercase			  =							audio_inputs['''padding_mask''']
							return inputs


	def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase			  =							kwargs.pop('''audio'''       ,_lowerCamelCase	)
				__lowercase			  =							kwargs.pop('''padding_mask'''       ,_lowerCamelCase	)

				if len(_lowerCamelCase	) > 0:
							__lowercase			  =							args[0]
							__lowercase			  =							args[1:]

				if audio_values is not None:
							return self._decode_audio(_lowerCamelCase       ,padding_mask=_lowerCamelCase	)
				else:
							return self.tokenizer.batch_decode(*_lowerCamelCase       ,**_lowerCamelCase	)


	def   _UpperCAmelCase       (self       ,*_lowerCamelCase       ,**_lowerCamelCase	)							->							Tuple:







				'''simple docstring'''





				return self.tokenizer.decode(*_lowerCamelCase       ,**_lowerCamelCase	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase = None	)							->							List[np.ndarray]:







				'''simple docstring'''





				__lowercase			  =							to_numpy(_lowerCamelCase	)
				__lowercase  ,						__lowercase  ,						__lowercase			  =							audio_values.shape

				if padding_mask is None:
							return list(_lowerCamelCase	)

				__lowercase			  =							to_numpy(_lowerCamelCase	)

				# match the sequence length of the padding mask to the generated audio arrays by padding with the **non-padding**
				# token (so that the generated audio values are **not** treated as padded tokens)
				__lowercase			  =							seq_len - padding_mask.shape[-1]
				__lowercase			  =							1 - self.feature_extractor.padding_value
				__lowercase			  =							np.pad(_lowerCamelCase       ,((0, 0), (0, difference))       ,'''constant'''       ,constant_values=_lowerCamelCase	)

				__lowercase			  =							audio_values.tolist()
				for i in range(_lowerCamelCase	):
							__lowercase			  =							np.asarray(audio_values[i]	)[
							    padding_mask[i][None, :] != self.feature_extractor.padding_value
							]
							__lowercase			  =							sliced_audio.reshape(_lowerCamelCase       ,-1	)

				return audio_values












'''simple docstring'''



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


_SCREAMING_SNAKE_CASE   =      logging.get_logger(__name__)

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






class 							__lowercase    ( lowerCAmelCase__  ):







	'''simple docstring'''

	a      :			Dict     =    "open-llama"


	def __init__(self       ,_lowerCamelCase=100000       ,_lowerCamelCase=4096       ,_lowerCamelCase=11008       ,_lowerCamelCase=32       ,_lowerCamelCase=32       ,_lowerCamelCase="silu"       ,_lowerCamelCase=2048       ,_lowerCamelCase=0.0_2       ,_lowerCamelCase=1E-6       ,_lowerCamelCase=True       ,_lowerCamelCase=0       ,_lowerCamelCase=1       ,_lowerCamelCase=2       ,_lowerCamelCase=False       ,_lowerCamelCase=True       ,_lowerCamelCase=0.1       ,_lowerCamelCase=0.1       ,_lowerCamelCase=True       ,_lowerCamelCase=True       ,_lowerCamelCase=None       ,**_lowerCamelCase       ,)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase			  =							vocab_size
				__lowercase			  =							max_position_embeddings
				__lowercase			  =							hidden_size
				__lowercase			  =							intermediate_size
				__lowercase			  =							num_hidden_layers
				__lowercase			  =							num_attention_heads
				__lowercase			  =							hidden_act
				__lowercase			  =							initializer_range
				__lowercase			  =							rms_norm_eps
				__lowercase			  =							use_cache
				__lowercase			  =							kwargs.pop(
				    '''use_memorry_efficient_attention'''       ,_lowerCamelCase	)
				__lowercase			  =							hidden_dropout_prob
				__lowercase			  =							attention_dropout_prob
				__lowercase			  =							use_stable_embedding
				__lowercase			  =							shared_input_output_embedding
				__lowercase			  =							rope_scaling
				self._rope_scaling_validation()

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


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







				'''simple docstring'''





				if self.rope_scaling is None:
							return

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





