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 			UpperCamelCase__   (	self , __lowercase , __lowercase)       ->	Tuple:
        __UpperCamelCase     :List[Any]			  =		jnp.ones((batch_size, length)) / length
        return scores







    def 			UpperCamelCase__   (	self)       ->	Optional[int]:
        __UpperCamelCase     :Dict			  =		None
        __UpperCamelCase     :Dict			  =		20

        __UpperCamelCase     :int			  =		self._get_uniform_logits(batch_size=2 , length=SCREAMING_SNAKE_CASE_)

        # tweak scores to not be uniform anymore
        __UpperCamelCase     :int			  =		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     :Optional[Any]			  =		jax.nn.softmax(SCREAMING_SNAKE_CASE_ , axis=-1)

        __UpperCamelCase     :Tuple			  =		FlaxTemperatureLogitsWarper(temperature=0.5)
        __UpperCamelCase     :int			  =		FlaxTemperatureLogitsWarper(temperature=1.3)

        __UpperCamelCase     :int			  =		jax.nn.softmax(temp_dist_warper_sharper(SCREAMING_SNAKE_CASE_ , scores.copy() , cur_len=SCREAMING_SNAKE_CASE_) , axis=-1)
        __UpperCamelCase     :Union[str, 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 			UpperCamelCase__   (	self)       ->	Union[str, Any]:
        __UpperCamelCase     :Optional[Any]			  =		None
        __UpperCamelCase     :Optional[int]			  =		10
        __UpperCamelCase     :Optional[Any]			  =		2

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

        __UpperCamelCase     :int			  =		FlaxTopKLogitsWarper(3)

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

        __UpperCamelCase     :int			  =		np.broadcast_to(np.arange(SCREAMING_SNAKE_CASE_)[None, :] , (batch_size, length)).copy()
        __UpperCamelCase     :List[str]			  =		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 			UpperCamelCase__   (	self)       ->	List[str]:
        __UpperCamelCase     :List[Any]			  =		None
        __UpperCamelCase     :Union[str, Any]			  =		10
        __UpperCamelCase     :List[Any]			  =		2

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

        __UpperCamelCase     :Optional[int]			  =		FlaxTopPLogitsWarper(0.8)
        __UpperCamelCase     :Tuple			  =		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
        __UpperCamelCase     :Union[str, Any]			  =		np.array([[0.3, 0.0, 0.0, 0.5], [0.0, 0.3, 0.3, 0.25]])
        self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , atol=1E-3))

        # check edge cases with negative and extreme logits
        __UpperCamelCase     :int			  =		np.broadcast_to(np.arange(SCREAMING_SNAKE_CASE_)[None, :] , (batch_size, vocab_size)).copy() - (
            vocab_size // 2
        )

        # make ramp_logits more extreme
        __UpperCamelCase     :Optional[Any]			  =		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     :List[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 			UpperCamelCase__   (	self)       ->	List[str]:
        __UpperCamelCase     :Union[str, Any]			  =		20
        __UpperCamelCase     :Optional[int]			  =		4
        __UpperCamelCase     :str			  =		0

        __UpperCamelCase     :Optional[Any]			  =		FlaxMinLengthLogitsProcessor(min_length=10 , eos_token_id=SCREAMING_SNAKE_CASE_)

        # check that min length is applied at length 5
        __UpperCamelCase     :List[Any]			  =		ids_tensor((batch_size, 20) , vocab_size=20)
        __UpperCamelCase     :Tuple			  =		5
        __UpperCamelCase     :Any			  =		self._get_uniform_logits(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Dict			  =		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
        __UpperCamelCase     :Any			  =		self._get_uniform_logits(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		15
        __UpperCamelCase     :List[str]			  =		min_dist_processor(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        self.assertFalse(jnp.isinf(SCREAMING_SNAKE_CASE_).any())







    def 			UpperCamelCase__   (	self)       ->	int:
        __UpperCamelCase     :int			  =		20
        __UpperCamelCase     :Union[str, Any]			  =		4
        __UpperCamelCase     :List[Any]			  =		0

        __UpperCamelCase     :List[Any]			  =		FlaxForcedBOSTokenLogitsProcessor(bos_token_id=SCREAMING_SNAKE_CASE_)

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







    def 			UpperCamelCase__   (	self)       ->	List[Any]:
        __UpperCamelCase     :Optional[Any]			  =		20
        __UpperCamelCase     :Any			  =		4
        __UpperCamelCase     :List[str]			  =		0
        __UpperCamelCase     :Optional[Any]			  =		5

        __UpperCamelCase     :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
        __UpperCamelCase     :str			  =		ids_tensor((batch_size, 4) , vocab_size=20)
        __UpperCamelCase     :Any			  =		4
        __UpperCamelCase     :Optional[Any]			  =		self._get_uniform_logits(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :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
        __UpperCamelCase     :Dict			  =		3
        __UpperCamelCase     :int			  =		self._get_uniform_logits(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		logits_processor(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        self.assertFalse(jnp.isinf(SCREAMING_SNAKE_CASE_).any())







    def 			UpperCamelCase__   (	self)       ->	List[str]:
        __UpperCamelCase     :Optional[Any]			  =		4
        __UpperCamelCase     :List[Any]			  =		10
        __UpperCamelCase     :Union[str, Any]			  =		15
        __UpperCamelCase     :Union[str, Any]			  =		2
        __UpperCamelCase     :List[Any]			  =		1
        __UpperCamelCase     :List[Any]			  =		15

        # dummy input_ids and scores
        __UpperCamelCase     :int			  =		ids_tensor((batch_size, sequence_length) , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :str			  =		input_ids.copy()

        __UpperCamelCase     :str			  =		self._get_uniform_logits(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		scores.copy()

        # instantiate all dist processors
        __UpperCamelCase     :Dict			  =		FlaxTemperatureLogitsWarper(temperature=0.5)
        __UpperCamelCase     :Optional[int]			  =		FlaxTopKLogitsWarper(3)
        __UpperCamelCase     :int			  =		FlaxTopPLogitsWarper(0.8)

        # instantiate all logits processors
        __UpperCamelCase     :int			  =		FlaxMinLengthLogitsProcessor(min_length=10 , eos_token_id=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :int			  =		FlaxForcedBOSTokenLogitsProcessor(bos_token_id=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :str			  =		FlaxForcedEOSTokenLogitsProcessor(max_length=SCREAMING_SNAKE_CASE_ , eos_token_id=SCREAMING_SNAKE_CASE_)

        __UpperCamelCase     :str			  =		10

        # no processor list
        __UpperCamelCase     :Optional[Any]			  =		temp_dist_warp(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Tuple			  =		top_k_warp(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Tuple			  =		top_p_warp(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		min_dist_proc(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Optional[int]			  =		bos_dist_proc(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Optional[Any]			  =		eos_dist_proc(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)

        # with processor list
        __UpperCamelCase     :Any			  =		FlaxLogitsProcessorList(
            [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc])
        __UpperCamelCase     :Union[str, Any]			  =		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 			UpperCamelCase__   (	self)       ->	int:
        __UpperCamelCase     :str			  =		4
        __UpperCamelCase     :str			  =		10
        __UpperCamelCase     :Optional[int]			  =		15
        __UpperCamelCase     :int			  =		2
        __UpperCamelCase     :Optional[int]			  =		1
        __UpperCamelCase     :Dict			  =		15

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

        __UpperCamelCase     :Any			  =		self._get_uniform_logits(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Any			  =		scores.copy()

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

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

        __UpperCamelCase     :Any			  =		10

        # no processor list
        def run_no_processor_list(__lowercase , __lowercase , __lowercase):
            __UpperCamelCase     :Dict			  =		temp_dist_warp(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            __UpperCamelCase     :Dict			  =		top_k_warp(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            __UpperCamelCase     :Any			  =		top_p_warp(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            __UpperCamelCase     :List[str]			  =		min_dist_proc(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            __UpperCamelCase     :List[str]			  =		bos_dist_proc(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            __UpperCamelCase     :List[str]			  =		eos_dist_proc(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            return scores

        # with processor list
        def run_processor_list(__lowercase , __lowercase , __lowercase):
            __UpperCamelCase     :str			  =		FlaxLogitsProcessorList(
                [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc])
            __UpperCamelCase     :Tuple			  =		processor(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , cur_len=SCREAMING_SNAKE_CASE_)
            return scores

        __UpperCamelCase     :List[Any]			  =		jax.jit(SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :Optional[Any]			  =		jax.jit(SCREAMING_SNAKE_CASE_)

        __UpperCamelCase     :Tuple			  =		jitted_run_no_processor_list(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_)
        __UpperCamelCase     :str			  =		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())







import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad
class  lowercase__(				unittest.TestCase							):



	"""simple docstring"""




	def 						_lowercase  (       self  :			List[str]       )       ->     List[Any]:
					lowercase_       =					1_0
	def 						_lowercase  (       self  :			int       )       ->     List[str]:
					lowercase_       =					[1, 2, 3, 4]
					lowercase_       =					[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
					self.assertEqual(truncate_or_pad(SCREAMING_SNAKE_CASE_       ,							self.block_size       ,							0       )       ,							SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			int       )       ->     Optional[Any]:
					lowercase_       =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
					lowercase_       =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
					self.assertEqual(truncate_or_pad(SCREAMING_SNAKE_CASE_       ,							self.block_size       ,							0       )       ,							SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     Optional[int]:
					lowercase_       =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0, 1_1, 1_2, 1_3]
					lowercase_       =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
					self.assertEqual(truncate_or_pad(SCREAMING_SNAKE_CASE_       ,							self.block_size       ,							0       )       ,							SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Any       )       ->     List[Any]:
					lowercase_       =					'''It was the year of Our Lord one thousand seven hundred and
        seventy-five.\n\nSpiritual revelations were conceded to England at that
        favoured period, as at this.'''
					lowercase_  ,	lowercase_       =					process_story(SCREAMING_SNAKE_CASE_       )
					self.assertEqual(SCREAMING_SNAKE_CASE_       ,							[]       )
	def 						_lowercase  (       self  :			List[str]       )       ->     List[str]:
					lowercase_       =					''''''
					lowercase_  ,	lowercase_       =					process_story(SCREAMING_SNAKE_CASE_       )
					self.assertEqual(SCREAMING_SNAKE_CASE_       ,							[]       )
					self.assertEqual(SCREAMING_SNAKE_CASE_       ,							[]       )
	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     Union[str, Any]:
					lowercase_       =					(
					    '''It was the year of Our Lord one thousand seven hundred and '''
					    '''seventy-five\n\nSpiritual revelations were conceded to England '''
					    '''at that favoured period, as at this.\n@highlight\n\nIt was the best of times'''
					)
					lowercase_  ,	lowercase_       =					process_story(SCREAMING_SNAKE_CASE_       )

					lowercase_       =					[
					    '''It was the year of Our Lord one thousand seven hundred and seventy-five.''',
					    '''Spiritual revelations were conceded to England at that favoured period, as at this.''',
					]
					self.assertEqual(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )

					lowercase_       =					['''It was the best of times.''']
					self.assertEqual(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     Optional[Any]:
					lowercase_       =					torch.tensor([1, 2, 3, 4]       )
					lowercase_       =					torch.tensor([1, 1, 1, 1]       )
					np.testing.assert_array_equal(build_mask(SCREAMING_SNAKE_CASE_       ,							0       ).numpy()       ,							expected.numpy()       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     Tuple:
					lowercase_       =					torch.tensor([1, 2, 3, 4, 2_3, 2_3, 2_3]       )
					lowercase_       =					torch.tensor([1, 1, 1, 1, 0, 0, 0]       )
					np.testing.assert_array_equal(build_mask(SCREAMING_SNAKE_CASE_       ,							2_3       ).numpy()       ,							expected.numpy()       )
	def 						_lowercase  (       self  :			int       )       ->     Dict:
					lowercase_       =					torch.tensor([8, 2, 3, 4, 1, 1, 1]       )
					lowercase_       =					torch.tensor([1, 1, 1, 1, 0, 0, 0]       )
					np.testing.assert_array_equal(build_mask(SCREAMING_SNAKE_CASE_       ,							1       ).numpy()       ,							expected.numpy()       )




	def 						_lowercase  (       self  :			List[str]       )       ->     Tuple:
					lowercase_       =					1_0_1
					lowercase_       =					torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 1_0_1, 5, 6], [1, 1_0_1, 3, 4, 1_0_1, 6]]       )
					lowercase_       =					torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]       )

					lowercase_       =					compute_token_type_ids(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )
					np.testing.assert_array_equal(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )




