



"""simple docstring"""






import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


_lowercase				:				int   		=		get_logger(__name__)


_lowercase				:				List[Any]   		=		r'''
    Args:
        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam
            search or log softmax for each vocabulary token when using beam search
        kwargs (`Dict[str, Any]`, *optional*):
            Additional logits processor specific kwargs.

    Return:
        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.

'''

class  __SCREAMING_SNAKE_CASE			:


					'''simple docstring'''





					@add_start_docstrings(_A  )
					def __call__( self							:						Union[str, Any],						lowerCamelCase							:						Union[str, Any],						lowerCamelCase							:						int  )->      List[str]:
								raise NotImplementedError(
								    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''  )





class  __SCREAMING_SNAKE_CASE			:


					'''simple docstring'''





					@add_start_docstrings(_A  )
					def __call__( self							:						str,						lowerCamelCase							:						Optional[int],						lowerCamelCase							:						Tuple  )->      Union[str, Any]:
								raise NotImplementedError(
								    F'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''  )





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					@add_start_docstrings(_A  )
					def __call__( self							:						str,						lowerCamelCase							:						int,						lowerCamelCase							:						Any,						lowerCamelCase							:						str,						**lowerCamelCase							:						Optional[Any]  )->      Tuple:
								for processor in self:
											lowerCamelCase__	:	str				=inspect.signature(processor.__call__  ).parameters
											if len(_A  ) > 3:
														if not all(arg in kwargs for arg in list(function_args.keys()  )[2:]  ):
																	raise ValueError(
																	    F'''Make sure that all the required parameters: {list(function_args.keys()  )} for '''
																	    F'''{processor.__class__} are passed to the logits processor.'''  )
														lowerCamelCase__	:	Any				=processor(_A,						_A,						_A,						**_A  )
											else:
														lowerCamelCase__	:	Union[str, Any]				=processor(_A,						_A,						_A  )
								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						str,						lowerCamelCase							:						int  )->      Optional[Any]:
								if not isinstance(_A,						_A  ) or not (temperature > 0):
											raise ValueError(F'''`temperature` has to be a strictly positive float, but is {temperature}'''  )

								lowerCamelCase__	:	Optional[int]				=temperature




					def __call__( self							:						Optional[Any],						lowerCamelCase							:						List[str],						lowerCamelCase							:						Optional[int],						lowerCamelCase							:						Dict  )->      Optional[int]:
								lowerCamelCase__	:	Dict				=scores / self.temperature
								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						List[Any],						lowerCamelCase							:						Optional[int],						lowerCamelCase							:						Union[str, Any] = -float('''Inf'''  ),						lowerCamelCase							:						Union[str, Any] = 1  )->      Any:
								if not isinstance(_A,						_A  ) or (top_p < 0 or top_p > 1.0):
											raise ValueError(F'''`top_p` has to be a float > 0 and < 1, but is {top_p}'''  )
								if not isinstance(_A,						_A  ) or (min_tokens_to_keep < 1):
											raise ValueError(F'''`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}'''  )

								lowerCamelCase__	:	Optional[Any]				=top_p
								lowerCamelCase__	:	Optional[Any]				=filter_value
								lowerCamelCase__	:	List[str]				=min_tokens_to_keep




					def __call__( self							:						Union[str, Any],						lowerCamelCase							:						Optional[int],						lowerCamelCase							:						Union[str, Any],						lowerCamelCase							:						Dict  )->      Optional[Any]:
								lowerCamelCase__	:	Union[str, Any]				=lax.top_k(_A,						scores.shape[-1]  )

								lowerCamelCase__	:	Union[str, Any]				=jnp.full_like(_A,						self.filter_value  )
								lowerCamelCase__	:	int				=jax.nn.softmax(_A,						axis=-1  ).cumsum(axis=-1  )
								lowerCamelCase__	:	Union[str, Any]				=cumulative_probs < self.top_p

								# include the token that is higher than top_p as well
								lowerCamelCase__	:	List[Any]				=jnp.roll(_A,						1  )
								score_mask |= score_mask.at[:, 0].set(_A  )

								# min tokens to keep
								lowerCamelCase__	:	int				=score_mask.at[:, : self.min_tokens_to_keep].set(_A  )

								lowerCamelCase__	:	Tuple				=jnp.where(_A,						_A,						_A  )
								lowerCamelCase__	:	List[str]				=jax.lax.sort_key_val(_A,						_A  )[-1]

								return next_scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						int,						lowerCamelCase							:						Union[str, Any],						lowerCamelCase							:						int = -float('''Inf'''  ),						lowerCamelCase							:						Optional[int] = 1  )->      Optional[int]:
								if not isinstance(_A,						_A  ) or top_k <= 0:
											raise ValueError(F'''`top_k` has to be a strictly positive integer, but is {top_k}'''  )

								lowerCamelCase__	:	Dict				=max(_A,						_A  )
								lowerCamelCase__	:	Tuple				=filter_value




					def __call__( self							:						List[str],						lowerCamelCase							:						Tuple,						lowerCamelCase							:						Dict,						lowerCamelCase							:						List[str]  )->      str:
								lowerCamelCase__	:	Tuple				=scores.shape
								lowerCamelCase__	:	List[Any]				=jnp.full(batch_size * vocab_size,						self.filter_value  )

								lowerCamelCase__	:	Optional[int]				=min(self.top_k,						scores.shape[-1]  )  # Safety check
								lowerCamelCase__	:	Dict				=lax.top_k(_A,						_A  )
								lowerCamelCase__	:	Optional[Any]				=jnp.broadcast_to((jnp.arange(_A  ) * vocab_size)[:, None],						(batch_size, topk)  ).flatten()
								lowerCamelCase__	:	Union[str, Any]				=topk_scores.flatten()
								lowerCamelCase__	:	List[Any]				=topk_indices.flatten() + shift

								lowerCamelCase__	:	Dict				=next_scores_flat.at[topk_indices_flat].set(_A  )
								lowerCamelCase__	:	Optional[Any]				=next_scores_flat.reshape(_A,						_A  )
								return next_scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						List[str],						lowerCamelCase							:						Union[str, Any]  )->      Union[str, Any]:
								lowerCamelCase__	:	Optional[int]				=bos_token_id




					def __call__( self							:						Dict,						lowerCamelCase							:						Optional[int],						lowerCamelCase							:						Tuple,						lowerCamelCase							:						Optional[int]  )->      Optional[int]:
								lowerCamelCase__	:	Optional[Any]				=jnp.full(scores.shape,						-float('''inf'''  )  )

								lowerCamelCase__	:	List[Any]				=1 - jnp.bool_(cur_len - 1  )

								lowerCamelCase__	:	Union[str, Any]				=jnp.where(_A,						new_scores.at[:, self.bos_token_id].set(0  ),						_A  )

								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						Dict,						lowerCamelCase							:						Optional[int],						lowerCamelCase							:						int  )->      Dict:
								lowerCamelCase__	:	Union[str, Any]				=max_length
								lowerCamelCase__	:	Union[str, Any]				=eos_token_id




					def __call__( self							:						Optional[int],						lowerCamelCase							:						int,						lowerCamelCase							:						Optional[Any],						lowerCamelCase							:						Optional[Any]  )->      Optional[int]:
								lowerCamelCase__	:	Optional[int]				=jnp.full(scores.shape,						-float('''inf'''  )  )

								lowerCamelCase__	:	str				=1 - jnp.bool_(cur_len - self.max_length + 1  )

								lowerCamelCase__	:	Optional[Any]				=jnp.where(_A,						new_scores.at[:, self.eos_token_id].set(0  ),						_A  )

								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						Optional[Any],						lowerCamelCase							:						List[Any],						lowerCamelCase							:						Dict  )->      Optional[Any]:
								if not isinstance(_A,						_A  ) or min_length < 0:
											raise ValueError(F'''`min_length` has to be a positive integer, but is {min_length}'''  )

								if not isinstance(_A,						_A  ) or eos_token_id < 0:
											raise ValueError(F'''`eos_token_id` has to be a positive integer, but is {eos_token_id}'''  )

								lowerCamelCase__	:	Tuple				=min_length
								lowerCamelCase__	:	List[Any]				=eos_token_id




					def __call__( self							:						Dict,						lowerCamelCase							:						Optional[Any],						lowerCamelCase							:						Any,						lowerCamelCase							:						int  )->      Tuple:
								# create boolean flag to decide if min length penalty should be applied
								lowerCamelCase__	:	Optional[Any]				=1 - jnp.clip(cur_len - self.min_length,						0,						1  )

								lowerCamelCase__	:	Union[str, Any]				=jnp.where(_A,						scores.at[:, self.eos_token_id].set(-float('''inf'''  )  ),						_A  )

								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						List[str],						lowerCamelCase							:						Dict,						lowerCamelCase							:						Optional[Any]  )->      List[Any]:
								lowerCamelCase__	:	List[str]				=list(_A  )
								lowerCamelCase__	:	List[Any]				=begin_index




					def __call__( self							:						Dict,						lowerCamelCase							:						Optional[Any],						lowerCamelCase							:						str,						lowerCamelCase							:						Tuple  )->      List[Any]:
								lowerCamelCase__	:	Optional[Any]				=1 - jnp.bool_(cur_len - self.begin_index  )

								lowerCamelCase__	:	Tuple				=jnp.where(_A,						scores.at[:, self.begin_suppress_tokens].set(-float('''inf'''  )  ),						_A  )

								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						str,						lowerCamelCase							:						Optional[int]  )->      Tuple:
								lowerCamelCase__	:	List[str]				=list(_A  )




					def __call__( self							:						Tuple,						lowerCamelCase							:						Any,						lowerCamelCase							:						Optional[Any],						lowerCamelCase							:						Optional[Any]  )->      Optional[int]:
								lowerCamelCase__	:	Tuple				=scores.at[..., self.suppress_tokens].set(-float('''inf'''  )  )

								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						str,						lowerCamelCase							:						Union[str, Any]  )->      int:
								lowerCamelCase__	:	Dict				=dict(_A  )
								# Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
								# index of the array corresponds to the index of the token to be forced, for XLA compatibility.
								# Indexes without forced tokens will have a negative value.
								lowerCamelCase__	:	Optional[Any]				=jnp.ones((max(force_token_map.keys()  ) + 1),						dtype=jnp.intaa  ) * -1
								for index, token in force_token_map.items():
											if token is not None:
														lowerCamelCase__	:	Tuple				=force_token_array.at[index].set(_A  )
								lowerCamelCase__	:	Union[str, Any]				=jnp.intaa(_A  )




					def __call__( self							:						int,						lowerCamelCase							:						Union[str, Any],						lowerCamelCase							:						int,						lowerCamelCase							:						List[str]  )->      Any:
								def _force_token(lowerCamelCase							:						List[str]  ):
											lowerCamelCase__	:	int				=scores.shape[0]
											lowerCamelCase__	:	int				=self.force_token_array[generation_idx]

											lowerCamelCase__	:	Tuple				=jnp.ones_like(_A,						dtype=scores.dtype  ) * -float('''inf'''  )
											lowerCamelCase__	:	Tuple				=jnp.zeros((batch_size, 1),						dtype=scores.dtype  )
											lowerCamelCase__	:	str				=lax.dynamic_update_slice(_A,						_A,						(0, current_token)  )
											return new_scores

								lowerCamelCase__	:	int				=lax.cond(
								    cur_len >= self.force_token_array.shape[0],						lambda: scores,						lambda: lax.cond(
								        self.force_token_array[cur_len] >= 0,						lambda: _force_token(_A  ),						lambda: scores,						),						)
								return scores





