



"""simple docstring"""





from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import tensorflow as tf

     from transformers import (
         TFConvBertForMaskedLM,
         TFConvBertForMultipleChoice,
         TFConvBertForQuestionAnswering,
         TFConvBertForSequenceClassification,
         TFConvBertForTokenClassification,
         TFConvBertModel,
     )




class 			lowercase__			:
       '''simple docstring'''







       def __init__(  self	,       snake_case	,       snake_case=13	,       snake_case=7	,       snake_case=True	,       snake_case=True	,       snake_case=True	,       snake_case=True	,       snake_case=99	,       snake_case=32	,       snake_case=2	,       snake_case=4	,       snake_case=37	,       snake_case="gelu"	,       snake_case=0.1	,       snake_case=0.1	,       snake_case=512	,       snake_case=16	,       snake_case=2	,       snake_case=0.02	,       snake_case=3	,       snake_case=4	,       snake_case=None	,       )			->							Dict:
         _UpperCAmelCase							 =		parent
         _UpperCAmelCase							 =		13
         _UpperCAmelCase							 =		7
         _UpperCAmelCase							 =		True
         _UpperCAmelCase							 =		True
         _UpperCAmelCase							 =		True
         _UpperCAmelCase							 =		True
         _UpperCAmelCase							 =		99
         _UpperCAmelCase							 =		384
         _UpperCAmelCase							 =		2
         _UpperCAmelCase							 =		4
         _UpperCAmelCase							 =		37
         _UpperCAmelCase							 =		'gelu'
         _UpperCAmelCase							 =		0.1
         _UpperCAmelCase							 =		0.1
         _UpperCAmelCase							 =		512
         _UpperCAmelCase							 =		16
         _UpperCAmelCase							 =		2
         _UpperCAmelCase							 =		0.02
         _UpperCAmelCase							 =		3
         _UpperCAmelCase							 =		4
         _UpperCAmelCase							 =		128
         _UpperCAmelCase							 =		2
         _UpperCAmelCase							 =		9
         _UpperCAmelCase							 =		1
         _UpperCAmelCase							 =		None






       def        lowerCamelCase_   (  self						)			->							List[str]:
         _UpperCAmelCase							 =		ids_tensor([self.batch_size, self.seq_length]	,       self.vocab_size						)

         _UpperCAmelCase							 =		None
         if self.use_input_mask:
           _UpperCAmelCase							 =		random_attention_mask([self.batch_size, self.seq_length]						)

         _UpperCAmelCase							 =		None
         if self.use_token_type_ids:
           _UpperCAmelCase							 =		ids_tensor([self.batch_size, self.seq_length]	,       self.type_vocab_size						)

         _UpperCAmelCase							 =		None
         _UpperCAmelCase							 =		None
         _UpperCAmelCase							 =		None
         if self.use_labels:
           _UpperCAmelCase							 =		ids_tensor([self.batch_size]	,       self.type_sequence_label_size						)
           _UpperCAmelCase							 =		ids_tensor([self.batch_size, self.seq_length]	,       self.num_labels						)
           _UpperCAmelCase							 =		ids_tensor([self.batch_size]	,       self.num_choices						)

         _UpperCAmelCase							 =		ConvBertConfig(
             vocab_size=self.vocab_size	,       hidden_size=self.hidden_size	,       num_hidden_layers=self.num_hidden_layers	,       num_attention_heads=self.num_attention_heads	,       intermediate_size=self.intermediate_size	,       hidden_act=self.hidden_act	,       hidden_dropout_prob=self.hidden_dropout_prob	,       attention_probs_dropout_prob=self.attention_probs_dropout_prob	,       max_position_embeddings=self.max_position_embeddings	,       type_vocab_size=self.type_vocab_size	,       initializer_range=self.initializer_range	,       return_dict=snake_case	,       )

         return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






       def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case						)			->							Any:
         _UpperCAmelCase							 =		TFConvBertModel(config=snake_case						)
         _UpperCAmelCase							 =		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

         _UpperCAmelCase							 =		[input_ids, input_mask]
         _UpperCAmelCase							 =		model(snake_case						)

         _UpperCAmelCase							 =		model(snake_case						)

         self.parent.assertEqual(result.last_hidden_state.shape	,       (self.batch_size, self.seq_length, self.hidden_size)						)






       def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case						)			->							List[str]:
         _UpperCAmelCase							 =		TFConvBertForMaskedLM(config=snake_case						)
         _UpperCAmelCase							 =		{
             'input_ids': input_ids,
             'attention_mask': input_mask,
             'token_type_ids': token_type_ids,
         }
         _UpperCAmelCase							 =		model(snake_case						)
         self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.seq_length, self.vocab_size)						)






       def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case						)			->							str:
         _UpperCAmelCase							 =		self.num_labels
         _UpperCAmelCase							 =		TFConvBertForSequenceClassification(config=snake_case						)
         _UpperCAmelCase							 =		{
             'input_ids': input_ids,
             'attention_mask': input_mask,
             'token_type_ids': token_type_ids,
         }

         _UpperCAmelCase							 =		model(snake_case						)
         self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.num_labels)						)






       def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case						)			->							int:
         _UpperCAmelCase							 =		self.num_choices
         _UpperCAmelCase							 =		TFConvBertForMultipleChoice(config=snake_case						)
         _UpperCAmelCase							 =		tf.tile(tf.expand_dims(snake_case	,       1						)	,       (1, self.num_choices, 1)						)
         _UpperCAmelCase							 =		tf.tile(tf.expand_dims(snake_case	,       1						)	,       (1, self.num_choices, 1)						)
         _UpperCAmelCase							 =		tf.tile(tf.expand_dims(snake_case	,       1						)	,       (1, self.num_choices, 1)						)
         _UpperCAmelCase							 =		{
             'input_ids': multiple_choice_inputs_ids,
             'attention_mask': multiple_choice_input_mask,
             'token_type_ids': multiple_choice_token_type_ids,
         }
         _UpperCAmelCase							 =		model(snake_case						)
         self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.num_choices)						)






       def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case						)			->							List[Any]:
         _UpperCAmelCase							 =		self.num_labels
         _UpperCAmelCase							 =		TFConvBertForTokenClassification(config=snake_case						)
         _UpperCAmelCase							 =		{
             'input_ids': input_ids,
             'attention_mask': input_mask,
             'token_type_ids': token_type_ids,
         }
         _UpperCAmelCase							 =		model(snake_case						)
         self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.seq_length, self.num_labels)						)






       def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case	,       snake_case						)			->							Optional[int]:
         _UpperCAmelCase							 =		TFConvBertForQuestionAnswering(config=snake_case						)
         _UpperCAmelCase							 =		{
             'input_ids': input_ids,
             'attention_mask': input_mask,
             'token_type_ids': token_type_ids,
         }

         _UpperCAmelCase							 =		model(snake_case						)
         self.parent.assertEqual(result.start_logits.shape	,       (self.batch_size, self.seq_length)						)
         self.parent.assertEqual(result.end_logits.shape	,       (self.batch_size, self.seq_length)						)






       def        lowerCamelCase_   (  self						)			->							Dict:
         _UpperCAmelCase							 =		self.prepare_config_and_inputs()
         (
             (
             _UpperCAmelCase					
         ) ,					(
             _UpperCAmelCase					
         ) ,					(
             _UpperCAmelCase					
         ) ,					(
             _UpperCAmelCase					
         ) ,					(
             _UpperCAmelCase					
         ) ,					(
             _UpperCAmelCase					
         ) ,					(
             _UpperCAmelCase					
         ) ,										
         )							 =		config_and_inputs
         _UpperCAmelCase							 =		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict







