
"""simple docstring"""




from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
					import tensorflow as tf

					from transformers import AutoTokenizer, TFAutoModelForSeqaSeqLM



@require_tf
@require_sentencepiece
@require_tokenizers
class 	lowerCAmelCase_						(unittest.TestCase  ):


				"""simple docstring"""



				@slow
				def 	__magic_name__    (self    )					->		Tuple:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       List[str]           =   TFAutoModelForSeqaSeqLM.from_pretrained("""google/mt5-small"""    )
											SCREAMING_SNAKE_CASE__						:       int           =   AutoTokenizer.from_pretrained("""google/mt5-small"""    )

											SCREAMING_SNAKE_CASE__						:       List[str]           =   tokenizer("""Hello there"""   ,       return_tensors="""tf"""    ).input_ids
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   tokenizer("""Hi I am"""   ,       return_tensors="""tf"""    ).input_ids

											SCREAMING_SNAKE_CASE__						:       List[Any]           =   model(SCREAMING_SNAKE_CASE__   ,       labels=SCREAMING_SNAKE_CASE__    ).loss
											SCREAMING_SNAKE_CASE__						:       List[Any]           =   -tf.math.reduce_mean(SCREAMING_SNAKE_CASE__    ).numpy()

											SCREAMING_SNAKE_CASE__						:       List[str]           =   -21.228168
											self.assertTrue(abs(mtf_score - EXPECTED_SCORE    ) < 2E-4    )






"""simple docstring"""




import pickle
import unittest

import torch

from accelerate import Accelerator
from accelerate.state import AcceleratorState
from accelerate.test_utils import require_cpu



@require_cpu
class 	lowerCAmelCase_						(unittest.TestCase  ):


				"""simple docstring"""



				def 	__magic_name__    (self    )					->		Union[str, Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       List[Any]           =   torch.nn.Linear(10   ,       10    )
											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   torch.optim.SGD(model.parameters()   ,       0.1    )
											SCREAMING_SNAKE_CASE__						:       int           =   Accelerator()
											SCREAMING_SNAKE_CASE__						:       List[Any]           =   accelerator.prepare(SCREAMING_SNAKE_CASE__    )
											try:
																		pickle.loads(pickle.dumps(SCREAMING_SNAKE_CASE__    )    )
											except Exception as e:
																		self.fail(F'''Accelerated optimizer pickling failed with {e}'''    )
											AcceleratorState._reset_state()




