




"""simple docstring"""

from typing import List, Optional, Union

import numpy as np
import tensorflow as tf

from .utils import logging


__A       						=	logging.get_logger(__name__)



def      UpperCamelCase__   (						lowercase__     :   Dict      ):
		if isinstance(lowercase__				,   np.ndarray      ):
				return list(tensor.shape      )

		snake_case						:  List[str]    	= tf.shape(lowercase__      )

		if tensor.shape == tf.TensorShape(lowercase__      ):
				return dynamic

		snake_case						:  List[Any]    	= tensor.shape.as_list()

		return [dynamic[i] if s is None else s for i, s in enumerate(lowercase__      )]



def      UpperCamelCase__   (						lowercase__     :   Optional[Any]				,   lowercase__     :   Optional[int] = None				,   lowercase__     :   Union[str, Any] = None      ):
		return tf.nn.softmax(logits=logits + 1E-9				,   axis=lowercase__				,   name=lowercase__      )



def      UpperCamelCase__   (						lowercase__     :   List[str]				,   lowercase__     :   Optional[int]				,   lowercase__     :   Optional[int]				,   lowercase__     :   Union[str, Any]=1E-5				,   lowercase__     :   int=-1      ):
		# This is a very simplified functional layernorm, designed to duplicate
		# the functionality of PyTorch nn.functional.layer_norm when this is needed to port
		# models in Transformers.

		if weight.shape.rank != 1 or bias.shape.rank != 1 or not isinstance(lowercase__				,   lowercase__      ):
				raise NotImplementedError("Only 1D weight and bias tensors are supported for now, with only a single axis."      )

		# Get mean and variance on the axis to be normalized
		snake_case						:  Union[str, Any]    	= tf.nn.moments(lowercase__				,   axes=[axis]				,   keepdims=lowercase__      )

		if axis != -1:
				# Reshape scale and weight to have the same rank as inputs, but with 1 dimensions
				# on every dimension except axis
				snake_case						:  str    	= [1] * inputs.shape.rank
				snake_case						:  Optional[Any]    	= shape_list(lowercase__      )[axis]
				snake_case						:  Tuple    	= tf.reshape(lowercase__				,   lowercase__      )
				snake_case						:  int    	= tf.reshape(lowercase__				,   lowercase__      )

		# Compute layer normalization using the batch_normalization
		# function.
		snake_case						:  int    	= tf.nn.batch_normalization(
		    lowercase__				,   lowercase__				,   lowercase__				,   offset=lowercase__				,   scale=lowercase__				,   variance_epsilon=lowercase__				,   )
		return outputs



def      UpperCamelCase__   (						lowercase__     :   Tuple				,   lowercase__     :   List[Any]=0				,   lowercase__     :   Optional[Any]=-1      ):
		# Replicates the behavior of torch.flatten in TF

		# If end_dim or start_dim is negative, count them from the end
		if end_dim < 0:
				end_dim += input.shape.rank
		if start_dim < 0:
				start_dim += input.shape.rank

		if start_dim == end_dim:
				return input

		snake_case						:  Optional[int]    	= tf.shape(lowercase__      )
		snake_case						:  Tuple    	= tf.math.reduce_prod(in_shape[start_dim : end_dim + 1]      )
		snake_case						:  Union[str, Any]    	= tf.concat([in_shape[:start_dim], [flattened_dim], in_shape[end_dim + 1 :]]				,   axis=0      )
		return tf.reshape(lowercase__				,   lowercase__      )



def      UpperCamelCase__   (						lowercase__     :   Union[str, Any]      ):
		if not isinstance(lowercase__				,   tf.Tensor      ):
				snake_case						:  List[str]    	= tf.convert_to_tensor(lowercase__      )  # Catches stray NumPy inputs
		if encoder_attention_mask.shape.rank == 3:
				snake_case						:  List[str]    	= encoder_attention_mask[:, None, :, :]
		if encoder_attention_mask.shape.rank == 2:
				snake_case						:  Optional[int]    	= encoder_attention_mask[:, None, None, :]
		# T5 has a mask that can compare sequence ids, we can simulate this here with this transposition
		# Cf. https://github.com/tensorflow/mesh/blob/8d2465e9bc93129b913b5ccc6a59aa97abd96ec6/mesh_tensorflow
		# /transformer/transformer_layers.py#L270
		# encoder_extended_attention_mask = (encoder_extended_attention_mask ==
		# encoder_extended_attention_mask.transpose(-1, -2))
		snake_case						:  Union[str, Any]    	= (
		    tf.cast(1				,   encoder_attention_mask.dtype      ) - encoder_extended_attention_mask
		) * encoder_extended_attention_mask.dtype.min

		return encoder_extended_attention_mask