@require_tf
class 			lowercase__			(      A,					A,					unittest.TestCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					(
           (
               TFConvBertModel,
               TFConvBertForMaskedLM,
               TFConvBertForQuestionAnswering,
               TFConvBertForSequenceClassification,
               TFConvBertForTokenClassification,
               TFConvBertForMultipleChoice,
           )
           if is_tf_available()
           else ()
       )
       _UpperCAmelCase      				=					(
           {
               '''feature-extraction''': TFConvBertModel,
               '''fill-mask''': TFConvBertForMaskedLM,
               '''question-answering''': TFConvBertForQuestionAnswering,
               '''text-classification''': TFConvBertForSequenceClassification,
               '''token-classification''': TFConvBertForTokenClassification,
               '''zero-shot''': TFConvBertForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       _UpperCAmelCase      				=					False
       _UpperCAmelCase      				=					False
       _UpperCAmelCase      				=					False






       def        lowerCamelCase_   (  self						)			->							Dict:
         _UpperCAmelCase							 =		TFConvBertModelTester(self						)
         _UpperCAmelCase							 =		ConfigTester(self	,       config_class=snake_case	,       hidden_size=37						)






       def        lowerCamelCase_   (  self						)			->							int:
         self.config_tester.run_common_tests()






       def        lowerCamelCase_   (  self						)			->							List[Any]:
         _UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case						)






       def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
         _UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*snake_case						)






       def        lowerCamelCase_   (  self						)			->							Dict:
         _UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*snake_case						)






       def        lowerCamelCase_   (  self						)			->							Dict:
         _UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*snake_case						)






       def        lowerCamelCase_   (  self						)			->							Optional[Any]:
         _UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*snake_case						)






       def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
         _UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*snake_case						)






       @slow
       def        lowerCamelCase_   (  self						)			->							Tuple:
         _UpperCAmelCase ,					_UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs_for_common()
         _UpperCAmelCase							 =		True
         _UpperCAmelCase							 =		True

         if hasattr(snake_case	,       'use_cache'						):
           _UpperCAmelCase							 =		True

         _UpperCAmelCase							 =		getattr(self.model_tester	,       'encoder_seq_length'	,       self.model_tester.seq_length						)
         _UpperCAmelCase							 =		getattr(self.model_tester	,       'key_length'	,       snake_case						)

         for model_class in self.all_model_classes:
           _UpperCAmelCase							 =		self._prepare_for_class(snake_case	,       snake_case						)
           _UpperCAmelCase							 =		model_class(snake_case						)
           _UpperCAmelCase							 =		len(model(snake_case						)						)

           with tempfile.TemporaryDirectory() as tmpdirname:
             model.save_pretrained(snake_case	,       saved_model=snake_case						)
             _UpperCAmelCase							 =		os.path.join(snake_case	,       'saved_model'	,       '1'						)
             _UpperCAmelCase							 =		tf.keras.models.load_model(snake_case						)
             _UpperCAmelCase							 =		model(snake_case						)

             if self.is_encoder_decoder:
               _UpperCAmelCase							 =		outputs['encoder_hidden_states']
               _UpperCAmelCase							 =		outputs['encoder_attentions']
             else:
               _UpperCAmelCase							 =		outputs['hidden_states']
               _UpperCAmelCase							 =		outputs['attentions']

             self.assertEqual(len(snake_case						)	,       snake_case						)

             _UpperCAmelCase							 =		getattr(
                 self.model_tester	,       'expected_num_hidden_layers'	,       self.model_tester.num_hidden_layers + 1						)

             self.assertEqual(len(snake_case						)	,       snake_case						)
             self.assertListEqual(
                 list(output_hidden_states[0].shape[-2:]						)	,       [self.model_tester.seq_length, self.model_tester.hidden_size]	,       )

             self.assertEqual(len(snake_case						)	,       self.model_tester.num_hidden_layers						)
             self.assertListEqual(
                 list(output_attentions[0].shape[-3:]						)	,       [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]	,       )






       @slow
       def        lowerCamelCase_   (  self						)			->							Optional[Any]:
         _UpperCAmelCase							 =		TFConvBertModel.from_pretrained('YituTech/conv-bert-base'						)
         self.assertIsNotNone(snake_case						)






       def        lowerCamelCase_   (  self						)			->							Tuple:
         _UpperCAmelCase ,					_UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs_for_common()
         _UpperCAmelCase							 =		True
         _UpperCAmelCase							 =		getattr(self.model_tester	,       'decoder_seq_length'	,       self.model_tester.seq_length						)
         _UpperCAmelCase							 =		getattr(self.model_tester	,       'encoder_seq_length'	,       self.model_tester.seq_length						)
         _UpperCAmelCase							 =		getattr(self.model_tester	,       'key_length'	,       snake_case						)
         _UpperCAmelCase							 =		getattr(self.model_tester	,       'key_length'	,       snake_case						)

         def check_decoder_attentions_output(snake_case						):
           _UpperCAmelCase							 =		len(snake_case						)
           self.assertEqual(out_len % 2	,       0						)
           _UpperCAmelCase							 =		outputs.decoder_attentions
           self.assertEqual(len(snake_case						)	,       self.model_tester.num_hidden_layers						)
           self.assertListEqual(
               list(decoder_attentions[0].shape[-3:]						)	,       [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]	,       )

         def check_encoder_attentions_output(snake_case						):
           _UpperCAmelCase							 =		[
               t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
           ]
           self.assertEqual(len(snake_case						)	,       self.model_tester.num_hidden_layers						)
           self.assertListEqual(
               list(attentions[0].shape[-3:]						)	,       [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]	,       )

         for model_class in self.all_model_classes:
           _UpperCAmelCase							 =		True
           _UpperCAmelCase							 =		False
           _UpperCAmelCase							 =		model_class(snake_case						)
           _UpperCAmelCase							 =		model(self._prepare_for_class(snake_case	,       snake_case						)						)
           _UpperCAmelCase							 =		len(snake_case						)
           self.assertEqual(config.output_hidden_states	,       snake_case						)
           check_encoder_attentions_output(snake_case						)

           if self.is_encoder_decoder:
             _UpperCAmelCase							 =		model_class(snake_case						)
             _UpperCAmelCase							 =		model(self._prepare_for_class(snake_case	,       snake_case						)						)
             self.assertEqual(config.output_hidden_states	,       snake_case						)
             check_decoder_attentions_output(snake_case						)

           # Check that output attentions can also be changed via the config
           del inputs_dict["output_attentions"]
           _UpperCAmelCase							 =		True
           _UpperCAmelCase							 =		model_class(snake_case						)
           _UpperCAmelCase							 =		model(self._prepare_for_class(snake_case	,       snake_case						)						)
           self.assertEqual(config.output_hidden_states	,       snake_case						)
           check_encoder_attentions_output(snake_case						)

           # Check attention is always last and order is fine
           _UpperCAmelCase							 =		True
           _UpperCAmelCase							 =		True
           _UpperCAmelCase							 =		model_class(snake_case						)
           _UpperCAmelCase							 =		model(self._prepare_for_class(snake_case	,       snake_case						)						)

           self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)	,       len(snake_case						)						)
           self.assertEqual(model.config.output_hidden_states	,       snake_case						)
           check_encoder_attentions_output(snake_case						)







