






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
		import torch

		from transformers.activations import gelu_new, gelu_python, get_activation

@require_torch
class 		__a				(    unittest.TestCase      ):
		def      UpperCAmelCase__    (      self						)			->	Any:




									"""simple docstring"""





									_UpperCAmelCase					=      torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]						)
									_UpperCAmelCase					=      get_activation('gelu'						)
									self.assertTrue(torch.allclose(gelu_python(_SCREAMING_SNAKE_CASE						)      ,   torch_builtin(_SCREAMING_SNAKE_CASE						)						)						)
									self.assertFalse(torch.allclose(gelu_python(_SCREAMING_SNAKE_CASE						)      ,   gelu_new(_SCREAMING_SNAKE_CASE						)						)						)
		def      UpperCAmelCase__    (      self						)			->	Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=      torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]						)
									_UpperCAmelCase					=      get_activation('gelu'						)
									_UpperCAmelCase					=      get_activation('gelu_10'						)

									_UpperCAmelCase					=      torch_builtin(_SCREAMING_SNAKE_CASE						)
									_UpperCAmelCase					=      geluaa(_SCREAMING_SNAKE_CASE						)

									_UpperCAmelCase					=      torch.where(y_gelu_aa < 10.0      ,   1      ,   0						)

									self.assertTrue(torch.max(_SCREAMING_SNAKE_CASE						).item() == 10.0						)
									self.assertTrue(torch.allclose(y_gelu * clipped_mask      ,   y_gelu_aa * clipped_mask						)						)
		def      UpperCAmelCase__    (      self						)			->	Optional[Any]:




									"""simple docstring"""





									get_activation('gelu'						)
									get_activation('gelu_10'						)
									get_activation('gelu_fast'						)
									get_activation('gelu_new'						)
									get_activation('gelu_python'						)
									get_activation('gelu_pytorch_tanh'						)
									get_activation('linear'						)
									get_activation('mish'						)
									get_activation('quick_gelu'						)
									get_activation('relu'						)
									get_activation('sigmoid'						)
									get_activation('silu'						)
									get_activation('swish'						)
									get_activation('tanh'						)
									with self.assertRaises(_SCREAMING_SNAKE_CASE						):
																get_activation('bogus'						)
									with self.assertRaises(_SCREAMING_SNAKE_CASE						):
																get_activation(_SCREAMING_SNAKE_CASE						)






		def      UpperCAmelCase__    (      self						)			->	Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=      get_activation('gelu'						)
									_UpperCAmelCase					=      1
									_UpperCAmelCase					=      get_activation('gelu'						)
									self.assertEqual(acta.a      ,   1						)
									with self.assertRaises(_SCREAMING_SNAKE_CASE						):
																_UpperCAmelCase					=      acta.a




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase__  :Any             =							{'''configuration_xglm''': ['''XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XGLMConfig''']}

try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__  :Optional[Any]             =							['''XGLMTokenizer''']

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__  :str             =							['''XGLMTokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__  :List[str]             =							[
		    '''XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''XGLMForCausalLM''',
		    '''XGLMModel''',
		    '''XGLMPreTrainedModel''',
		]


try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__  :str             =							[
		    '''FlaxXGLMForCausalLM''',
		    '''FlaxXGLMModel''',
		    '''FlaxXGLMPreTrainedModel''',
		]


try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__  :List[Any]             =							[
		    '''TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFXGLMForCausalLM''',
		    '''TFXGLMModel''',
		    '''TFXGLMPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_xglm import XGLMTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_xglm_fast import XGLMTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_xglm import (
				    TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFXGLMForCausalLM,
				    TFXGLMModel,
				    TFXGLMPreTrainedModel,
				)


else:
		import sys

		lowerCAmelCase__  :Any             =							_LazyModule(__name__, globals()['''__file__'''], _import_structure)
