
"""simple docstring"""







import collections
import gzip
import os
import urllib

import numpy
from tensorflow.python.framework import dtypes, random_seed
from tensorflow.python.platform import gfile
from tensorflow.python.util.deprecation import deprecated

lowercase_         =       collections.namedtuple("_Datasets", ["train", "validation", "test"])

# CVDF mirror of http://yann.lecun.com/exdb/mnist/
lowercase_         =       "https://storage.googleapis.com/cvdf-datasets/mnist/"




def       A_      (       lowercase   )  ->				Union[str, Any]:


     """simple docstring"""







     UpperCAmelCase_    :     Optional[int]            =	numpy.dtype(numpy.uintaa   ).newbyteorder(""">"""   )
     return numpy.frombuffer(bytestream.read(4   )    ,			dtype=lowercase   )[0]




@deprecated(lowercase    ,			"""Please use tf.data to implement this functionality."""   )
def       A_      (       lowercase   )  ->				List[Any]:


     """simple docstring"""







     print("""Extracting"""    ,			f.name   )
     with gzip.GzipFile(fileobj=lowercase   ) as bytestream:
          UpperCAmelCase_    :     int            =	_readaa(lowercase   )
          if magic != 2051:
               raise ValueError(
                   """Invalid magic number %d in MNIST image file: %s""" % (magic, f.name)   )
          UpperCAmelCase_    :     Tuple            =	_readaa(lowercase   )
          UpperCAmelCase_    :     List[str]            =	_readaa(lowercase   )
          UpperCAmelCase_    :     Union[str, Any]            =	_readaa(lowercase   )
          UpperCAmelCase_    :     Any            =	bytestream.read(rows * cols * num_images   )
          UpperCAmelCase_    :     List[Any]            =	numpy.frombuffer(lowercase    ,			dtype=numpy.uinta   )
          UpperCAmelCase_    :     Dict            =	data.reshape(lowercase    ,			lowercase    ,			lowercase    ,			1   )
          return data




@deprecated(lowercase    ,			"""Please use tf.one_hot on tensors."""   )
def       A_      (       lowercase    ,			lowercase   )  ->				Any:


     """simple docstring"""







     UpperCAmelCase_    :     Union[str, Any]            =	labels_dense.shape[0]
     UpperCAmelCase_    :     str            =	numpy.arange(lowercase   ) * num_classes
     UpperCAmelCase_    :     int            =	numpy.zeros((num_labels, num_classes)   )
     UpperCAmelCase_    :     Tuple            =	1
     return labels_one_hot




@deprecated(lowercase    ,			"""Please use tf.data to implement this functionality."""   )
def       A_      (       lowercase    ,			lowercase=False    ,			lowercase=10   )  ->				Any:


     """simple docstring"""







     print("""Extracting"""    ,			f.name   )
     with gzip.GzipFile(fileobj=lowercase   ) as bytestream:
          UpperCAmelCase_    :     Dict            =	_readaa(lowercase   )
          if magic != 2049:
               raise ValueError(
                   """Invalid magic number %d in MNIST label file: %s""" % (magic, f.name)   )
          UpperCAmelCase_    :     List[str]            =	_readaa(lowercase   )
          UpperCAmelCase_    :     List[str]            =	bytestream.read(lowercase   )
          UpperCAmelCase_    :     Dict            =	numpy.frombuffer(lowercase    ,			dtype=numpy.uinta   )
          if one_hot:
               return _dense_to_one_hot(lowercase    ,			lowercase   )
          return labels



