

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







    """simple docstring"""





    @slow
    def 						snake_case__     (      self :       List[Any]		)->    Optional[int]:





        '''simple docstring'''







        A__          =   FlaxMTaForConditionalGeneration.from_pretrained('google/mt5-small'		)
        A__          =   AutoTokenizer.from_pretrained('google/mt5-small'		)

        A__          =   tokenizer('Hello there',return_tensors='np'		).input_ids
        A__          =   tokenizer('Hi I am',return_tensors='np'		).input_ids

        A__          =   shift_tokens_right(lowercase_,model.config.pad_token_id,model.config.decoder_start_token_id		)

        A__          =   model(lowercase_,decoder_input_ids=lowercase_		).logits
        A__          =   optax.softmax_cross_entropy(lowercase_,onehot(lowercase_,logits.shape[-1]		)		).mean()

        A__          =   -(labels.shape[-1] * loss.item())

        A__          =   -84.9_127
        self.assertTrue(abs(mtf_score - EXPECTED_SCORE		) < 1E-4		)









import unittest

from transformers import load_tool
from transformers.utils import is_torch_available


if is_torch_available():
 import torch

from transformers.testing_utils import require_torch

from .test_tools_common import ToolTesterMixin





@require_torch
class 			__a  (    unittest.TestCase       ,   A__       ):







 def 					__lowercase					(		self					:   Any						):


      '''simple docstring'''






      UpperCamelCase__			:   Dict       				=  load_tool("text-to-speech"						)
      self.tool.setup()







 def 					__lowercase					(		self					:   Union[str, Any]						):


      '''simple docstring'''






      torch.manual_seed(0						)
      UpperCamelCase__			:   Union[str, Any]       				=  self.tool("hey"						)
      UpperCamelCase__			:   Any       				=  result.to_raw()
      self.assertTrue(
          torch.allclose(
              resulting_tensor[:3]							,   torch.tensor([-0.0_0_0_5_9_6_6_6_6_8_8_3_2_1_1_5_8_2_9, -0.0_0_0_3_6_5_7_6_4_0_1_9_0_7_9_5_0_6_4, -0.0_0_0_1_3_4_3_9_5_0_2_7_9_9_8_8_3_4_8_5]						)							,   )						)







 def 					__lowercase					(		self					:   List[Any]						):


      '''simple docstring'''






      torch.manual_seed(0						)
      UpperCamelCase__			:   List[Any]       				=  self.tool("hey"						)
      UpperCamelCase__			:   int       				=  result.to_raw()
      self.assertTrue(
          torch.allclose(
              resulting_tensor[:3]							,   torch.tensor([-0.0_0_0_5_9_6_6_6_6_8_8_3_2_1_1_5_8_2_9, -0.0_0_0_3_6_5_7_6_4_0_1_9_0_7_9_5_0_6_4, -0.0_0_0_1_3_4_3_9_5_0_2_7_9_9_8_8_3_4_8_5]						)							,   )						)