def      UpperCamelCase__   (						lowercase__     :   List[Any]				,   lowercase__     :   List[str]				,   lowercase__     :   List[str] = "input_ids"      ):
		tf.debugging.assert_less(
		    lowercase__				,   tf.cast(lowercase__				,   dtype=tensor.dtype      )				,   message=(
		        F'''The maximum value of {tensor_name} ({tf.math.reduce_max(lowercase__      )}) must be smaller than the embedding '''
		        F'''layer\'s input dimension ({embed_dim}). The likely cause is some problem at tokenization time.'''
		    )				,   )



def      UpperCamelCase__   (						lowercase__     :   Union[str, Any]				,   lowercase__     :   Any				,   lowercase__     :   Tuple      ):
		snake_case						:  Any    	= 6_4512
		# Check that no item in `data` is larger than `HDF5_OBJECT_HEADER_LIMIT`
		# because in that case even chunking the array would not make the saving
		# possible.
		snake_case						:  Any    	= [x for x in data if len(lowercase__      ) > HDF5_OBJECT_HEADER_LIMIT]

		# Expecting this to never be true.
		if bad_attributes:
				raise RuntimeError(
				    "The following attributes cannot be saved to HDF5 file because "
				    F'''they are larger than {HDF5_OBJECT_HEADER_LIMIT} '''
				    F'''bytes: {bad_attributes}'''      )

		snake_case						:  List[Any]    	= np.asarray(lowercase__      )

		snake_case						:  int    	= 1
		snake_case						:  Any    	= np.array_split(lowercase__				,   lowercase__      )

		# This will never loop forever thanks to the test above.
		while any(x.nbytes > HDF5_OBJECT_HEADER_LIMIT for x in chunked_data      ):
				num_chunks += 1
				snake_case						:  Tuple    	= np.array_split(lowercase__				,   lowercase__      )

		if num_chunks > 1:
				for chunk_id, chunk_data in enumerate(lowercase__      ):
						snake_case						:  int    	= chunk_data
		else:
				snake_case						:  List[Any]    	= data



def      UpperCamelCase__   (						lowercase__     :   List[str]				,   lowercase__     :   Optional[Any]      ):
		if name in group.attrs:
				snake_case						:  str    	= [n.decode("utf8"      ) if hasattr(lowercase__				,   "decode"      ) else n for n in group.attrs[name]]
		else:
				snake_case						:  List[str]    	= []
				snake_case						:  Union[str, Any]    	= 0
				while "%s%d" % (name, chunk_id) in group.attrs:
						data.extend(
						    [n.decode("utf8"      ) if hasattr(lowercase__				,   "decode"      ) else n for n in group.attrs["%s%d" % (name, chunk_id)]]      )
						chunk_id += 1
		return data



def      UpperCamelCase__   (						lowercase__     :   str      ):

		def _expand_single_ad_tensor(lowercase__     :   Optional[Any]      ):
				if isinstance(lowercase__				,   tf.Tensor      ) and t.shape.rank == 1:
						return tf.expand_dims(lowercase__				,   axis=-1      )
				return t

		return tf.nest.map_structure(_expand_single_ad_tensor				,   lowercase__      )





import unittest

import numpy as np

from transformers import is_flax_available
from transformers.testing_utils import require_flax

from ..test_modeling_flax_common import ids_tensor


if is_flax_available():
     import jax
     import jax.numpy as jnp

     from transformers.generation import (
         FlaxForcedBOSTokenLogitsProcessor,
         FlaxForcedEOSTokenLogitsProcessor,
         FlaxLogitsProcessorList,
         FlaxMinLengthLogitsProcessor,
         FlaxTemperatureLogitsWarper,
         FlaxTopKLogitsWarper,
         FlaxTopPLogitsWarper,
     )