class  __SCREAMING_SNAKE_CASE			(   snake_case__     ):


					'''simple docstring'''





					def __init__( self							:						List[str],						lowerCamelCase							:						List[Any],						lowerCamelCase							:						List[str],						lowerCamelCase							:						Optional[int]  )->      int:
								lowerCamelCase__	:	str				=generate_config.eos_token_id
								lowerCamelCase__	:	Any				=generate_config.no_timestamps_token_id
								lowerCamelCase__	:	List[str]				=generate_config.no_timestamps_token_id + 1

								lowerCamelCase__	:	List[Any]				=decoder_input_length + 1

								if generate_config.is_multilingual:
											# room for language token and task token
											self.begin_index += 2
								if hasattr(_A,						'''max_initial_timestamp_index'''  ):
											lowerCamelCase__	:	List[Any]				=generate_config.max_initial_timestamp_index
								else:
											lowerCamelCase__	:	Tuple				=model_config.vocab_size
								if self.max_initial_timestamp_index is None:
											lowerCamelCase__	:	Tuple				=model_config.vocab_size




					def __call__( self							:						List[Any],						lowerCamelCase							:						List[Any],						lowerCamelCase							:						List[str],						lowerCamelCase							:						Dict  )->      Optional[Any]:
								# suppress <|notimestamps|> which is handled by without_timestamps
								lowerCamelCase__	:	Any				=scores.at[:, self.no_timestamps_token_id].set(-float('''inf'''  )  )

								def handle_pairs(lowerCamelCase							:						Dict,						lowerCamelCase							:						Tuple  ):
											lowerCamelCase__	:	Tuple				=jnp.where((cur_len - self.begin_index) >= 1,						_A,						_A  )
											lowerCamelCase__	:	str				=jnp.where(
											    input_ids_k[cur_len - 1] >= self.timestamp_begin,						True and last_was_timestamp,						_A,						)

											lowerCamelCase__	:	List[str]				=jnp.where((cur_len - self.begin_index) < 2,						_A,						_A  )
											lowerCamelCase__	:	int				=jnp.where(
											    input_ids_k[cur_len - 2] >= self.timestamp_begin,						_A,						_A,						)

											return jnp.where(
											    _A,						jnp.where(
											        penultimate_was_timestamp > 0,						scores_k.at[self.timestamp_begin :].set(-float('''inf'''  )  ),						scores_k.at[: self.eos_token_id].set(-float('''inf'''  )  ),						),						_A,						)

								lowerCamelCase__	:	Tuple				=jax.vmap(_A  )(_A,						_A  )

								lowerCamelCase__	:	List[Any]				=jnp.where(cur_len == self.begin_index,						_A,						_A  )
								lowerCamelCase__	:	str				=jnp.where(
								    self.max_initial_timestamp_index is not None,						True and apply_max_initial_timestamp,						_A,						)

								lowerCamelCase__	:	Any				=self.timestamp_begin + self.max_initial_timestamp_index

								lowerCamelCase__	:	Tuple				=jnp.where(
								    _A,						scores.at[:, last_allowed + 1 :].set(-float('''inf'''  )  ),						_A,						)

								# if sum of probability over timestamps is above any other token, sample timestamp
								lowerCamelCase__	:	Optional[int]				=jax.nn.log_softmax(_A,						axis=-1  )

								def handle_cumulative_probs(lowerCamelCase							:						List[Any],						lowerCamelCase							:						Optional[Any]  ):
											lowerCamelCase__	:	Any				=jax.nn.logsumexp(logprobs_k[self.timestamp_begin :],						axis=-1  )
											lowerCamelCase__	:	Optional[Any]				=jnp.max(logprobs_k[: self.timestamp_begin]  )
											return jnp.where(
											    timestamp_logprob > max_text_token_logprob,						scores_k.at[: self.timestamp_begin].set(-float('''inf'''  )  ),						_A,						)

								lowerCamelCase__	:	Union[str, Any]				=jax.vmap(_A  )(_A,						_A  )

								return scores









"""simple docstring"""






from ..utils import DummyObject, requires_backends

class  __SCREAMING_SNAKE_CASE			(   metaclass=lowerCAmelCase_     ):


					'''simple docstring'''





					_a         =							['onnx']



					def __init__( self							:						List[str],						*lowerCamelCase							:						Union[str, Any],						**lowerCamelCase							:						str  )->      Optional[int]:
								requires_backends(self,						['''onnx''']  )



					@classmethod
					def 	snake_case ( cls							:						List[str],						*lowerCamelCase							:						Any,						**lowerCamelCase							:						Union[str, Any]  )->      Optional[int]:
								requires_backends(cls,						['''onnx''']  )




					@classmethod
					def 	snake_case ( cls							:						Union[str, Any],						*lowerCamelCase							:						Tuple,						**lowerCamelCase							:						Tuple  )->      Optional[int]:
								requires_backends(cls,						['''onnx''']  )




