



"""simple docstring"""





def 	__lowerCAmelCase						(		__UpperCamelCase      :			bytes    ):


						'''simple docstring'''






						return "".join([hex(__UpperCamelCase    )[2:].zfill(2    ).upper() for byte in list(__UpperCamelCase    )]    )
def 	__lowerCAmelCase						(		__UpperCamelCase      :			str    ):


						'''simple docstring'''






						if (len(__UpperCamelCase    ) % 2) != 0:
												raise ValueError(
												    """Base16 encoded data is invalid:
Data does not have an even number of hex digits."""    )
						# Check the character set - the standard base16 alphabet
						# is uppercase according to RFC3548 section 6
						if not set(__UpperCamelCase    ) <= set("""0123456789ABCDEF"""    ):
												raise ValueError(
												    """Base16 encoded data is invalid:
Data is not uppercase hex or it contains invalid characters."""    )
						# For every two hexadecimal digits (= a byte), turn it into an integer.
						# Then, string the result together into bytes, and return it.
						return bytes(int(data[i] + data[i + 1]					, 1_6    ) for i in range(0					, len(__UpperCamelCase    )					, 2    )    )


if __name__ == "__main__":
					import doctest

					doctest.testmod()






"""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    _lowerCAmelCase    (				unittest.TestCase		):





		"""simple docstring"""






		@slow
		def    UpperCAmelCase__							(					self   ) ->						Optional[int]:







								'''simple docstring'''

								snake_case_   : int						=			FlaxMTaForConditionalGeneration.from_pretrained("""google/mt5-small"""   )
								snake_case_   : List[Any]						=			AutoTokenizer.from_pretrained("""google/mt5-small"""   )

								snake_case_   : Dict						=			tokenizer("""Hello there"""							,    return_tensors="""np"""   ).input_ids
								snake_case_   : List[str]						=			tokenizer("""Hi I am"""							,    return_tensors="""np"""   ).input_ids

								snake_case_   : Optional[Any]						=			shift_tokens_right(_lowercase							,    model.config.pad_token_id							,    model.config.decoder_start_token_id   )

								snake_case_   : Tuple						=			model(_lowercase							,    decoder_input_ids=_lowercase   ).logits
								snake_case_   : Tuple						=			optax.softmax_cross_entropy(_lowercase							,    onehot(_lowercase							,    logits.shape[-1]   )   ).mean()

								snake_case_   : List[str]						=			-(labels.shape[-1] * loss.item())

								snake_case_   : Optional[int]						=			-84.9127
								self.assertTrue(abs(mtf_score - EXPECTED_SCORE   ) < 1E-4   )

