



'''simple docstring'''
from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
					    TFDebertaVaForMaskedLM,
					    TFDebertaVaForQuestionAnswering,
					    TFDebertaVaForSequenceClassification,
					    TFDebertaVaForTokenClassification,
					    TFDebertaVaModel,
					)






class 				lowercase__      :





	def __init__(					self   :							Optional[int]					,lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							Optional[Any]=13					,lowerCamelCase__   :							List[Any]=7					,lowerCamelCase__   :							Tuple=True					,lowerCamelCase__   :							List[Any]=True					,lowerCamelCase__   :							Tuple=True					,lowerCamelCase__   :							Tuple=True					,lowerCamelCase__   :							Optional[Any]=99					,lowerCamelCase__   :							Tuple=32					,lowerCamelCase__   :							int=2					,lowerCamelCase__   :							Tuple=4					,lowerCamelCase__   :							Tuple=37					,lowerCamelCase__   :							Tuple="gelu"					,lowerCamelCase__   :							Union[str, Any]=0.1					,lowerCamelCase__   :							int=0.1					,lowerCamelCase__   :							Dict=512					,lowerCamelCase__   :							Tuple=16					,lowerCamelCase__   :							Optional[int]=2					,lowerCamelCase__   :							Optional[Any]=0.0_2					,lowerCamelCase__   :							List[str]=False					,lowerCamelCase__   :							Tuple=True					,lowerCamelCase__   :							Tuple="None"					,lowerCamelCase__   :							List[str]=3					,lowerCamelCase__   :							Optional[Any]=4					,lowerCamelCase__   :							Tuple=None					,):







							'''simple docstring'''
							_UpperCamelCase   :						Dict												=  parent
							_UpperCamelCase   :						str												=  batch_size
							_UpperCamelCase   :						Dict												=  seq_length
							_UpperCamelCase   :						List[Any]												=  is_training
							_UpperCamelCase   :						Dict												=  use_input_mask
							_UpperCamelCase   :						List[Any]												=  use_token_type_ids
							_UpperCamelCase   :						List[str]												=  use_labels
							_UpperCamelCase   :						Optional[Any]												=  vocab_size
							_UpperCamelCase   :						List[Any]												=  hidden_size
							_UpperCamelCase   :						List[Any]												=  num_hidden_layers
							_UpperCamelCase   :						Any												=  num_attention_heads
							_UpperCamelCase   :						str												=  intermediate_size
							_UpperCamelCase   :						Optional[int]												=  hidden_act
							_UpperCamelCase   :						Any												=  hidden_dropout_prob
							_UpperCamelCase   :						List[str]												=  attention_probs_dropout_prob
							_UpperCamelCase   :						Tuple												=  max_position_embeddings
							_UpperCamelCase   :						Dict												=  type_vocab_size
							_UpperCamelCase   :						int												=  type_sequence_label_size
							_UpperCamelCase   :						Tuple												=  initializer_range
							_UpperCamelCase   :						str												=  num_labels
							_UpperCamelCase   :						str												=  num_choices
							_UpperCamelCase   :						Any												=  relative_attention
							_UpperCamelCase   :						Optional[Any]												=  position_biased_input
							_UpperCamelCase   :						Optional[int]												=  pos_att_type
							_UpperCamelCase   :						Optional[int]												=  scope





	def       UpperCamelCase_    (					self   :							Any					):







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

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

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

							_UpperCamelCase   :						List[str]												=  None
							_UpperCamelCase   :						Optional[int]												=  None
							_UpperCamelCase   :						List[str]												=  None
							if self.use_labels:
													_UpperCamelCase   :						int												=  ids_tensor([self.batch_size]					,self.type_sequence_label_size					)
													_UpperCamelCase   :						List[Any]												=  ids_tensor([self.batch_size, self.seq_length]					,self.num_labels					)

							_UpperCamelCase   :						Any												=  DebertaVaConfig(
							    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					,relative_attention=self.relative_attention					,position_biased_input=self.position_biased_input					,initializer_range=self.initializer_range					,return_dict=lowerCamelCase__					,)

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





	def       UpperCamelCase_    (					self   :							Tuple					,lowerCamelCase__   :							Dict					,lowerCamelCase__   :							Any					,lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							int					,lowerCamelCase__   :							Union[str, Any]					,lowerCamelCase__   :							Any					,lowerCamelCase__   :							Dict					):







							'''simple docstring'''
							_UpperCamelCase   :						Union[str, Any]												=  TFDebertaVaModel(config=lowerCamelCase__					)
							_UpperCamelCase   :						List[str]												=  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

							_UpperCamelCase   :						Any												=  [input_ids, input_mask]
							_UpperCamelCase   :						Optional[int]												=  model(lowerCamelCase__					)

							_UpperCamelCase   :						Union[str, Any]												=  model(lowerCamelCase__					)

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





	def       UpperCamelCase_    (					self   :							Union[str, Any]					,lowerCamelCase__   :							Union[str, Any]					,lowerCamelCase__   :							str					,lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							Any					,lowerCamelCase__   :							str					,lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							Tuple					):







							'''simple docstring'''
							_UpperCamelCase   :						Tuple												=  TFDebertaVaForMaskedLM(config=lowerCamelCase__					)
							_UpperCamelCase   :						Dict												=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							_UpperCamelCase   :						int												=  model(lowerCamelCase__					)
							self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.seq_length, self.vocab_size)					)





	def       UpperCamelCase_    (					self   :							Tuple					,lowerCamelCase__   :							int					,lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							Optional[int]					,lowerCamelCase__   :							List[str]					,lowerCamelCase__   :							Optional[int]					,lowerCamelCase__   :							Optional[Any]					,lowerCamelCase__   :							Optional[int]					):







							'''simple docstring'''
							_UpperCamelCase   :						Dict												=  self.num_labels
							_UpperCamelCase   :						int												=  TFDebertaVaForSequenceClassification(config=lowerCamelCase__					)
							_UpperCamelCase   :						Optional[int]												=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							_UpperCamelCase   :						List[Any]												=  model(lowerCamelCase__					)
							self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.num_labels)					)





	def       UpperCamelCase_    (					self   :							int					,lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							str					,lowerCamelCase__   :							Union[str, Any]					,lowerCamelCase__   :							str					,lowerCamelCase__   :							List[Any]					,lowerCamelCase__   :							Any					,lowerCamelCase__   :							Dict					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[int]												=  self.num_labels
							_UpperCamelCase   :						Dict												=  TFDebertaVaForTokenClassification(config=lowerCamelCase__					)
							_UpperCamelCase   :						Union[str, Any]												=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							_UpperCamelCase   :						List[Any]												=  model(lowerCamelCase__					)
							self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.seq_length, self.num_labels)					)





	def       UpperCamelCase_    (					self   :							Any					,lowerCamelCase__   :							int					,lowerCamelCase__   :							Union[str, Any]					,lowerCamelCase__   :							Dict					,lowerCamelCase__   :							Optional[Any]					,lowerCamelCase__   :							List[Any]					,lowerCamelCase__   :							str					,lowerCamelCase__   :							Optional[int]					):







							'''simple docstring'''
							_UpperCamelCase   :						Union[str, Any]												=  TFDebertaVaForQuestionAnswering(config=lowerCamelCase__					)
							_UpperCamelCase   :						Tuple												=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							_UpperCamelCase   :						Tuple												=  model(lowerCamelCase__					)
							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   :							Union[str, Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Dict												=  self.prepare_config_and_inputs()
							(
							    (
							    _UpperCamelCase       
							)							,     (
							    _UpperCamelCase       
							)							,     (
							    _UpperCamelCase       
							)							,     (
							    _UpperCamelCase       
							)							,     (
							    _UpperCamelCase       
							)							,     (
							    _UpperCamelCase       
							)							,     (
							    _UpperCamelCase       
							)							,            
							)   :						List[Any]												=  config_and_inputs
							_UpperCamelCase   :						Optional[int]												=  {'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  ):
	lowercase__    							=     (
	    (
	        TFDebertaVaModel,
	        TFDebertaVaForMaskedLM,
	        TFDebertaVaForQuestionAnswering,
	        TFDebertaVaForSequenceClassification,
	        TFDebertaVaForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	lowercase__    							=     (
	    {
	        """feature-extraction""": TFDebertaVaModel,
	        """fill-mask""": TFDebertaVaForMaskedLM,
	        """question-answering""": TFDebertaVaForQuestionAnswering,
	        """text-classification""": TFDebertaVaForSequenceClassification,
	        """token-classification""": TFDebertaVaForTokenClassification,
	        """zero-shot""": TFDebertaVaForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)

	lowercase__    							=     False
	lowercase__    							=     False





	def       UpperCamelCase_    (					self   :							str					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[int]												=  TFDebertaVaModelTester(self					)
							_UpperCamelCase   :						Optional[Any]												=  ConfigTester(self					,config_class=lowerCamelCase__					,hidden_size=37					)





	def       UpperCamelCase_    (					self   :							Union[str, Any]					):







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





	def       UpperCamelCase_    (					self   :							Dict					):







							'''simple docstring'''
							_UpperCamelCase   :						Union[str, Any]												=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							Union[str, Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Any												=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							Optional[int]					):







							'''simple docstring'''
							_UpperCamelCase   :						Union[str, Any]												=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							int					):







							'''simple docstring'''
							_UpperCamelCase   :						List[Any]												=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Union[str, Any]												=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__					)





	@slow
	def       UpperCamelCase_    (					self   :							Any					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[int]												=  TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'					)
							self.assertIsNotNone(lowerCamelCase__					)






@require_tf
class 				lowercase__      (				unittest.TestCase  ):





	@unittest.skip(reason='Model not available yet'					)
	def       UpperCamelCase_    (					self   :							List[str]					):







							'''simple docstring'''
							pass





	@slow
	def       UpperCamelCase_    (					self   :							Tuple					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[Any]												=  TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'					)
							_UpperCamelCase   :						Optional[Any]												=  tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]					)
							_UpperCamelCase   :						List[Any]												=  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
							_UpperCamelCase   :						Union[str, Any]												=  model(lowerCamelCase__					,attention_mask=lowerCamelCase__					)[0]

							_UpperCamelCase   :						List[str]												=  tf.constant(
							    [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]					)
							tf.debugging.assert_near(output[:, 1:4, 1:4]					,lowerCamelCase__					,atol=1E-4					)






from __future__ import annotations






class      UpperCamelCase:


					def __init__(    self						:		Optional[int]  ,     SCREAMING_SNAKE_CASE						:		str  ,     SCREAMING_SNAKE_CASE						:		str    )      ->						str:




											'''simple docstring'''

											__snake_case		,       __snake_case				=		text, pattern
											__snake_case		,       __snake_case				=		len(SCREAMING_SNAKE_CASE    ), len(SCREAMING_SNAKE_CASE    )


					def 				SCREAMING_SNAKE_CASE_	(    self						:		Optional[Any]  ,     SCREAMING_SNAKE_CASE						:		str    )      ->						int:




											'''simple docstring'''

											for i in range(self.patLen - 1  ,     -1  ,     -1    ):
																	if char == self.pattern[i]:
																							return i
											return -1


					def 				SCREAMING_SNAKE_CASE_	(    self						:		int  ,     SCREAMING_SNAKE_CASE						:		int    )      ->						int:




											'''simple docstring'''

											for i in range(self.patLen - 1  ,     -1  ,     -1    ):
																	if self.pattern[i] != self.text[current_pos + i]:
																							return current_pos + i
											return -1






					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[Any]    )      ->						list[int]:




											'''simple docstring'''

											__snake_case				=		[]
											for i in range(self.textLen - self.patLen + 1    ):
																	__snake_case				=		self.mismatch_in_text(SCREAMING_SNAKE_CASE    )
																	if mismatch_index == -1:
																							positions.append(SCREAMING_SNAKE_CASE    )
																	else:
																							__snake_case				=		self.match_in_pattern(self.text[mismatch_index]    )
																							__snake_case				=		(
																							    mismatch_index - match_index
																							)  # shifting index lgtm [py/multiple-definition]
											return positions




A				:       str      =  'ABAABA'
A				:       Optional[Any]      =  'AB'
A				:       Any      =  BoyerMooreSearch(text, pattern)
A				:       Tuple      =  bms.bad_character_heuristic()

if len(positions) == 0:
	print('No match found')
else:
	print('Pattern found in following positions: ')
	print(positions)