class 		UpperCAmelCase_						:
 """simple docstring"""




 @deprecated(
     a_  , """Please use alternatives such as official/mnist/_DataSet.py"""
     """ from tensorflow/models."""  , )
 def __init__(			self							:			Optional[Any]  , a_							:			int  , a_							:			Tuple  , a_							:			int=False  , a_							:			str=False  , a_							:			List[str]=dtypes.floataa  , a_							:			Optional[Any]=True  , a_							:			Optional[Any]=None  , )->       Union[str, Any]:



      """simple docstring"""

      UpperCAmelCase_       ,UpperCAmelCase_    :     Optional[int]            =	random_seed.get_seed(a_			)
      # If op level seed is not set, use whatever graph level seed is returned
      numpy.random.seed(seeda if seed is None else seeda			)
      UpperCAmelCase_    :     int            =	dtypes.as_dtype(a_			).base_dtype
      if dtype not in (dtypes.uinta, dtypes.floataa):
           raise TypeError("""Invalid image dtype %r, expected uint8 or float32""" % dtype			)
      if fake_data:
           UpperCAmelCase_    :     str            =	1_00_00
           UpperCAmelCase_    :     Tuple            =	one_hot
      else:
           assert (
               images.shape[0] == labels.shape[0]
           ), f'''images.shape: {images.shape} labels.shape: {labels.shape}'''
           UpperCAmelCase_    :     Union[str, Any]            =	images.shape[0]

           # Convert shape from [num examples, rows, columns, depth]
           # to [num examples, rows*columns] (assuming depth == 1)
           if reshape:
                assert images.shape[3] == 1
                UpperCAmelCase_    :     int            =	images.reshape(
                    images.shape[0]  , images.shape[1] * images.shape[2]			)
           if dtype == dtypes.floataa:
                # Convert from [0, 255] -> [0.0, 1.0].
                UpperCAmelCase_    :     Optional[int]            =	images.astype(numpy.floataa			)
                UpperCAmelCase_    :     Any            =	numpy.multiply(a_  , 1.0 / 255.0			)
      UpperCAmelCase_    :     List[str]            =	images
      UpperCAmelCase_    :     Dict            =	labels
      UpperCAmelCase_    :     List[str]            =	0
      UpperCAmelCase_    :     Optional[int]            =	0




 @property
 def 	a   (			self							:			Any			)->       int:



      """simple docstring"""

      return self._images




 @property
 def 	a   (			self							:			str			)->       Tuple:



      """simple docstring"""

      return self._labels




 @property
 def 	a   (			self							:			Dict			)->       List[Any]:



      """simple docstring"""

      return self._num_examples




 @property
 def 	a   (			self							:			Optional[int]			)->       Optional[int]:



      """simple docstring"""

      return self._epochs_completed






 def 	a   (			self							:			Tuple  , a_							:			Union[str, Any]  , a_							:			str=False  , a_							:			str=True			)->       int:



      """simple docstring"""

      if fake_data:
           UpperCAmelCase_    :     Tuple            =	[1] * 7_84
           UpperCAmelCase_    :     Tuple            =	[1] + [0] * 9 if self.one_hot else 0
           return (
               [fake_image for _ in range(a_			)],
               [fake_label for _ in range(a_			)],
           )
      UpperCAmelCase_    :     List[Any]            =	self._index_in_epoch
      # Shuffle for the first epoch
      if self._epochs_completed == 0 and start == 0 and shuffle:
           UpperCAmelCase_    :     Any            =	numpy.arange(self._num_examples			)
           numpy.random.shuffle(a_			)
           UpperCAmelCase_    :     str            =	self.images[perma]
           UpperCAmelCase_    :     Any            =	self.labels[perma]
      # Go to the next epoch
      if start + batch_size > self._num_examples:
           # Finished epoch
           self._epochs_completed += 1
           # Get the rest examples in this epoch
           UpperCAmelCase_    :     List[str]            =	self._num_examples - start
           UpperCAmelCase_    :     Union[str, Any]            =	self._images[start : self._num_examples]
           UpperCAmelCase_    :     Tuple            =	self._labels[start : self._num_examples]
           # Shuffle the data
           if shuffle:
                UpperCAmelCase_    :     Any            =	numpy.arange(self._num_examples			)
                numpy.random.shuffle(a_			)
                UpperCAmelCase_    :     List[Any]            =	self.images[perm]
                UpperCAmelCase_    :     Union[str, Any]            =	self.labels[perm]
           # Start next epoch
           UpperCAmelCase_    :     Optional[Any]            =	0
           UpperCAmelCase_    :     Optional[int]            =	batch_size - rest_num_examples
           UpperCAmelCase_    :     Optional[int]            =	self._index_in_epoch
           UpperCAmelCase_    :     Tuple            =	self._images[start:end]
           UpperCAmelCase_    :     Union[str, Any]            =	self._labels[start:end]
           return (
               numpy.concatenate((images_rest_part, images_new_part)  , axis=0			),
               numpy.concatenate((labels_rest_part, labels_new_part)  , axis=0			),
           )
      else:
           self._index_in_epoch += batch_size
           UpperCAmelCase_    :     Dict            =	self._index_in_epoch
           return self._images[start:end], self._labels[start:end]




