'''simple docstring'''





import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
   from transformers import AutoModelForSeqaSeqLM, AutoTokenizer







@require_torch
@require_sentencepiece
@require_tokenizers
class __snake_case       (		unittest.TestCase	):




   @slow
   def 			__a		(					self    :       str   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   AutoModelForSeqaSeqLM.from_pretrained("""google/mt5-small""" ,			return_dict=_lowerCamelCase   ).to(_lowerCamelCase   )
     SCREAMING_SNAKE_CASE__    							=   AutoTokenizer.from_pretrained("""google/mt5-small"""   )

     SCREAMING_SNAKE_CASE__    							=   tokenizer("""Hello there""" ,			return_tensors="""pt"""   ).input_ids
     SCREAMING_SNAKE_CASE__    							=   tokenizer("""Hi I am""" ,			return_tensors="""pt"""   ).input_ids

     SCREAMING_SNAKE_CASE__    							=   model(input_ids.to(_lowerCamelCase   ) ,			labels=labels.to(_lowerCamelCase   )   ).loss
     SCREAMING_SNAKE_CASE__    							=   -(labels.shape[-1] * loss.item())

     SCREAMING_SNAKE_CASE__    							=   -84.91_27
     self.assertTrue(abs(mtf_score - EXPECTED_SCORE   ) < 1E-4   )

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




   def 			__a		(					self    :       Any   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   torch.nn.Linear(10 ,			10   )
     SCREAMING_SNAKE_CASE__    							=   torch.optim.SGD(model.parameters() ,			0.1   )
     SCREAMING_SNAKE_CASE__    							=   Accelerator()
     SCREAMING_SNAKE_CASE__    							=   accelerator.prepare(_lowercase   )
     try:
       pickle.loads(pickle.dumps(_lowercase   )   )
     except Exception as e:
       self.fail(f"""Accelerated optimizer pickling failed with {e}"""   )
     AcceleratorState._reset_state()
