






'''simple docstring'''



from .integrations import (
    is_optuna_available,
    is_ray_available,
    is_sigopt_available,
    is_wandb_available,
    run_hp_search_optuna,
    run_hp_search_ray,
    run_hp_search_sigopt,
    run_hp_search_wandb,
)
from .trainer_utils import (
    HPSearchBackend,
    default_hp_space_optuna,
    default_hp_space_ray,
    default_hp_space_sigopt,
    default_hp_space_wandb,
)
from .utils import logging


SCREAMING_SNAKE_CASE						=	logging.get_logger(__name__)
class UpperCAmelCase_					:




      """simple docstring"""




      UpperCamelCase_								=			42
      UpperCamelCase_								=			None






      @staticmethod
      def 				A__      ( )  ->  List[str]:


       '''simple docstring'''

       raise NotImplementedError






      def 				A__      ( self			:		Any     ,      UpperCAmelCase			:		str     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		str     ,      **UpperCAmelCase			:		int		)  ->  Any:


       '''simple docstring'''

       raise NotImplementedError






      def 				A__      ( self			:		Tuple     ,      UpperCAmelCase			:		Tuple		)  ->  Any:


       '''simple docstring'''

       raise NotImplementedError






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


       '''simple docstring'''

       if not self.is_available():
        raise RuntimeError(
            f'You picked the {self.name} backend, but it is not installed. Run {self.pip_install()}.'		)






      @classmethod
      def 				A__      ( cls			:		Any		)  ->  Dict:


       '''simple docstring'''

       return f'`pip install {cls.pip_package or cls.name}`'





class UpperCAmelCase_					(    __A				):




      """simple docstring"""




      UpperCamelCase_								=			'''optuna'''






      @staticmethod
      def 				A__      ( )  ->  List[Any]:


       '''simple docstring'''

       return is_optuna_available()






      def 				A__      ( self			:		Optional[int]     ,      UpperCAmelCase			:		str     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		str     ,      **UpperCAmelCase			:		List[Any]		)  ->  List[str]:


       '''simple docstring'''

       return run_hp_search_optuna(UpperCAmelCase     ,      UpperCAmelCase     ,      UpperCAmelCase     ,      **UpperCAmelCase		)






      def 				A__      ( self			:		int     ,      UpperCAmelCase			:		Optional[int]		)  ->  int:


       '''simple docstring'''

       return default_hp_space_optuna(UpperCAmelCase		)





class UpperCAmelCase_					(    __A				):




      """simple docstring"""




      UpperCamelCase_								=			'''ray'''
      UpperCamelCase_								=			'''\'ray[tune]\''''






      @staticmethod
      def 				A__      ( )  ->  List[Any]:


       '''simple docstring'''

       return is_ray_available()






      def 				A__      ( self			:		Any     ,      UpperCAmelCase			:		Any     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		str     ,      **UpperCAmelCase			:		str		)  ->  List[Any]:


       '''simple docstring'''

       return run_hp_search_ray(UpperCAmelCase     ,      UpperCAmelCase     ,      UpperCAmelCase     ,      **UpperCAmelCase		)






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


       '''simple docstring'''

       return default_hp_space_ray(UpperCAmelCase		)





class UpperCAmelCase_					(    __A				):




      """simple docstring"""




      UpperCamelCase_								=			'''sigopt'''






      @staticmethod
      def 				A__      ( )  ->  Optional[int]:


       '''simple docstring'''

       return is_sigopt_available()






      def 				A__      ( self			:		Tuple     ,      UpperCAmelCase			:		Union[str, Any]     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		str     ,      **UpperCAmelCase			:		Optional[Any]		)  ->  Tuple:


       '''simple docstring'''

       return run_hp_search_sigopt(UpperCAmelCase     ,      UpperCAmelCase     ,      UpperCAmelCase     ,      **UpperCAmelCase		)






      def 				A__      ( self			:		Union[str, Any]     ,      UpperCAmelCase			:		Dict		)  ->  Optional[Any]:


       '''simple docstring'''

       return default_hp_space_sigopt(UpperCAmelCase		)





class UpperCAmelCase_					(    __A				):




      """simple docstring"""




      UpperCamelCase_								=			'''wandb'''






      @staticmethod
      def 				A__      ( )  ->  List[Any]:


       '''simple docstring'''

       return is_wandb_available()






      def 				A__      ( self			:		Union[str, Any]     ,      UpperCAmelCase			:		List[Any]     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		str     ,      **UpperCAmelCase			:		Optional[Any]		)  ->  Tuple:


       '''simple docstring'''

       return run_hp_search_wandb(UpperCAmelCase     ,      UpperCAmelCase     ,      UpperCAmelCase     ,      **UpperCAmelCase		)






      def 				A__      ( self			:		str     ,      UpperCAmelCase			:		Dict		)  ->  Optional[Any]:


       '''simple docstring'''

       return default_hp_space_wandb(UpperCAmelCase		)





SCREAMING_SNAKE_CASE						=	{
    HPSearchBackend(backend.name): backend for backend in [OptunaBackend, RayTuneBackend, SigOptBackend, WandbBackend]
}


def 							lowercase_				(    )       ->      str:



 """simple docstring"""




 lowercase					:   Optional[int]				  =[backend for backend in ALL_HYPERPARAMETER_SEARCH_BACKENDS.values() if backend.is_available()]
 if len(__A			) > 0:
  lowercase					:   int				  =available_backends[0].name
  if len(__A			) > 1:
   logger.info(
       F'{len(__A			)} hyperparameter search backends available. Using {name} as the default.'			)
  return name
 raise RuntimeError(
     '''No hyperparameter search backend available.\n'''
     + '''\n'''.join(
         F' - To install {backend.name} run {backend.pip_install()}'
         for backend in ALL_HYPERPARAMETER_SEARCH_BACKENDS.values()			)			)











'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


SCREAMING_SNAKE_CASE						=	{
    'configuration_mega': ['MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MegaConfig', 'MegaOnnxConfig'],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      SCREAMING_SNAKE_CASE						=	[
          'MEGA_PRETRAINED_MODEL_ARCHIVE_LIST',
          'MegaForCausalLM',
          'MegaForMaskedLM',
          'MegaForMultipleChoice',
          'MegaForQuestionAnswering',
          'MegaForSequenceClassification',
          'MegaForTokenClassification',
          'MegaModel',
          'MegaPreTrainedModel',
      ]

if TYPE_CHECKING:
      from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_mega import (
                MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
                MegaForCausalLM,
                MegaForMaskedLM,
                MegaForMultipleChoice,
                MegaForQuestionAnswering,
                MegaForSequenceClassification,
                MegaForTokenClassification,
                MegaModel,
                MegaPreTrainedModel,
            )

else:
      import sys

      SCREAMING_SNAKE_CASE						=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