@deprecated(lowercase    ,			"""Please write your own downloading logic."""   )
def       A_      (       lowercase    ,			lowercase    ,			lowercase   )  ->				str:


     """simple docstring"""







     if not gfile.Exists(lowercase   ):
          gfile.MakeDirs(lowercase   )
     UpperCAmelCase_    :     Union[str, Any]            =	os.path.join(lowercase    ,			lowercase   )
     if not gfile.Exists(lowercase   ):
          urllib.request.urlretrieve(lowercase    ,			lowercase   )  # noqa: S310
          with gfile.GFile(lowercase   ) as f:
               UpperCAmelCase_    :     int            =	f.size()
          print("""Successfully downloaded"""    ,			lowercase    ,			lowercase    ,			"""bytes."""   )
     return filepath




@deprecated(
    lowercase    ,			"""Please use alternatives such as:""" """ tensorflow_datasets.load('mnist')"""   )
def       A_      (       lowercase    ,			lowercase=False    ,			lowercase=False    ,			lowercase=dtypes.floataa    ,			lowercase=True    ,			lowercase=5000    ,			lowercase=None    ,			lowercase=DEFAULT_SOURCE_URL    ,			)  ->				Tuple:


     """simple docstring"""







     if fake_data:

          def fake():
               return _DataSet(
                   []    ,			[]    ,			fake_data=lowercase    ,			one_hot=lowercase    ,			dtype=lowercase    ,			seed=lowercase   )

          UpperCAmelCase_    :     Optional[int]            =	fake()
          UpperCAmelCase_    :     Optional[Any]            =	fake()
          UpperCAmelCase_    :     str            =	fake()
          return _Datasets(train=lowercase    ,			validation=lowercase    ,			test=lowercase   )

     if not source_url:  # empty string check
          UpperCAmelCase_    :     Any            =	DEFAULT_SOURCE_URL

     UpperCAmelCase_    :     Dict            =	"""train-images-idx3-ubyte.gz"""
     UpperCAmelCase_    :     int            =	"""train-labels-idx1-ubyte.gz"""
     UpperCAmelCase_    :     Optional[Any]            =	"""t10k-images-idx3-ubyte.gz"""
     UpperCAmelCase_    :     Any            =	"""t10k-labels-idx1-ubyte.gz"""

     UpperCAmelCase_    :     Any            =	_maybe_download(
         lowercase    ,			lowercase    ,			source_url + train_images_file   )
     with gfile.Open(lowercase    ,			"""rb"""   ) as f:
          UpperCAmelCase_    :     Tuple            =	_extract_images(lowercase   )

     UpperCAmelCase_    :     Any            =	_maybe_download(
         lowercase    ,			lowercase    ,			source_url + train_labels_file   )
     with gfile.Open(lowercase    ,			"""rb"""   ) as f:
          UpperCAmelCase_    :     int            =	_extract_labels(lowercase    ,			one_hot=lowercase   )

     UpperCAmelCase_    :     Dict            =	_maybe_download(
         lowercase    ,			lowercase    ,			source_url + test_images_file   )
     with gfile.Open(lowercase    ,			"""rb"""   ) as f:
          UpperCAmelCase_    :     str            =	_extract_images(lowercase   )

     UpperCAmelCase_    :     int            =	_maybe_download(
         lowercase    ,			lowercase    ,			source_url + test_labels_file   )
     with gfile.Open(lowercase    ,			"""rb"""   ) as f:
          UpperCAmelCase_    :     Any            =	_extract_labels(lowercase    ,			one_hot=lowercase   )

     if not 0 <= validation_size <= len(lowercase   ):
          UpperCAmelCase_    :     Dict            =	(
              """Validation size should be between 0 and """
              f'''{len(lowercase   )}. Received: {validation_size}.'''
          )
          raise ValueError(lowercase   )

     UpperCAmelCase_    :     List[Any]            =	train_images[:validation_size]
     UpperCAmelCase_    :     Any            =	train_labels[:validation_size]
     UpperCAmelCase_    :     Union[str, Any]            =	train_images[validation_size:]
     UpperCAmelCase_    :     Any            =	train_labels[validation_size:]

     UpperCAmelCase_    :     str            =	{"""dtype""": dtype, """reshape""": reshape, """seed""": seed}

     UpperCAmelCase_    :     List[str]            =	_DataSet(lowercase    ,			lowercase    ,			**lowercase   )
     UpperCAmelCase_    :     Optional[int]            =	_DataSet(lowercase    ,			lowercase    ,			**lowercase   )
     UpperCAmelCase_    :     Union[str, Any]            =	_DataSet(lowercase    ,			lowercase    ,			**lowercase   )

     return _Datasets(train=lowercase    ,			validation=lowercase    ,			test=lowercase   )