@require_tf
class 			lowercase__			(      unittest.TestCase    ):
       '''simple docstring'''







       @slow
       def        lowerCamelCase_   (  self						)			->							List[str]:
         _UpperCAmelCase							 =		TFConvBertModel.from_pretrained('YituTech/conv-bert-base'						)
         _UpperCAmelCase							 =		tf.constant([[0, 1, 2, 3, 4, 5]]						)
         _UpperCAmelCase							 =		model(snake_case						)[0]

         _UpperCAmelCase							 =		[1, 6, 768]
         self.assertEqual(output.shape	,       snake_case						)

         _UpperCAmelCase							 =		tf.constant(
             [
                 [
                     [-0.03475493, -0.4686034, -0.30638832],
                     [0.22637248, -0.26988646, -0.7423424],
                     [0.10324868, -0.45013508, -0.58280784],
                 ]
             ]						)
         tf.debugging.assert_near(output[:, :3, :3]	,       snake_case	,       atol=1E-4						)







"""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 			lowercase__			(      unittest.TestCase    ):
							'''simple docstring'''







							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		{
									    '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},
									    }
									}
									_UpperCAmelCase							 =		{
									    '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(snake_case						)	,       snake_case						)






							def        lowerCamelCase_   (  self						)			->							List[str]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									self.assertTrue(np.allclose(transpose(snake_case						)	,       x.transpose()						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									self.assertTrue(np.allclose(transpose(snake_case	,       axes=(1, 2, 0)						)	,       x.transpose((1, 2, 0)						)						)						)






							@require_torch
							def        lowerCamelCase_   (  self						)			->							List[str]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(transpose(snake_case						)	,       transpose(snake_case						).numpy()						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(transpose(snake_case	,       axes=(1, 2, 0)						)	,       transpose(snake_case	,       axes=(1, 2, 0)						).numpy()						)						)






							@require_tf
							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(transpose(snake_case						)	,       transpose(snake_case						).numpy()						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(transpose(snake_case	,       axes=(1, 2, 0)						)	,       transpose(snake_case	,       axes=(1, 2, 0)						).numpy()						)						)






							@require_flax
							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(transpose(snake_case						)	,       np.asarray(transpose(snake_case						)						)						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(transpose(snake_case	,       axes=(1, 2, 0)						)	,       np.asarray(transpose(snake_case	,       axes=(1, 2, 0)						)						)						)						)






							def        lowerCamelCase_   (  self						)			->							List[str]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (4, 3)						)	,       np.reshape(snake_case	,       (4, 3)						)						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (12, 5)						)	,       np.reshape(snake_case	,       (12, 5)						)						)						)






							@require_torch
							def        lowerCamelCase_   (  self						)			->							Optional[Any]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (4, 3)						)	,       reshape(snake_case	,       (4, 3)						).numpy()						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (12, 5)						)	,       reshape(snake_case	,       (12, 5)						).numpy()						)						)






							@require_tf
							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (4, 3)						)	,       reshape(snake_case	,       (4, 3)						).numpy()						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (12, 5)						)	,       reshape(snake_case	,       (12, 5)						).numpy()						)						)






							@require_flax
							def        lowerCamelCase_   (  self						)			->							Tuple:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (4, 3)						)	,       np.asarray(reshape(snake_case	,       (4, 3)						)						)						)						)

									_UpperCAmelCase							 =		np.random.randn(3	,       4	,       5						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(reshape(snake_case	,       (12, 5)						)	,       np.asarray(reshape(snake_case	,       (12, 5)						)						)						)						)






							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		np.random.randn(1	,       3	,       4						)
									self.assertTrue(np.allclose(squeeze(snake_case						)	,       np.squeeze(snake_case						)						)						)

									_UpperCAmelCase							 =		np.random.randn(1	,       4	,       1	,       5						)
									self.assertTrue(np.allclose(squeeze(snake_case	,       axis=2						)	,       np.squeeze(snake_case	,       axis=2						)						)						)






							@require_torch
							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		np.random.randn(1	,       3	,       4						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(squeeze(snake_case						)	,       squeeze(snake_case						).numpy()						)						)

									_UpperCAmelCase							 =		np.random.randn(1	,       4	,       1	,       5						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(squeeze(snake_case	,       axis=2						)	,       squeeze(snake_case	,       axis=2						).numpy()						)						)






							@require_tf
							def        lowerCamelCase_   (  self						)			->							Optional[int]:
									_UpperCAmelCase							 =		np.random.randn(1	,       3	,       4						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(squeeze(snake_case						)	,       squeeze(snake_case						).numpy()						)						)

									_UpperCAmelCase							 =		np.random.randn(1	,       4	,       1	,       5						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(squeeze(snake_case	,       axis=2						)	,       squeeze(snake_case	,       axis=2						).numpy()						)						)






							@require_flax
							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		np.random.randn(1	,       3	,       4						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(squeeze(snake_case						)	,       np.asarray(squeeze(snake_case						)						)						)						)

									_UpperCAmelCase							 =		np.random.randn(1	,       4	,       1	,       5						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(squeeze(snake_case	,       axis=2						)	,       np.asarray(squeeze(snake_case	,       axis=2						)						)						)						)






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									self.assertTrue(np.allclose(expand_dims(snake_case	,       axis=1						)	,       np.expand_dims(snake_case	,       axis=1						)						)						)






							@require_torch
							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		torch.tensor(snake_case						)
									self.assertTrue(np.allclose(expand_dims(snake_case	,       axis=1						)	,       expand_dims(snake_case	,       axis=1						).numpy()						)						)






							@require_tf
							def        lowerCamelCase_   (  self						)			->							int:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		tf.constant(snake_case						)
									self.assertTrue(np.allclose(expand_dims(snake_case	,       axis=1						)	,       expand_dims(snake_case	,       axis=1						).numpy()						)						)






							@require_flax
							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		np.random.randn(3	,       4						)
									_UpperCAmelCase							 =		jnp.array(snake_case						)
									self.assertTrue(np.allclose(expand_dims(snake_case	,       axis=1						)	,       np.asarray(expand_dims(snake_case	,       axis=1						)						)						)						)


