

import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
			import jax.numpy as jnp

if is_tf_available():
			import tensorflow as tf

if is_torch_available():
			import torch






class _UpperCamelCase							(							unittest.TestCase      ):
			'''simple docstring'''







			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					str    =				{
				    "task_specific_params": {
				        "summarization": {"length_penalty": 1.0, "max_length": 128, "min_length": 12, "num_beams": 4},
				        "summarization_cnn": {"length_penalty": 2.0, "max_length": 142, "min_length": 56, "num_beams": 4},
				        "summarization_xsum": {"length_penalty": 1.0, "max_length": 62, "min_length": 11, "num_beams": 6},
				    }
				}
				SCREAMING_SNAKE_CASE      :					List[str]    =				{
				    "task_specific_params.summarization.length_penalty": 1.0,
				    "task_specific_params.summarization.max_length": 128,
				    "task_specific_params.summarization.min_length": 12,
				    "task_specific_params.summarization.num_beams": 4,
				    "task_specific_params.summarization_cnn.length_penalty": 2.0,
				    "task_specific_params.summarization_cnn.max_length": 142,
				    "task_specific_params.summarization_cnn.min_length": 56,
				    "task_specific_params.summarization_cnn.num_beams": 4,
				    "task_specific_params.summarization_xsum.length_penalty": 1.0,
				    "task_specific_params.summarization_xsum.max_length": 62,
				    "task_specific_params.summarization_xsum.min_length": 11,
				    "task_specific_params.summarization_xsum.num_beams": 6,
				}

				self.assertEqual(flatten_dict(__UpperCAmelCase		)					,					__UpperCAmelCase		)
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Dict    =				np.random.randn(3					,					4		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase		)					,					x.transpose()		)		)

				SCREAMING_SNAKE_CASE      :					str    =				np.random.randn(3					,					4					,					5		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		)					,					x.transpose((1, 2, 0)		)		)		)
			@require_torch
			def 							__UpperCamelCase       (	self							:       Tuple		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase		)					,					transpose(__UpperCAmelCase		).numpy()		)		)

				SCREAMING_SNAKE_CASE      :					Tuple    =				np.random.randn(3					,					4					,					5		)
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		)					,					transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		).numpy()		)		)
			@require_tf
			def 							__UpperCamelCase       (	self							:       List[str]		)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					int    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase		)					,					transpose(__UpperCAmelCase		).numpy()		)		)

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				np.random.randn(3					,					4					,					5		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		)					,					transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		).numpy()		)		)
			@require_flax
			def 							__UpperCamelCase       (	self							:       str		)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Dict    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase		)					,					np.asarray(transpose(__UpperCAmelCase		)		)		)		)

				SCREAMING_SNAKE_CASE      :					str    =				np.random.randn(3					,					4					,					5		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		)					,					np.asarray(transpose(__UpperCAmelCase					,					axes=(1, 2, 0)		)		)		)		)
			def 							__UpperCamelCase       (	self							:       Optional[int]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.random.randn(3					,					4		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(4, 3)		)					,					np.reshape(__UpperCAmelCase					,					(4, 3)		)		)		)

				SCREAMING_SNAKE_CASE      :					Dict    =				np.random.randn(3					,					4					,					5		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(12, 5)		)					,					np.reshape(__UpperCAmelCase					,					(12, 5)		)		)		)
			@require_torch
			def 							__UpperCamelCase       (	self							:       Tuple		)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[Any]    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(4, 3)		)					,					reshape(__UpperCAmelCase					,					(4, 3)		).numpy()		)		)

				SCREAMING_SNAKE_CASE      :					List[str]    =				np.random.randn(3					,					4					,					5		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(12, 5)		)					,					reshape(__UpperCAmelCase					,					(12, 5)		).numpy()		)		)
			@require_tf
			def 							__UpperCamelCase       (	self							:       Optional[int]		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[Any]    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Dict    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(4, 3)		)					,					reshape(__UpperCAmelCase					,					(4, 3)		).numpy()		)		)

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.random.randn(3					,					4					,					5		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(12, 5)		)					,					reshape(__UpperCAmelCase					,					(12, 5)		).numpy()		)		)
			@require_flax
			def 							__UpperCamelCase       (	self							:       Union[str, Any]		)							->				Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Any    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(4, 3)		)					,					np.asarray(reshape(__UpperCAmelCase					,					(4, 3)		)		)		)		)

				SCREAMING_SNAKE_CASE      :					List[str]    =				np.random.randn(3					,					4					,					5		)
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(reshape(__UpperCAmelCase					,					(12, 5)		)					,					np.asarray(reshape(__UpperCAmelCase					,					(12, 5)		)		)		)		)
			def 							__UpperCamelCase       (	self							:       Optional[int]		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				np.random.randn(1					,					3					,					4		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase		)					,					np.squeeze(__UpperCAmelCase		)		)		)

				SCREAMING_SNAKE_CASE      :					List[str]    =				np.random.randn(1					,					4					,					1					,					5		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase					,					axis=2		)					,					np.squeeze(__UpperCAmelCase					,					axis=2		)		)		)
			@require_torch
			def 							__UpperCamelCase       (	self							:       Tuple		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Dict    =				np.random.randn(1					,					3					,					4		)
				SCREAMING_SNAKE_CASE      :					Any    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase		)					,					squeeze(__UpperCAmelCase		).numpy()		)		)

				SCREAMING_SNAKE_CASE      :					Any    =				np.random.randn(1					,					4					,					1					,					5		)
				SCREAMING_SNAKE_CASE      :					str    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase					,					axis=2		)					,					squeeze(__UpperCAmelCase					,					axis=2		).numpy()		)		)
			@require_tf
			def 							__UpperCamelCase       (	self							:       Tuple		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					int    =				np.random.randn(1					,					3					,					4		)
				SCREAMING_SNAKE_CASE      :					List[str]    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase		)					,					squeeze(__UpperCAmelCase		).numpy()		)		)

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.random.randn(1					,					4					,					1					,					5		)
				SCREAMING_SNAKE_CASE      :					int    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase					,					axis=2		)					,					squeeze(__UpperCAmelCase					,					axis=2		).numpy()		)		)
			@require_flax
			def 							__UpperCamelCase       (	self							:       Dict		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				np.random.randn(1					,					3					,					4		)
				SCREAMING_SNAKE_CASE      :					List[Any]    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase		)					,					np.asarray(squeeze(__UpperCAmelCase		)		)		)		)

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				np.random.randn(1					,					4					,					1					,					5		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(squeeze(__UpperCAmelCase					,					axis=2		)					,					np.asarray(squeeze(__UpperCAmelCase					,					axis=2		)		)		)		)
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				np.random.randn(3					,					4		)
				self.assertTrue(np.allclose(expand_dims(__UpperCAmelCase					,					axis=1		)					,					np.expand_dims(__UpperCAmelCase					,					axis=1		)		)		)
			@require_torch
			def 							__UpperCamelCase       (	self							:       Optional[Any]		)							->				int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Any    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				torch.tensor(__UpperCAmelCase		)
				self.assertTrue(np.allclose(expand_dims(__UpperCAmelCase					,					axis=1		)					,					expand_dims(__UpperCAmelCase					,					axis=1		).numpy()		)		)
			@require_tf
			def 							__UpperCamelCase       (	self							:       str		)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					int    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					int    =				tf.constant(__UpperCAmelCase		)
				self.assertTrue(np.allclose(expand_dims(__UpperCAmelCase					,					axis=1		)					,					expand_dims(__UpperCAmelCase					,					axis=1		).numpy()		)		)






			@require_flax
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				np.random.randn(3					,					4		)
				SCREAMING_SNAKE_CASE      :					Any    =				jnp.array(__UpperCAmelCase		)
				self.assertTrue(np.allclose(expand_dims(__UpperCAmelCase					,					axis=1		)					,					np.asarray(expand_dims(__UpperCAmelCase					,					axis=1		)		)		)		)



