






import torch

from diffusers import DPMSolverSDEScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import require_torchsde

from .test_schedulers import SchedulerCommonTest




@require_torchsde
class 				__A     (			a ):





				"""simple docstring"""







				UpperCamelCase__ :      Optional[int]			 =(DPMSolverSDEScheduler,)
				UpperCamelCase__ :      Tuple			 =1_0


				def       __lowercase							( self							,  **lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		={
									    'num_train_timesteps': 1100,
									    'beta_start': 0.0_001,
									    'beta_end': 0.02,
									    'beta_schedule': 'linear',
									    'noise_sampler_seed': 0,
									}

									config.update(**lowerCamelCase__    )
									return config


				def       __lowercase							( self    ):




									"""simple docstring"""

									for timesteps in [10, 50, 100, 1000]:
														self.check_over_configs(num_train_timesteps=lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									for beta_start, beta_end in zip([0.00_001, 0.0_001, 0.001]							,  [0.0_002, 0.002, 0.02]    ):
														self.check_over_configs(beta_start=lowerCamelCase__							,  beta_end=lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									for schedule in ["linear", "scaled_linear"]:
														self.check_over_configs(beta_schedule=lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									for prediction_type in ["epsilon", "v_prediction"]:
														self.check_over_configs(prediction_type=lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=self.scheduler_classes[0]
									__UpperCamelCase      :					Dict       		=self.get_scheduler_config()
									__UpperCamelCase      :					Union[str, Any]       		=scheduler_class(**lowerCamelCase__    )

									scheduler.set_timesteps(self.num_inference_steps    )

									__UpperCamelCase      :					Dict       		=self.dummy_model()
									__UpperCamelCase      :					Optional[int]       		=self.dummy_sample_deter * scheduler.init_noise_sigma
									__UpperCamelCase      :					Tuple       		=sample.to(lowerCamelCase__    )

									for i, t in enumerate(scheduler.timesteps    ):
														__UpperCamelCase      :					Union[str, Any]       		=scheduler.scale_model_input(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Dict       		=model(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					int       		=scheduler.step(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    )
														__UpperCamelCase      :					List[str]       		=output.prev_sample

									__UpperCamelCase      :					List[Any]       		=torch.sum(torch.abs(lowerCamelCase__    )    )
									__UpperCamelCase      :					Optional[int]       		=torch.mean(torch.abs(lowerCamelCase__    )    )

									if torch_device in ["mps"]:
														assert abs(result_sum.item() - 167.47_821_044_921_875    ) < 1E-2
														assert abs(result_mean.item() - 0.2_178_705_964_565_277    ) < 1E-3
									elif torch_device in ["cuda"]:
														assert abs(result_sum.item() - 171.59_352_111_816_406    ) < 1E-2
														assert abs(result_mean.item() - 0.22_342_906_892_299_652    ) < 1E-3
									else:
														assert abs(result_sum.item() - 162.52_383_422_851_562    ) < 1E-2
														assert abs(result_mean.item() - 0.211_619_570_851_326    ) < 1E-3


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Dict       		=self.scheduler_classes[0]
									__UpperCamelCase      :					int       		=self.get_scheduler_config(prediction_type='v_prediction'    )
									__UpperCamelCase      :					Optional[Any]       		=scheduler_class(**lowerCamelCase__    )

									scheduler.set_timesteps(self.num_inference_steps    )

									__UpperCamelCase      :					Optional[Any]       		=self.dummy_model()
									__UpperCamelCase      :					Tuple       		=self.dummy_sample_deter * scheduler.init_noise_sigma
									__UpperCamelCase      :					List[Any]       		=sample.to(lowerCamelCase__    )

									for i, t in enumerate(scheduler.timesteps    ):
														__UpperCamelCase      :					List[Any]       		=scheduler.scale_model_input(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					List[Any]       		=model(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Optional[int]       		=scheduler.step(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    )
														__UpperCamelCase      :					Any       		=output.prev_sample

									__UpperCamelCase      :					int       		=torch.sum(torch.abs(lowerCamelCase__    )    )
									__UpperCamelCase      :					Dict       		=torch.mean(torch.abs(lowerCamelCase__    )    )

									if torch_device in ["mps"]:
														assert abs(result_sum.item() - 124.77_149_200_439_453    ) < 1E-2
														assert abs(result_mean.item() - 0.16_226_289_014_816_284    ) < 1E-3
									elif torch_device in ["cuda"]:
														assert abs(result_sum.item() - 128.1_663_360_595_703    ) < 1E-2
														assert abs(result_mean.item() - 0.16_688_326_001_167_297    ) < 1E-3
									else:
														assert abs(result_sum.item() - 119.8_487_548_828_125    ) < 1E-2
														assert abs(result_mean.item() - 0.1_560_530_662_536_621    ) < 1E-3


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=self.scheduler_classes[0]
									__UpperCamelCase      :					str       		=self.get_scheduler_config()
									__UpperCamelCase      :					Tuple       		=scheduler_class(**lowerCamelCase__    )

									scheduler.set_timesteps(self.num_inference_steps							,  device=lowerCamelCase__    )

									__UpperCamelCase      :					str       		=self.dummy_model()
									__UpperCamelCase      :					Any       		=self.dummy_sample_deter.to(lowerCamelCase__    ) * scheduler.init_noise_sigma

									for t in scheduler.timesteps:
														__UpperCamelCase      :					Tuple       		=scheduler.scale_model_input(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Optional[Any]       		=model(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					int       		=scheduler.step(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    )
														__UpperCamelCase      :					List[str]       		=output.prev_sample

									__UpperCamelCase      :					List[Any]       		=torch.sum(torch.abs(lowerCamelCase__    )    )
									__UpperCamelCase      :					Any       		=torch.mean(torch.abs(lowerCamelCase__    )    )

									if torch_device in ["mps"]:
														assert abs(result_sum.item() - 167.46_957_397_460_938    ) < 1E-2
														assert abs(result_mean.item() - 0.21_805_934_607_982_635    ) < 1E-3
									elif torch_device in ["cuda"]:
														assert abs(result_sum.item() - 171.59_353_637_695_312    ) < 1E-2
														assert abs(result_mean.item() - 0.22_342_908_382_415_771    ) < 1E-3
									else:
														assert abs(result_sum.item() - 162.52_383_422_851_562    ) < 1E-2
														assert abs(result_mean.item() - 0.211_619_570_851_326    ) < 1E-3







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[str]       		=self.scheduler_classes[0]
									__UpperCamelCase      :					Optional[int]       		=self.get_scheduler_config()
									__UpperCamelCase      :					Optional[Any]       		=scheduler_class(**lowerCamelCase__							,  use_karras_sigmas=lowerCamelCase__    )

									scheduler.set_timesteps(self.num_inference_steps							,  device=lowerCamelCase__    )

									__UpperCamelCase      :					Tuple       		=self.dummy_model()
									__UpperCamelCase      :					Optional[Any]       		=self.dummy_sample_deter.to(lowerCamelCase__    ) * scheduler.init_noise_sigma
									__UpperCamelCase      :					int       		=sample.to(lowerCamelCase__    )

									for t in scheduler.timesteps:
														__UpperCamelCase      :					List[str]       		=scheduler.scale_model_input(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Dict       		=model(lowerCamelCase__							,  lowerCamelCase__    )

														__UpperCamelCase      :					Any       		=scheduler.step(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    )
														__UpperCamelCase      :					Dict       		=output.prev_sample

									__UpperCamelCase      :					Optional[int]       		=torch.sum(torch.abs(lowerCamelCase__    )    )
									__UpperCamelCase      :					Union[str, Any]       		=torch.mean(torch.abs(lowerCamelCase__    )    )

									if torch_device in ["mps"]:
														assert abs(result_sum.item() - 176.66_974_135_742_188    ) < 1E-2
														assert abs(result_mean.item() - 0.23_003_872_730_981_811    ) < 1E-2
									elif torch_device in ["cuda"]:
														assert abs(result_sum.item() - 177.63_653_564_453_125    ) < 1E-2
														assert abs(result_mean.item() - 0.23_003_872_730_981_811    ) < 1E-2
									else:
														assert abs(result_sum.item() - 170.3_135_223_388_672    ) < 1E-2
														assert abs(result_mean.item() - 0.23_003_872_730_981_811    ) < 1E-2








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,		__magic_name__,		__magic_name__=13,		__magic_name__=7,		__magic_name__=True,		__magic_name__=True,		__magic_name__=True,		__magic_name__=True,		__magic_name__=99,		__magic_name__=32,		__magic_name__=2,		__magic_name__=4,		__magic_name__=37,		__magic_name__="gelu",		__magic_name__=0.1,		__magic_name__=0.1,		__magic_name__=512,		__magic_name__=16,		__magic_name__=2,		__magic_name__=0.02,		__magic_name__=3,		__magic_name__=4,		__magic_name__=None,		) ->      List[str]:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      parent
       UpperCamelCase__							:				int          =      13
       UpperCamelCase__							:				Optional[Any]          =      7
       UpperCamelCase__							:				Dict          =      True
       UpperCamelCase__							:				Dict          =      True
       UpperCamelCase__							:				str          =      True
       UpperCamelCase__							:				List[str]          =      True
       UpperCamelCase__							:				Tuple          =      99
       UpperCamelCase__							:				Any          =      384
       UpperCamelCase__							:				Tuple          =      2
       UpperCamelCase__							:				int          =      4
       UpperCamelCase__							:				Optional[int]          =      37
       UpperCamelCase__							:				str          =      '''gelu'''
       UpperCamelCase__							:				Any          =      0.1
       UpperCamelCase__							:				Dict          =      0.1
       UpperCamelCase__							:				Tuple          =      512
       UpperCamelCase__							:				int          =      16
       UpperCamelCase__							:				int          =      2
       UpperCamelCase__							:				Any          =      0.02
       UpperCamelCase__							:				Optional[Any]          =      3
       UpperCamelCase__							:				Any          =      4
       UpperCamelCase__							:				Any          =      128
       UpperCamelCase__							:				List[str]          =      2
       UpperCamelCase__							:				List[str]          =      9
       UpperCamelCase__							:				Optional[int]          =      1
       UpperCamelCase__							:				List[Any]          =      None




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				Tuple          =      ids_tensor([self.batch_size, self.seq_length],		self.vocab_size							)

       UpperCamelCase__							:				Optional[int]          =      None
       if self.use_input_mask:
           UpperCamelCase__							:				Dict          =      random_attention_mask([self.batch_size, self.seq_length]							)

       UpperCamelCase__							:				Dict          =      None
       if self.use_token_type_ids:
           UpperCamelCase__							:				List[str]          =      ids_tensor([self.batch_size, self.seq_length],		self.type_vocab_size							)

       UpperCamelCase__							:				str          =      None
       UpperCamelCase__							:				Union[str, Any]          =      None
       UpperCamelCase__							:				Dict          =      None
       if self.use_labels:
           UpperCamelCase__							:				str          =      ids_tensor([self.batch_size],		self.type_sequence_label_size							)
           UpperCamelCase__							:				List[str]          =      ids_tensor([self.batch_size, self.seq_length],		self.num_labels							)
           UpperCamelCase__							:				Tuple          =      ids_tensor([self.batch_size],		self.num_choices							)

       UpperCamelCase__							:				Any          =      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=__magic_name__,		)

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




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				Tuple          =      TFConvBertModel(config=__magic_name__							)
       UpperCamelCase__							:				str          =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

       UpperCamelCase__							:				Any          =      [input_ids, input_mask]
       UpperCamelCase__							:				int          =      model(__magic_name__							)

       UpperCamelCase__							:				int          =      model(__magic_name__							)

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




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      TFConvBertForMaskedLM(config=__magic_name__							)
       UpperCamelCase__							:				List[str]          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCamelCase__							:				Tuple          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.vocab_size)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.num_labels
       UpperCamelCase__							:				Optional[int]          =      TFConvBertForSequenceClassification(config=__magic_name__							)
       UpperCamelCase__							:				str          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       UpperCamelCase__							:				Any          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_labels)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				int          =      self.num_choices
       UpperCamelCase__							:				str          =      TFConvBertForMultipleChoice(config=__magic_name__							)
       UpperCamelCase__							:				Optional[int]          =      tf.tile(tf.expand_dims(__magic_name__,		1							),		(1, self.num_choices, 1)							)
       UpperCamelCase__							:				Any          =      tf.tile(tf.expand_dims(__magic_name__,		1							),		(1, self.num_choices, 1)							)
       UpperCamelCase__							:				Tuple          =      tf.tile(tf.expand_dims(__magic_name__,		1							),		(1, self.num_choices, 1)							)
       UpperCamelCase__							:				int          =      {
           '''input_ids''': multiple_choice_inputs_ids,
           '''attention_mask''': multiple_choice_input_mask,
           '''token_type_ids''': multiple_choice_token_type_ids,
       }
       UpperCamelCase__							:				Tuple          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_choices)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      self.num_labels
       UpperCamelCase__							:				Any          =      TFConvBertForTokenClassification(config=__magic_name__							)
       UpperCamelCase__							:				str          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCamelCase__							:				Dict          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.num_labels)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      TFConvBertForQuestionAnswering(config=__magic_name__							)
       UpperCamelCase__							:				Optional[Any]          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       UpperCamelCase__							:				List[str]          =      model(__magic_name__							)
       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       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.prepare_config_and_inputs()
       (
           (
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,
       )							:				Any          =      config_and_inputs
       UpperCamelCase__							:				List[str]          =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_tf
class     lowercase__       (	__lowerCamelCase			,				__lowerCamelCase			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		(
       (
           TFConvBertModel,
           TFConvBertForMaskedLM,
           TFConvBertForQuestionAnswering,
           TFConvBertForSequenceClassification,
           TFConvBertForTokenClassification,
           TFConvBertForMultipleChoice,
       )
       if is_tf_available()
       else ()
   )
   a						:							int   		=		(
       {
           "feature-extraction": TFConvBertModel,
           "fill-mask": TFConvBertForMaskedLM,
           "question-answering": TFConvBertForQuestionAnswering,
           "text-classification": TFConvBertForSequenceClassification,
           "token-classification": TFConvBertForTokenClassification,
           "zero-shot": TFConvBertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   a						:							Optional[Any]   		=		False
   a						:							List[str]   		=		False
   a						:							List[Any]   		=		False




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






       """simple docstring"""
       UpperCamelCase__							:				List[str]          =      TFConvBertModelTester(self							)
       UpperCamelCase__							:				Optional[int]          =      ConfigTester(self,		config_class=__magic_name__,		hidden_size=37							)




   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       self.config_tester.run_common_tests()




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






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*__magic_name__							)




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






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*__magic_name__							)




   @slow
   def       UpperCamelCase__  (    self							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__   ,UpperCamelCase__							:				Tuple          =      self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase__							:				Union[str, Any]          =      True
       UpperCamelCase__							:				Optional[int]          =      True

       if hasattr(__magic_name__,		'''use_cache'''							):
           UpperCamelCase__							:				Union[str, Any]          =      True

       UpperCamelCase__							:				Tuple          =      getattr(self.model_tester,		'''encoder_seq_length''',		self.model_tester.seq_length							)
       UpperCamelCase__							:				Any          =      getattr(self.model_tester,		'''key_length''',		__magic_name__							)

       for model_class in self.all_model_classes:
           UpperCamelCase__							:				Optional[int]          =      self._prepare_for_class(__magic_name__,		__magic_name__							)
           UpperCamelCase__							:				Any          =      model_class(__magic_name__							)
           UpperCamelCase__							:				List[str]          =      len(model(__magic_name__							)							)

           with tempfile.TemporaryDirectory() as tmpdirname:
               model.save_pretrained(__magic_name__,		saved_model=__magic_name__							)
               UpperCamelCase__							:				List[Any]          =      os.path.join(__magic_name__,		'''saved_model''',		'''1'''							)
               UpperCamelCase__							:				Dict          =      tf.keras.models.load_model(__magic_name__							)
               UpperCamelCase__							:				Optional[int]          =      model(__magic_name__							)

               if self.is_encoder_decoder:
                   UpperCamelCase__							:				Union[str, Any]          =      outputs['''encoder_hidden_states''']
                   UpperCamelCase__							:				Any          =      outputs['''encoder_attentions''']
               else:
                   UpperCamelCase__							:				Optional[Any]          =      outputs['''hidden_states''']
                   UpperCamelCase__							:				Dict          =      outputs['''attentions''']

               self.assertEqual(len(__magic_name__							),		__magic_name__							)

               UpperCamelCase__							:				Optional[Any]          =      getattr(
                   self.model_tester,		'''expected_num_hidden_layers''',		self.model_tester.num_hidden_layers + 1							)

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

               self.assertEqual(len(__magic_name__							),		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       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				str          =      TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''							)
       self.assertIsNotNone(__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__   ,UpperCamelCase__							:				int          =      self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase__							:				str          =      True
       UpperCamelCase__							:				Union[str, Any]          =      getattr(self.model_tester,		'''decoder_seq_length''',		self.model_tester.seq_length							)
       UpperCamelCase__							:				str          =      getattr(self.model_tester,		'''encoder_seq_length''',		self.model_tester.seq_length							)
       UpperCamelCase__							:				List[str]          =      getattr(self.model_tester,		'''key_length''',		__magic_name__							)
       UpperCamelCase__							:				int          =      getattr(self.model_tester,		'''key_length''',		__magic_name__							)

       def check_decoder_attentions_output(__magic_name__							):
           UpperCamelCase__							:				List[str]          =      len(__magic_name__							)
           self.assertEqual(out_len % 2,		0							)
           UpperCamelCase__							:				Optional[Any]          =      outputs.decoder_attentions
           self.assertEqual(len(__magic_name__							),		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(__magic_name__							):
           UpperCamelCase__							:				int          =      [
               t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
           ]
           self.assertEqual(len(__magic_name__							),		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__							:				Dict          =      True
           UpperCamelCase__							:				str          =      False
           UpperCamelCase__							:				Optional[Any]          =      model_class(__magic_name__							)
           UpperCamelCase__							:				Dict          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)
           UpperCamelCase__							:				int          =      len(__magic_name__							)
           self.assertEqual(config.output_hidden_states,		__magic_name__							)
           check_encoder_attentions_output(__magic_name__							)

           if self.is_encoder_decoder:
               UpperCamelCase__							:				str          =      model_class(__magic_name__							)
               UpperCamelCase__							:				List[str]          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)
               self.assertEqual(config.output_hidden_states,		__magic_name__							)
               check_decoder_attentions_output(__magic_name__							)

           # Check that output attentions can also be changed via the config
           del inputs_dict["output_attentions"]
           UpperCamelCase__							:				List[Any]          =      True
           UpperCamelCase__							:				Dict          =      model_class(__magic_name__							)
           UpperCamelCase__							:				Optional[Any]          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)
           self.assertEqual(config.output_hidden_states,		__magic_name__							)
           check_encoder_attentions_output(__magic_name__							)

           # Check attention is always last and order is fine
           UpperCamelCase__							:				List[Any]          =      True
           UpperCamelCase__							:				List[Any]          =      True
           UpperCamelCase__							:				Dict          =      model_class(__magic_name__							)
           UpperCamelCase__							:				List[Any]          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)

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






@require_tf
class     lowercase__       (	unittest.TestCase				):

   '''simple docstring'''


   @slow
   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''							)
       UpperCamelCase__							:				Tuple          =      tf.constant([[0, 1, 2, 3, 4, 5]]							)
       UpperCamelCase__							:				int          =      model(__magic_name__							)[0]

       UpperCamelCase__							:				Dict          =      [1, 6, 768]
       self.assertEqual(output.shape,		__magic_name__							)

       UpperCamelCase__							:				Union[str, Any]          =      tf.constant(
           [
               [
                   [-0.0347_5493, -0.468_6034, -0.3063_8832],
                   [0.2263_7248, -0.2698_8646, -0.742_3424],
                   [0.1032_4868, -0.4501_3508, -0.5828_0784],
               ]
           ]							)
       tf.debugging.assert_near(output[:, :3, :3],		__magic_name__,		atol=1E-4							)

