

'''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  UpperCAmelCase    (				self					):





        """simple docstring"""







        for model_name in ["bert-base-cased", "bert-large-uncased"]:
              with self.subTest(_SCREAMING_SNAKE_CASE					):
                    SCREAMING_SNAKE_CASE_				:  List[Any]           =     AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE					)
                    self.assertIsNotNone(_SCREAMING_SNAKE_CASE					)
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

                    SCREAMING_SNAKE_CASE_				:  List[str]           =     FlaxAutoModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
                    self.assertIsNotNone(_SCREAMING_SNAKE_CASE					)
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

  @slow
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        for model_name in ["roberta-base", "roberta-large"]:
              with self.subTest(_SCREAMING_SNAKE_CASE					):
                    SCREAMING_SNAKE_CASE_				:  str           =     AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE					)
                    self.assertIsNotNone(_SCREAMING_SNAKE_CASE					)
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

                    SCREAMING_SNAKE_CASE_				:  str           =     FlaxAutoModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
                    self.assertIsNotNone(_SCREAMING_SNAKE_CASE					)
                    self.assertIsInstance(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

  @slow
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        for model_name in ["bert-base-cased", "bert-large-uncased"]:
              SCREAMING_SNAKE_CASE_				:  List[str]           =     AutoTokenizer.from_pretrained(_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  int           =     FlaxBertModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     tokenizer('Do you support jax jitted function?' ,					return_tensors=TensorType.JAX					)

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

              eval(**_SCREAMING_SNAKE_CASE					).block_until_ready()

  @slow
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        for model_name in ["roberta-base", "roberta-large"]:
              SCREAMING_SNAKE_CASE_				:  int           =     AutoTokenizer.from_pretrained(_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  Any           =     FlaxRobertaModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     tokenizer('Do you support jax jitted function?' ,					return_tensors=TensorType.JAX					)

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

              eval(**_SCREAMING_SNAKE_CASE					).block_until_ready()

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with self.assertRaisesRegex(
            _SCREAMING_SNAKE_CASE ,					'bert-base is not a local folder and is not a valid model identifier'					):
              SCREAMING_SNAKE_CASE_				:  Any           =     FlaxAutoModel.from_pretrained('bert-base'					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with self.assertRaisesRegex(
            _SCREAMING_SNAKE_CASE ,					r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'					):
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     FlaxAutoModel.from_pretrained(_SCREAMING_SNAKE_CASE ,					revision='aaaaaa'					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with self.assertRaisesRegex(
            _SCREAMING_SNAKE_CASE ,					'hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack' ,					):
              SCREAMING_SNAKE_CASE_				:  Any           =     FlaxAutoModel.from_pretrained('hf-internal-testing/config-no-model'					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with self.assertRaisesRegex(_SCREAMING_SNAKE_CASE ,					'Use `from_pt=True` to load this model'					):
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     FlaxAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only'					)









def    A_  (							a					,   a  ):

      """simple docstring"""



      return numa ^ numa < 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()