"""simple docstring"""







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 		UpperCAmelCase_						(unittest.TestCase    ):
 """simple docstring"""




 def 	a   (			self							:			str  , a_							:			int  , a_							:			int			)->       Optional[Any]:



      """simple docstring"""

      UpperCAmelCase_    :     List[Any]            =	jnp.ones((batch_size, length)			) / length
      return scores




 def 	a   (			self							:			str			)->       int:



      """simple docstring"""

      UpperCAmelCase_    :     List[Any]            =	None
      UpperCAmelCase_    :     int            =	20

      UpperCAmelCase_    :     Tuple            =	self._get_uniform_logits(batch_size=2  , length=a_			)

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

      # compute softmax
      UpperCAmelCase_    :     str            =	jax.nn.softmax(a_  , axis=-1			)

      UpperCAmelCase_    :     Union[str, Any]            =	FlaxTemperatureLogitsWarper(temperature=0.5			)
      UpperCAmelCase_    :     Any            =	FlaxTemperatureLogitsWarper(temperature=1.3			)

      UpperCAmelCase_    :     Optional[Any]            =	jax.nn.softmax(temp_dist_warper_sharper(a_  , scores.copy()  , cur_len=a_			)  , axis=-1			)
      UpperCAmelCase_    :     List[str]            =	jax.nn.softmax(temp_dist_warper_smoother(a_  , scores.copy()  , cur_len=a_			)  , 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 	a   (			self							:			Union[str, Any]			)->       Tuple:



      """simple docstring"""

      UpperCAmelCase_    :     Dict            =	None
      UpperCAmelCase_    :     str            =	10
      UpperCAmelCase_    :     List[Any]            =	2

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

      UpperCAmelCase_    :     List[Any]            =	FlaxTopKLogitsWarper(3			)

      UpperCAmelCase_    :     Tuple            =	top_k_warp(a_  , a_  , cur_len=a_			)

      # 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
      UpperCAmelCase_    :     Any            =	5
      UpperCAmelCase_    :     Optional[int]            =	FlaxTopKLogitsWarper(top_k=1  , filter_value=0.0  , min_tokens_to_keep=3			)

      UpperCAmelCase_    :     Any            =	np.broadcast_to(np.arange(a_			)[None, :]  , (batch_size, length)			).copy()
      UpperCAmelCase_    :     Tuple            =	top_k_warp_safety_check(a_  , a_  , cur_len=a_			)

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




 def 	a   (			self							:			Dict			)->       List[str]:



      """simple docstring"""

      UpperCAmelCase_    :     Tuple            =	None
      UpperCAmelCase_    :     List[str]            =	10
      UpperCAmelCase_    :     List[Any]            =	2

      # create distribution and take log (inverse to Softmax as taken in TopPLogitsWarper)
      UpperCAmelCase_    :     int            =	np.log(np.array([[0.3, 0.1, 0.1, 0.5], [0.15, 0.3, 0.3, 0.25]]			)			)

      UpperCAmelCase_    :     str            =	FlaxTopPLogitsWarper(0.8			)
      UpperCAmelCase_    :     Union[str, Any]            =	np.exp(top_p_warp(a_  , a_  , cur_len=a_			)			)

      # dist should be filtered to keep min num values so that sum is >= top_p
      # exp (-inf) => 0
      UpperCAmelCase_    :     List[Any]            =	np.array([[0.3, 0.0, 0.0, 0.5], [0.0, 0.3, 0.3, 0.25]]			)
      self.assertTrue(np.allclose(a_  , a_  , atol=1E-3			)			)

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

      # make ramp_logits more extreme
      UpperCAmelCase_    :     Tuple            =	ramp_logits[1] * 100.0

      # make sure at least 2 tokens are kept
      UpperCAmelCase_    :     Any            =	FlaxTopPLogitsWarper(0.9  , min_tokens_to_keep=2  , filter_value=0.0			)
      UpperCAmelCase_    :     Dict            =	top_p_warp(a_  , a_  , cur_len=a_			)

      # 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 	a   (			self							:			List[str]			)->       Any:



      """simple docstring"""

      UpperCAmelCase_    :     Dict            =	20
      UpperCAmelCase_    :     List[str]            =	4
      UpperCAmelCase_    :     Dict            =	0

      UpperCAmelCase_    :     Union[str, Any]            =	FlaxMinLengthLogitsProcessor(min_length=10  , eos_token_id=a_			)

      # check that min length is applied at length 5
      UpperCAmelCase_    :     Union[str, Any]            =	ids_tensor((batch_size, 20)  , vocab_size=20			)
      UpperCAmelCase_    :     str            =	5
      UpperCAmelCase_    :     Tuple            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     List[Any]            =	min_dist_processor(a_  , a_  , cur_len=a_			)
      self.assertListEqual(scores_before_min_length[:, eos_token_id].tolist()  , 4 * [-float("""inf"""			)]			)

      # check that min length is not applied anymore at length 15
      UpperCAmelCase_    :     str            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     Optional[Any]            =	15
      UpperCAmelCase_    :     str            =	min_dist_processor(a_  , a_  , cur_len=a_			)
      self.assertFalse(jnp.isinf(a_			).any()			)




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



      """simple docstring"""

      UpperCAmelCase_    :     Optional[int]            =	20
      UpperCAmelCase_    :     int            =	4
      UpperCAmelCase_    :     str            =	0

      UpperCAmelCase_    :     Optional[int]            =	FlaxForcedBOSTokenLogitsProcessor(bos_token_id=a_			)

      # check that all scores are -inf except the bos_token_id score
      UpperCAmelCase_    :     List[str]            =	ids_tensor((batch_size, 1)  , vocab_size=20			)
      UpperCAmelCase_    :     List[Any]            =	1
      UpperCAmelCase_    :     int            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     int            =	logits_processor(a_  , a_  , cur_len=a_			)
      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
      UpperCAmelCase_    :     int            =	3
      UpperCAmelCase_    :     Tuple            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     Union[str, Any]            =	logits_processor(a_  , a_  , cur_len=a_			)
      self.assertFalse(jnp.isinf(a_			).any()			)




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



      """simple docstring"""

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

      UpperCAmelCase_    :     Optional[Any]            =	FlaxForcedEOSTokenLogitsProcessor(max_length=a_  , eos_token_id=a_			)

      # check that all scores are -inf except the eos_token_id when max_length is reached
      UpperCAmelCase_    :     str            =	ids_tensor((batch_size, 4)  , vocab_size=20			)
      UpperCAmelCase_    :     int            =	4
      UpperCAmelCase_    :     Optional[Any]            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     Union[str, Any]            =	logits_processor(a_  , a_  , cur_len=a_			)
      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
      UpperCAmelCase_    :     Any            =	3
      UpperCAmelCase_    :     Tuple            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     int            =	logits_processor(a_  , a_  , cur_len=a_			)
      self.assertFalse(jnp.isinf(a_			).any()			)




 def 	a   (			self							:			int			)->       List[Any]:



      """simple docstring"""

      UpperCAmelCase_    :     Dict            =	4
      UpperCAmelCase_    :     List[Any]            =	10
      UpperCAmelCase_    :     Tuple            =	15
      UpperCAmelCase_    :     Optional[Any]            =	2
      UpperCAmelCase_    :     List[Any]            =	1
      UpperCAmelCase_    :     Dict            =	15

      # dummy input_ids and scores
      UpperCAmelCase_    :     Dict            =	ids_tensor((batch_size, sequence_length)  , a_			)
      UpperCAmelCase_    :     Tuple            =	input_ids.copy()

      UpperCAmelCase_    :     int            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     Optional[Any]            =	scores.copy()

      # instantiate all dist processors
      UpperCAmelCase_    :     Tuple            =	FlaxTemperatureLogitsWarper(temperature=0.5			)
      UpperCAmelCase_    :     str            =	FlaxTopKLogitsWarper(3			)
      UpperCAmelCase_    :     Tuple            =	FlaxTopPLogitsWarper(0.8			)

      # instantiate all logits processors
      UpperCAmelCase_    :     Tuple            =	FlaxMinLengthLogitsProcessor(min_length=10  , eos_token_id=a_			)
      UpperCAmelCase_    :     Optional[Any]            =	FlaxForcedBOSTokenLogitsProcessor(bos_token_id=a_			)
      UpperCAmelCase_    :     Tuple            =	FlaxForcedEOSTokenLogitsProcessor(max_length=a_  , eos_token_id=a_			)

      UpperCAmelCase_    :     Tuple            =	10

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

      # with processor list
      UpperCAmelCase_    :     Tuple            =	FlaxLogitsProcessorList(
          [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc]			)
      UpperCAmelCase_    :     Union[str, Any]            =	processor(a_  , a_  , cur_len=a_			)

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

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






 def 	a   (			self							:			Optional[int]			)->       Any:



      """simple docstring"""

      UpperCAmelCase_    :     Any            =	4
      UpperCAmelCase_    :     List[Any]            =	10
      UpperCAmelCase_    :     Optional[int]            =	15
      UpperCAmelCase_    :     Optional[Any]            =	2
      UpperCAmelCase_    :     Dict            =	1
      UpperCAmelCase_    :     int            =	15

      # dummy input_ids and scores
      UpperCAmelCase_    :     List[str]            =	ids_tensor((batch_size, sequence_length)  , a_			)
      UpperCAmelCase_    :     Dict            =	input_ids.copy()

      UpperCAmelCase_    :     Dict            =	self._get_uniform_logits(a_  , a_			)
      UpperCAmelCase_    :     Tuple            =	scores.copy()

      # instantiate all dist processors
      UpperCAmelCase_    :     Dict            =	FlaxTemperatureLogitsWarper(temperature=0.5			)
      UpperCAmelCase_    :     int            =	FlaxTopKLogitsWarper(3			)
      UpperCAmelCase_    :     int            =	FlaxTopPLogitsWarper(0.8			)

      # instantiate all logits processors
      UpperCAmelCase_    :     str            =	FlaxMinLengthLogitsProcessor(min_length=10  , eos_token_id=a_			)
      UpperCAmelCase_    :     Dict            =	FlaxForcedBOSTokenLogitsProcessor(bos_token_id=a_			)
      UpperCAmelCase_    :     Union[str, Any]            =	FlaxForcedEOSTokenLogitsProcessor(max_length=a_  , eos_token_id=a_			)

      UpperCAmelCase_    :     Dict            =	10

      # no processor list
      def run_no_processor_list(a_							:			Any  , a_							:			List[str]  , a_							:			Tuple			):
           UpperCAmelCase_    :     List[Any]            =	temp_dist_warp(a_  , a_  , cur_len=a_			)
           UpperCAmelCase_    :     Tuple            =	top_k_warp(a_  , a_  , cur_len=a_			)
           UpperCAmelCase_    :     int            =	top_p_warp(a_  , a_  , cur_len=a_			)
           UpperCAmelCase_    :     Tuple            =	min_dist_proc(a_  , a_  , cur_len=a_			)
           UpperCAmelCase_    :     Optional[int]            =	bos_dist_proc(a_  , a_  , cur_len=a_			)
           UpperCAmelCase_    :     List[Any]            =	eos_dist_proc(a_  , a_  , cur_len=a_			)
           return scores

      # with processor list
      def run_processor_list(a_							:			List[str]  , a_							:			Optional[int]  , a_							:			Optional[int]			):
           UpperCAmelCase_    :     List[str]            =	FlaxLogitsProcessorList(
               [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc]			)
           UpperCAmelCase_    :     Optional[Any]            =	processor(a_  , a_  , cur_len=a_			)
           return scores

      UpperCAmelCase_    :     str            =	jax.jit(a_			)
      UpperCAmelCase_    :     Tuple            =	jax.jit(a_			)

      UpperCAmelCase_    :     Optional[int]            =	jitted_run_no_processor_list(a_  , a_  , a_			)
      UpperCAmelCase_    :     List[Any]            =	jitted_run_processor_list(a_  , a_  , a_			)

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

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

