"""simple docstring"""




import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
     import jax

     from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
     from transformers.models.bert.modeling_flax_bert import FlaxBertModel
     from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel
@require_flax
class 		__A							(				unittest.TestCase	):






     @slow
     def 					__A						(	self						):
       for model_name in ["bert-base-cased", "bert-large-uncased"]:
         with self.subTest(a__						):
           _lowerCAmelCase		: Optional[int]						    =  AutoConfig.from_pretrained(a__						)
           self.assertIsNotNone(a__						)
           self.assertIsInstance(a__       ,  a__						)

           _lowerCAmelCase		: str						    =  FlaxAutoModel.from_pretrained(a__						)
           self.assertIsNotNone(a__						)
           self.assertIsInstance(a__       ,  a__						)






     @slow
     def 					__A						(	self						):
       for model_name in ["roberta-base", "roberta-large"]:
         with self.subTest(a__						):
           _lowerCAmelCase		: Tuple						    =  AutoConfig.from_pretrained(a__						)
           self.assertIsNotNone(a__						)
           self.assertIsInstance(a__       ,  a__						)

           _lowerCAmelCase		: Tuple						    =  FlaxAutoModel.from_pretrained(a__						)
           self.assertIsNotNone(a__						)
           self.assertIsInstance(a__       ,  a__						)






     @slow
     def 					__A						(	self						):
       for model_name in ["bert-base-cased", "bert-large-uncased"]:
         _lowerCAmelCase		: Union[str, Any]						    =  AutoTokenizer.from_pretrained(a__						)
         _lowerCAmelCase		: Optional[Any]						    =  FlaxBertModel.from_pretrained(a__						)
         _lowerCAmelCase		: int						    =  tokenizer("""Do you support jax jitted function?"""       ,  return_tensors=TensorType.JAX						)

         @jax.jit
         def eval(**a__						):
           return model(**a__						)

         eval(**a__						).block_until_ready()






     @slow
     def 					__A						(	self						):
       for model_name in ["roberta-base", "roberta-large"]:
         _lowerCAmelCase		: Optional[Any]						    =  AutoTokenizer.from_pretrained(a__						)
         _lowerCAmelCase		: str						    =  FlaxRobertaModel.from_pretrained(a__						)
         _lowerCAmelCase		: List[str]						    =  tokenizer("""Do you support jax jitted function?"""       ,  return_tensors=TensorType.JAX						)

         @jax.jit
         def eval(**a__						):
           return model(**a__						)

         eval(**a__						).block_until_ready()






     def 					__A						(	self						):
       with self.assertRaisesRegex(
           a__       ,  """bert-base is not a local folder and is not a valid model identifier"""						):
         _lowerCAmelCase		: List[str]						    =  FlaxAutoModel.from_pretrained("""bert-base"""						)






     def 					__A						(	self						):
       with self.assertRaisesRegex(
           a__       ,  r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""						):
         _lowerCAmelCase		: Any						    =  FlaxAutoModel.from_pretrained(a__       ,  revision="""aaaaaa"""						)






     def 					__A						(	self						):
       with self.assertRaisesRegex(
           a__       ,  """hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack"""       ,  ):
         _lowerCAmelCase		: int						    =  FlaxAutoModel.from_pretrained("""hf-internal-testing/config-no-model"""						)






     def 					__A						(	self						):
       with self.assertRaisesRegex(a__       ,  """Use `from_pt=True` to load this model"""						):
         _lowerCAmelCase		: int						    =  FlaxAutoModel.from_pretrained("""hf-internal-testing/tiny-bert-pt-only"""						)





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






     def 					__A						(	self						):
       _lowerCAmelCase		: str						    =  torch.nn.Linear(10       ,  10						)
       _lowerCAmelCase		: Optional[Any]						    =  torch.optim.SGD(model.parameters()       ,  0.1						)
       _lowerCAmelCase		: Optional[Any]						    =  Accelerator()
       _lowerCAmelCase		: Tuple						    =  accelerator.prepare(a__						)
       try:
         pickle.loads(pickle.dumps(a__						)						)
       except Exception as e:
         self.fail(F"Accelerated optimizer pickling failed with {e}"						)
       AcceleratorState._reset_state()




