
"""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   _snake_case       (      self      :							List[str]  )		->Dict:






        '''simple docstring'''






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

                _UpperCAmelCase        = FlaxAutoModel.from_pretrained(__UpperCamelCase  )
                self.assertIsNotNone(__UpperCamelCase  )
                self.assertIsInstance(__UpperCamelCase  ,       __UpperCamelCase  )







    @slow
    def   _snake_case       (      self      :							Union[str, Any]  )		->Union[str, Any]:






        '''simple docstring'''






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

                _UpperCAmelCase        = FlaxAutoModel.from_pretrained(__UpperCamelCase  )
                self.assertIsNotNone(__UpperCamelCase  )
                self.assertIsInstance(__UpperCamelCase  ,       __UpperCamelCase  )







    @slow
    def   _snake_case       (      self      :							Optional[Any]  )		->Tuple:






        '''simple docstring'''






        for model_name in ["bert-base-cased", "bert-large-uncased"]:
            _UpperCAmelCase        = AutoTokenizer.from_pretrained(__UpperCamelCase  )
            _UpperCAmelCase        = FlaxBertModel.from_pretrained(__UpperCamelCase  )
            _UpperCAmelCase        = tokenizer("""Do you support jax jitted function?"""  ,       return_tensors=TensorType.JAX  )

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

            eval(**__UpperCamelCase  ).block_until_ready()







    @slow
    def   _snake_case       (      self      :							Optional[int]  )		->Union[str, Any]:






        '''simple docstring'''






        for model_name in ["roberta-base", "roberta-large"]:
            _UpperCAmelCase        = AutoTokenizer.from_pretrained(__UpperCamelCase  )
            _UpperCAmelCase        = FlaxRobertaModel.from_pretrained(__UpperCamelCase  )
            _UpperCAmelCase        = tokenizer("""Do you support jax jitted function?"""  ,       return_tensors=TensorType.JAX  )

            @jax.jit
            def eval(**__UpperCamelCase      :							Union[str, Any]  ):
                return model(**__UpperCamelCase  )

            eval(**__UpperCamelCase  ).block_until_ready()







    def   _snake_case       (      self      :							Optional[int]  )		->Optional[int]:






        '''simple docstring'''






        with self.assertRaisesRegex(
            __UpperCamelCase  ,       """bert-base is not a local folder and is not a valid model identifier"""  ):
            _UpperCAmelCase        = FlaxAutoModel.from_pretrained("""bert-base"""  )







    def   _snake_case       (      self      :							Tuple  )		->Optional[Any]:






        '''simple docstring'''






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







    def   _snake_case       (      self      :							Dict  )		->str:






        '''simple docstring'''






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







    def   _snake_case       (      self      :							Dict  )		->List[Any]:






        '''simple docstring'''






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

"""simple docstring"""



import importlib
import os
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional, Union

import torch

from ..utils import BaseOutput


a       :						int       		=		'''scheduler_config.json'''




class 		a_    (			_UpperCAmelCase						):
    a   :					List[Any]			     =					1
    a   :					Tuple			     =					2
    a   :					Dict			     =					3
    a   :					str			     =					4
    a   :					Optional[int]			     =					5
    a   :					Any			     =					6
    a   :					int			     =					7
    a   :					Any			     =					8
    a   :					List[Any]			     =					9
    a   :					Any			     =					10
    a   :					List[str]			     =					11
    a   :					Optional[int]			     =					12
    a   :					Any			     =					13
    a   :					Dict			     =					14







@dataclass
class 		a_    (			_UpperCAmelCase						):
    a   :					torch.FloatTensor







class 		a_    :
    a   :					Dict			     =					SCHEDULER_CONFIG_NAME
    a   :					List[str]			     =					[]
    a   :					Optional[int]			     =					True







    @classmethod
    def   _snake_case       (      cls      :							List[str]  ,       __UpperCamelCase      :							Dict[str, Any] = None  ,       __UpperCamelCase      :							Optional[str] = None  ,       __UpperCamelCase      :							List[str]=False  ,       **__UpperCamelCase      :							int  ,       )		->Dict:






        '''simple docstring'''






        _UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase        = cls.load_config(
            pretrained_model_name_or_path=__UpperCamelCase  ,       subfolder=__UpperCamelCase  ,       return_unused_kwargs=__UpperCamelCase  ,       return_commit_hash=__UpperCamelCase  ,       **__UpperCamelCase  ,       )
        return cls.from_config(__UpperCamelCase  ,       return_unused_kwargs=__UpperCamelCase  ,       **__UpperCamelCase  )







    def   _snake_case       (      self      :							Tuple  ,       __UpperCamelCase      :							Union[str, os.PathLike]  ,       __UpperCamelCase      :							bool = False  ,       **__UpperCamelCase      :							List[str]  )		->Any:






        '''simple docstring'''






        self.save_config(save_directory=__UpperCamelCase  ,       push_to_hub=__UpperCamelCase  ,       **__UpperCamelCase  )







    @property
    def   _snake_case       (      self      :							Optional[int]  )		->List[Any]:






        '''simple docstring'''






        return self._get_compatibles()







    @classmethod
    def   _snake_case       (      cls      :							List[str]  )		->Dict:






        '''simple docstring'''






        _UpperCAmelCase        = list(set([cls.__name__] + cls._compatibles  )  )
        _UpperCAmelCase        = importlib.import_module(__name__.split("""."""  )[0]  )
        _UpperCAmelCase        = [
            getattr(__UpperCamelCase  ,       __UpperCamelCase  ) for c in compatible_classes_str if hasattr(__UpperCamelCase  ,       __UpperCamelCase  )
        ]
        return compatible_classes