"""simple docstring"""







from typing import TYPE_CHECKING

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


__lowercase    					=      {
    """configuration_bert""": ["""BERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """BertConfig""", """BertOnnxConfig"""],
    """tokenization_bert""": ["""BasicTokenizer""", """BertTokenizer""", """WordpieceTokenizer"""],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowercase    					=      ["""BertTokenizerFast"""]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowercase    					=      [
     """BERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """BertForMaskedLM""",
     """BertForMultipleChoice""",
     """BertForNextSentencePrediction""",
     """BertForPreTraining""",
     """BertForQuestionAnswering""",
     """BertForSequenceClassification""",
     """BertForTokenClassification""",
     """BertLayer""",
     """BertLMHeadModel""",
     """BertModel""",
     """BertPreTrainedModel""",
     """load_tf_weights_in_bert""",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowercase    					=      [
     """TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """TFBertEmbeddings""",
     """TFBertForMaskedLM""",
     """TFBertForMultipleChoice""",
     """TFBertForNextSentencePrediction""",
     """TFBertForPreTraining""",
     """TFBertForQuestionAnswering""",
     """TFBertForSequenceClassification""",
     """TFBertForTokenClassification""",
     """TFBertLMHeadModel""",
     """TFBertMainLayer""",
     """TFBertModel""",
     """TFBertPreTrainedModel""",
 ]
try:
 if not is_tensorflow_text_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowercase    					=      ["""TFBertTokenizer"""]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowercase    					=      [
     """FlaxBertForCausalLM""",
     """FlaxBertForMaskedLM""",
     """FlaxBertForMultipleChoice""",
     """FlaxBertForNextSentencePrediction""",
     """FlaxBertForPreTraining""",
     """FlaxBertForQuestionAnswering""",
     """FlaxBertForSequenceClassification""",
     """FlaxBertForTokenClassification""",
     """FlaxBertModel""",
     """FlaxBertPreTrainedModel""",
 ]

if TYPE_CHECKING:
 from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig
 from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_bert_fast import BertTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_bert import (
      BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      BertForMaskedLM,
      BertForMultipleChoice,
      BertForNextSentencePrediction,
      BertForPreTraining,
      BertForQuestionAnswering,
      BertForSequenceClassification,
      BertForTokenClassification,
      BertLayer,
      BertLMHeadModel,
      BertModel,
      BertPreTrainedModel,
      load_tf_weights_in_bert,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_bert import (
      TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFBertEmbeddings,
      TFBertForMaskedLM,
      TFBertForMultipleChoice,
      TFBertForNextSentencePrediction,
      TFBertForPreTraining,
      TFBertForQuestionAnswering,
      TFBertForSequenceClassification,
      TFBertForTokenClassification,
      TFBertLMHeadModel,
      TFBertMainLayer,
      TFBertModel,
      TFBertPreTrainedModel,
  )

 try:
  if not is_tensorflow_text_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_bert_tf import TFBertTokenizer

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_bert import (
      FlaxBertForCausalLM,
      FlaxBertForMaskedLM,
      FlaxBertForMultipleChoice,
      FlaxBertForNextSentencePrediction,
      FlaxBertForPreTraining,
      FlaxBertForQuestionAnswering,
      FlaxBertForSequenceClassification,
      FlaxBertForTokenClassification,
      FlaxBertModel,
      FlaxBertPreTrainedModel,
  )

else:
 import sys

 __lowercase    					=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