@require_flax
class   _lowerCamelCase (					unittest.TestCase			):




       """simple docstring"""



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)->List[Any]:




         '''simple docstring'''





         A_      :				Optional[int]		     =					jnp.ones((batch_size, length)		) / length
         return scores



       def        _snake_case       (      self		)->Tuple:




         '''simple docstring'''





         A_      :				Union[str, Any]		     =					None
         A_      :				Any		     =					20

         A_      :				Any		     =					self._get_uniform_logits(batch_size=2				,       length=_SCREAMING_SNAKE_CASE		)

         # tweak scores to not be uniform anymore
         A_      :				Dict		     =					scores.at[1, 5].set((1 / length) + 0.1		)  # peak, 1st batch
         A_      :				Tuple		     =					scores.at[1, 10].set((1 / length) - 0.4		)  # valley, 1st batch

         # compute softmax
         A_      :				List[str]		     =					jax.nn.softmax(_SCREAMING_SNAKE_CASE				,       axis=-1		)

         A_      :				Any		     =					FlaxTemperatureLogitsWarper(temperature=0.5		)
         A_      :				Optional[int]		     =					FlaxTemperatureLogitsWarper(temperature=1.3		)

         A_      :				Optional[Any]		     =					jax.nn.softmax(temp_dist_warper_sharper(_SCREAMING_SNAKE_CASE				,       scores.copy()				,       cur_len=_SCREAMING_SNAKE_CASE		)				,       axis=-1		)
         A_      :				List[Any]		     =					jax.nn.softmax(temp_dist_warper_smoother(_SCREAMING_SNAKE_CASE				,       scores.copy()				,       cur_len=_SCREAMING_SNAKE_CASE		)				,       axis=-1		)

         # uniform distribution stays uniform
         self.assertTrue(jnp.allclose(probs[0, :]				,       warped_prob_sharp[0, :]				,       atol=1e-3		)		)
         self.assertTrue(jnp.allclose(probs[0, :]				,       warped_prob_smooth[0, :]				,       atol=1e-3		)		)

         # sharp peaks get higher, valleys get lower
         self.assertLess(probs[1, :].max()				,       warped_prob_sharp[1, :].max()		)
         self.assertGreater(probs[1, :].min()				,       warped_prob_sharp[1, :].min()		)

         # smooth peaks get lower, valleys get higher
         self.assertGreater(probs[1, :].max()				,       warped_prob_smooth[1, :].max()		)
         self.assertLess(probs[1, :].min()				,       warped_prob_smooth[1, :].min()		)



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




         '''simple docstring'''





         A_      :				Any		     =					None
         A_      :				List[Any]		     =					10
         A_      :				str		     =					2

         # create ramp distribution
         A_      :				Any		     =					np.broadcast_to(np.arange(_SCREAMING_SNAKE_CASE		)[None, :]				,       (batch_size, vocab_size)		).copy()
         A_      :				List[Any]		     =					ramp_logits[1:, : vocab_size // 2] + vocab_size

         A_      :				Any		     =					FlaxTopKLogitsWarper(3		)

         A_      :				Tuple		     =					top_k_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)

         # check that correct tokens are filtered
         self.assertListEqual(jnp.isinf(scores[0]		).tolist()				,       7 * [True] + 3 * [False]		)
         self.assertListEqual(jnp.isinf(scores[1]		).tolist()				,       2 * [True] + 3 * [False] + 5 * [True]		)

         # check special case
         A_      :				Optional[int]		     =					5
         A_      :				List[Any]		     =					FlaxTopKLogitsWarper(top_k=1				,       filter_value=0.0				,       min_tokens_to_keep=3		)

         A_      :				Optional[Any]		     =					np.broadcast_to(np.arange(_SCREAMING_SNAKE_CASE		)[None, :]				,       (batch_size, length)		).copy()
         A_      :				Dict		     =					top_k_warp_safety_check(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)

         # min_tokens overwrites k: 3 tokens are kept => 2 tokens are nullified
         self.assertListEqual((scores == 0.0).sum(axis=-1		).tolist()				,       [2, 2]		)



       def        _snake_case       (      self		)->Any:




         '''simple docstring'''





         A_      :				str		     =					None
         A_      :				Optional[Any]		     =					10
         A_      :				Any		     =					2

         # create distribution and take log (inverse to Softmax as taken in TopPLogitsWarper)
         A_      :				Optional[int]		     =					np.log(np.array([[0.3, 0.1, 0.1, 0.5], [0.1_5, 0.3, 0.3, 0.2_5]]		)		)

         A_      :				str		     =					FlaxTopPLogitsWarper(0.8		)
         A_      :				Optional[int]		     =					np.exp(top_p_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)		)

         # dist should be filtered to keep min num values so that sum is >= top_p
         # exp (-inf) => 0
         A_      :				Tuple		     =					np.array([[0.3, 0.0, 0.0, 0.5], [0.0, 0.3, 0.3, 0.2_5]]		)
         self.assertTrue(np.allclose(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       atol=1e-3		)		)

         # check edge cases with negative and extreme logits
         A_      :				Union[str, Any]		     =					np.broadcast_to(np.arange(_SCREAMING_SNAKE_CASE		)[None, :]				,       (batch_size, vocab_size)		).copy() - (
             vocab_size // 2
         )

         # make ramp_logits more extreme
         A_      :				str		     =					ramp_logits[1] * 1_0_0.0

         # make sure at least 2 tokens are kept
         A_      :				str		     =					FlaxTopPLogitsWarper(0.9				,       min_tokens_to_keep=2				,       filter_value=0.0		)
         A_      :				str		     =					top_p_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)

         # first batch should keep three tokens, second batch would keep only 1, but due to `min_tokens_to_keep=2` keeps 2.
         self.assertListEqual((filtered_dist != 0.0).sum(axis=-1		).tolist()				,       [3, 2]		)



       def        _snake_case       (      self		)->Any:




         '''simple docstring'''





         A_      :				str		     =					20
         A_      :				Union[str, Any]		     =					4
         A_      :				Optional[Any]		     =					0

         A_      :				Union[str, Any]		     =					FlaxMinLengthLogitsProcessor(min_length=10				,       eos_token_id=_SCREAMING_SNAKE_CASE		)

         # check that min length is applied at length 5
         A_      :				int		     =					ids_tensor((batch_size, 20)				,       vocab_size=20		)
         A_      :				List[Any]		     =					5
         A_      :				Optional[int]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					min_dist_processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         self.assertListEqual(scores_before_min_length[:, eos_token_id].tolist()				,       4 * [-float('''inf'''		)]		)

         # check that min length is not applied anymore at length 15
         A_      :				Tuple		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Any		     =					15
         A_      :				int		     =					min_dist_processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         self.assertFalse(jnp.isinf(_SCREAMING_SNAKE_CASE		).any()		)



       def        _snake_case       (      self		)->Optional[Any]:




         '''simple docstring'''





         A_      :				Optional[int]		     =					20
         A_      :				Optional[int]		     =					4
         A_      :				Optional[int]		     =					0

         A_      :				Optional[Any]		     =					FlaxForcedBOSTokenLogitsProcessor(bos_token_id=_SCREAMING_SNAKE_CASE		)

         # check that all scores are -inf except the bos_token_id score
         A_      :				Optional[Any]		     =					ids_tensor((batch_size, 1)				,       vocab_size=20		)
         A_      :				str		     =					1
         A_      :				List[str]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				List[str]		     =					logits_processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         self.assertTrue(jnp.isneginf(scores[:, bos_token_id + 1 :]		).all()		)
         self.assertListEqual(scores[:, bos_token_id].tolist()				,       4 * [0]		)  # score for bos_token_id shold be zero

         # check that bos_token_id is not forced if current length is greater than 1
         A_      :				Optional[int]		     =					3
         A_      :				List[Any]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Tuple		     =					logits_processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         self.assertFalse(jnp.isinf(_SCREAMING_SNAKE_CASE		).any()		)



       def        _snake_case       (      self		)->List[str]:




         '''simple docstring'''





         A_      :				Union[str, Any]		     =					20
         A_      :				str		     =					4
         A_      :				Dict		     =					0
         A_      :				Optional[int]		     =					5

         A_      :				Tuple		     =					FlaxForcedEOSTokenLogitsProcessor(max_length=_SCREAMING_SNAKE_CASE				,       eos_token_id=_SCREAMING_SNAKE_CASE		)

         # check that all scores are -inf except the eos_token_id when max_length is reached
         A_      :				List[Any]		     =					ids_tensor((batch_size, 4)				,       vocab_size=20		)
         A_      :				Any		     =					4
         A_      :				Optional[Any]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				List[Any]		     =					logits_processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         self.assertTrue(jnp.isneginf(scores[:, eos_token_id + 1 :]		).all()		)
         self.assertListEqual(scores[:, eos_token_id].tolist()				,       4 * [0]		)  # score for eos_token_id should be zero

         # check that eos_token_id is not forced if max_length is not reached
         A_      :				int		     =					3
         A_      :				Union[str, Any]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Dict		     =					logits_processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         self.assertFalse(jnp.isinf(_SCREAMING_SNAKE_CASE		).any()		)



       def        _snake_case       (      self		)->str:




         '''simple docstring'''





         A_      :				str		     =					4
         A_      :				Dict		     =					10
         A_      :				Union[str, Any]		     =					15
         A_      :				str		     =					2
         A_      :				int		     =					1
         A_      :				List[str]		     =					15

         # dummy input_ids and scores
         A_      :				Tuple		     =					ids_tensor((batch_size, sequence_length)				,       _SCREAMING_SNAKE_CASE		)
         A_      :				int		     =					input_ids.copy()

         A_      :				List[Any]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					scores.copy()

         # instantiate all dist processors
         A_      :				Dict		     =					FlaxTemperatureLogitsWarper(temperature=0.5		)
         A_      :				Any		     =					FlaxTopKLogitsWarper(3		)
         A_      :				List[Any]		     =					FlaxTopPLogitsWarper(0.8		)

         # instantiate all logits processors
         A_      :				List[Any]		     =					FlaxMinLengthLogitsProcessor(min_length=10				,       eos_token_id=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					FlaxForcedBOSTokenLogitsProcessor(bos_token_id=_SCREAMING_SNAKE_CASE		)
         A_      :				Dict		     =					FlaxForcedEOSTokenLogitsProcessor(max_length=_SCREAMING_SNAKE_CASE				,       eos_token_id=_SCREAMING_SNAKE_CASE		)

         A_      :				Union[str, Any]		     =					10

         # no processor list
         A_      :				int		     =					temp_dist_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         A_      :				List[str]		     =					top_k_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         A_      :				Any		     =					top_p_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         A_      :				Dict		     =					min_dist_proc(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					bos_dist_proc(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[Any]		     =					eos_dist_proc(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)

         # with processor list
         A_      :				Any		     =					FlaxLogitsProcessorList(
             [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc]		)
         A_      :				List[str]		     =					processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)

         # scores should be equal
         self.assertTrue(jnp.allclose(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       atol=1e-3		)		)

         # input_ids should never be changed
         self.assertListEqual(input_ids.tolist()				,       input_ids_comp.tolist()		)







       def        _snake_case       (      self		)->Dict:




         '''simple docstring'''





         A_      :				str		     =					4
         A_      :				Dict		     =					10
         A_      :				Tuple		     =					15
         A_      :				List[str]		     =					2
         A_      :				List[str]		     =					1
         A_      :				Union[str, Any]		     =					15

         # dummy input_ids and scores
         A_      :				Any		     =					ids_tensor((batch_size, sequence_length)				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					input_ids.copy()

         A_      :				Optional[Any]		     =					self._get_uniform_logits(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				Tuple		     =					scores.copy()

         # instantiate all dist processors
         A_      :				List[str]		     =					FlaxTemperatureLogitsWarper(temperature=0.5		)
         A_      :				Optional[Any]		     =					FlaxTopKLogitsWarper(3		)
         A_      :				int		     =					FlaxTopPLogitsWarper(0.8		)

         # instantiate all logits processors
         A_      :				List[Any]		     =					FlaxMinLengthLogitsProcessor(min_length=10				,       eos_token_id=_SCREAMING_SNAKE_CASE		)
         A_      :				Dict		     =					FlaxForcedBOSTokenLogitsProcessor(bos_token_id=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[Any]		     =					FlaxForcedEOSTokenLogitsProcessor(max_length=_SCREAMING_SNAKE_CASE				,       eos_token_id=_SCREAMING_SNAKE_CASE		)

         A_      :				str		     =					10

         # no processor list
         def run_no_processor_list(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		):
           A_      :				int		     =					temp_dist_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           A_      :				Optional[Any]		     =					top_k_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           A_      :				List[Any]		     =					top_p_warp(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           A_      :				Dict		     =					min_dist_proc(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           A_      :				Any		     =					bos_dist_proc(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           A_      :				Optional[Any]		     =					eos_dist_proc(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           return scores

         # with processor list
         def run_processor_list(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		):
           A_      :				Optional[int]		     =					FlaxLogitsProcessorList(
               [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc]		)
           A_      :				Optional[int]		     =					processor(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       cur_len=_SCREAMING_SNAKE_CASE		)
           return scores

         A_      :				Optional[int]		     =					jax.jit(_SCREAMING_SNAKE_CASE		)
         A_      :				Union[str, Any]		     =					jax.jit(_SCREAMING_SNAKE_CASE		)

         A_      :				Dict		     =					jitted_run_no_processor_list(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)
         A_      :				List[Any]		     =					jitted_run_processor_list(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE		)

         # scores should be equal
         self.assertTrue(jnp.allclose(_SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       atol=1e-3		)		)

         # input_ids should never be changed
         self.assertListEqual(input_ids.tolist()				,       input_ids_comp.tolist()		)




