


"""simple docstring"""







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 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    def 	__snake_case							(					self				:    List[Any]):
      a						:		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},
          }
      }
      a						:		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 	__snake_case							(					self				:    List[Any]):
      a						:		Dict      							=			np.random.randn(3				, 4)
      self.assertTrue(np.allclose(transpose(__UpperCAmelCase)				, x.transpose()))

      a						:		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 	__snake_case							(					self				:    Tuple):
      a						:		Union[str, Any]      							=			np.random.randn(3				, 4)
      a						:		Union[str, Any]      							=			torch.tensor(__UpperCAmelCase)
      self.assertTrue(np.allclose(transpose(__UpperCAmelCase)				, transpose(__UpperCAmelCase).numpy()))

      a						:		Tuple      							=			np.random.randn(3				, 4				, 5)
      a						:		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 	__snake_case							(					self				:    List[str]):
      a						:		int      							=			np.random.randn(3				, 4)
      a						:		Optional[int]      							=			tf.constant(__UpperCAmelCase)
      self.assertTrue(np.allclose(transpose(__UpperCAmelCase)				, transpose(__UpperCAmelCase).numpy()))

      a						:		Optional[Any]      							=			np.random.randn(3				, 4				, 5)
      a						:		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 	__snake_case							(					self				:    str):
      a						:		Union[str, Any]      							=			np.random.randn(3				, 4)
      a						:		Dict      							=			jnp.array(__UpperCAmelCase)
      self.assertTrue(np.allclose(transpose(__UpperCAmelCase)				, np.asarray(transpose(__UpperCAmelCase))))

      a						:		str      							=			np.random.randn(3				, 4				, 5)
      a						:		List[str]      							=			jnp.array(__UpperCAmelCase)
      self.assertTrue(np.allclose(transpose(__UpperCAmelCase				, axes=(1, 2, 0))				, np.asarray(transpose(__UpperCAmelCase				, axes=(1, 2, 0)))))






    def 	__snake_case							(					self				:    Optional[int]):
      a						:		Union[str, Any]      							=			np.random.randn(3				, 4)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (4, 3))				, np.reshape(__UpperCAmelCase				, (4, 3))))

      a						:		Dict      							=			np.random.randn(3				, 4				, 5)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (12, 5))				, np.reshape(__UpperCAmelCase				, (12, 5))))






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

      a						:		List[str]      							=			np.random.randn(3				, 4				, 5)
      a						:		Union[str, Any]      							=			torch.tensor(__UpperCAmelCase)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (12, 5))				, reshape(__UpperCAmelCase				, (12, 5)).numpy()))






    @require_tf
    def 	__snake_case							(					self				:    Optional[int]):
      a						:		List[Any]      							=			np.random.randn(3				, 4)
      a						:		Dict      							=			tf.constant(__UpperCAmelCase)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (4, 3))				, reshape(__UpperCAmelCase				, (4, 3)).numpy()))

      a						:		Union[str, Any]      							=			np.random.randn(3				, 4				, 5)
      a						:		Union[str, Any]      							=			tf.constant(__UpperCAmelCase)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (12, 5))				, reshape(__UpperCAmelCase				, (12, 5)).numpy()))






    @require_flax
    def 	__snake_case							(					self				:    Union[str, Any]):
      a						:		Optional[Any]      							=			np.random.randn(3				, 4)
      a						:		Any      							=			jnp.array(__UpperCAmelCase)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (4, 3))				, np.asarray(reshape(__UpperCAmelCase				, (4, 3)))))

      a						:		List[str]      							=			np.random.randn(3				, 4				, 5)
      a						:		Union[str, Any]      							=			jnp.array(__UpperCAmelCase)
      self.assertTrue(np.allclose(reshape(__UpperCAmelCase				, (12, 5))				, np.asarray(reshape(__UpperCAmelCase				, (12, 5)))))






    def 	__snake_case							(					self				:    Optional[int]):
      a						:		Tuple      							=			np.random.randn(1				, 3				, 4)
      self.assertTrue(np.allclose(squeeze(__UpperCAmelCase)				, np.squeeze(__UpperCAmelCase)))

      a						:		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 	__snake_case							(					self				:    Tuple):
      a						:		Dict      							=			np.random.randn(1				, 3				, 4)
      a						:		Any      							=			torch.tensor(__UpperCAmelCase)
      self.assertTrue(np.allclose(squeeze(__UpperCAmelCase)				, squeeze(__UpperCAmelCase).numpy()))

      a						:		Any      							=			np.random.randn(1				, 4				, 1				, 5)
      a						:		str      							=			torch.tensor(__UpperCAmelCase)
      self.assertTrue(np.allclose(squeeze(__UpperCAmelCase				, axis=2)				, squeeze(__UpperCAmelCase				, axis=2).numpy()))






    @require_tf
    def 	__snake_case							(					self				:    Tuple):
      a						:		int      							=			np.random.randn(1				, 3				, 4)
      a						:		List[str]      							=			tf.constant(__UpperCAmelCase)
      self.assertTrue(np.allclose(squeeze(__UpperCAmelCase)				, squeeze(__UpperCAmelCase).numpy()))

      a						:		Union[str, Any]      							=			np.random.randn(1				, 4				, 1				, 5)
      a						:		int      							=			tf.constant(__UpperCAmelCase)
      self.assertTrue(np.allclose(squeeze(__UpperCAmelCase				, axis=2)				, squeeze(__UpperCAmelCase				, axis=2).numpy()))






    @require_flax
    def 	__snake_case							(					self				:    Dict):
      a						:		Tuple      							=			np.random.randn(1				, 3				, 4)
      a						:		List[Any]      							=			jnp.array(__UpperCAmelCase)
      self.assertTrue(np.allclose(squeeze(__UpperCAmelCase)				, np.asarray(squeeze(__UpperCAmelCase))))

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






    def 	__snake_case							(					self				:    List[Any]):
      a						:		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 	__snake_case							(					self				:    Optional[Any]):
      a						:		Any      							=			np.random.randn(3				, 4)
      a						:		Optional[Any]      							=			torch.tensor(__UpperCAmelCase)
      self.assertTrue(np.allclose(expand_dims(__UpperCAmelCase				, axis=1)				, expand_dims(__UpperCAmelCase				, axis=1).numpy()))






    @require_tf
    def 	__snake_case							(					self				:    str):
      a						:		int      							=			np.random.randn(3				, 4)
      a						:		int      							=			tf.constant(__UpperCAmelCase)
      self.assertTrue(np.allclose(expand_dims(__UpperCAmelCase				, axis=1)				, expand_dims(__UpperCAmelCase				, axis=1).numpy()))






    @require_flax
    def 	__snake_case							(					self				:    List[Any]):
      a						:		Optional[int]      							=			np.random.randn(3				, 4)
      a						:		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__)






