"""simple docstring"""







import unittest

from transformers import is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, require_torch, slow


if is_flax_available():
		import optax
		from flax.training.common_utils import onehot

		from transformers import AutoTokenizer, FlaxMTaForConditionalGeneration
		from transformers.models.ta.modeling_flax_ta import shift_tokens_right

@require_torch
@require_sentencepiece
@require_tokenizers
@require_flax
class 		UpperCamelCase      (   unittest.TestCase						):



				@slow
				def  _lowercase					(self    :				Dict)   ->     Optional[Any]:
					__snake_case      :							Union[str, Any]						=			FlaxMTaForConditionalGeneration.from_pretrained('google/mt5-small')
					__snake_case      :							int						=			AutoTokenizer.from_pretrained('google/mt5-small')

					__snake_case      :							List[Any]						=			tokenizer('Hello there'     ,  return_tensors='np').input_ids
					__snake_case      :							List[str]						=			tokenizer('Hi I am'     ,  return_tensors='np').input_ids

					__snake_case      :							Tuple						=			shift_tokens_right(_A     ,  model.config.pad_token_id     ,  model.config.decoder_start_token_id)

					__snake_case      :							Union[str, Any]						=			model(_A     ,  decoder_input_ids=_A).logits
					__snake_case      :							str						=			optax.softmax_cross_entropy(_A     ,  onehot(_A     ,  logits.shape[-1])).mean()

					__snake_case      :							Dict						=			-(labels.shape[-1] * loss.item())

					__snake_case      :							List[Any]						=			-84.9_127
					self.assertTrue(abs(mtf_score - EXPECTED_SCORE) < 1E-4)






"""simple docstring"""







def   __UpperCAmelCase    (   UpperCAmelCase_   :    list      ,							UpperCAmelCase_   :    int      ,							UpperCAmelCase_   :    int = 0      ,							UpperCAmelCase_   :    int = 0  )							->      int:

	'''simple docstring'''





	__snake_case      :							str						=			right or len(UpperCAmelCase_  ) - 1
	if left > right:
		return -1
	elif list_data[left] == key:
		return left
	elif list_data[right] == key:
		return right
	else:
		return search(UpperCAmelCase_      ,							UpperCAmelCase_      ,							left + 1      ,							right - 1  )


if __name__ == "__main__":
	import doctest

	doctest.testmod()





