



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

import unittest

from transformers import DebertaConfig, 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 (
					    TFDebertaForMaskedLM,
					    TFDebertaForQuestionAnswering,
					    TFDebertaForSequenceClassification,
					    TFDebertaForTokenClassification,
					    TFDebertaModel,
					)



class _A  :





		def __init__(     self ,       __UpperCAmelCase ,       __UpperCAmelCase=13 ,       __UpperCAmelCase=7 ,       __UpperCAmelCase=True ,       __UpperCAmelCase=True ,       __UpperCAmelCase=True ,       __UpperCAmelCase=True ,       __UpperCAmelCase=99 ,       __UpperCAmelCase=32 ,       __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=None ,       )       ->     List[str]:

					'''simple docstring'''
					__UpperCAmelCase   :      Any										=     parent
					__UpperCAmelCase   :      int										=     13
					__UpperCAmelCase   :      List[str]										=     7
					__UpperCAmelCase   :      int										=     True
					__UpperCAmelCase   :      Tuple										=     True
					__UpperCAmelCase   :      Optional[int]										=     True
					__UpperCAmelCase   :      str										=     True
					__UpperCAmelCase   :      Any										=     99
					__UpperCAmelCase   :      Optional[Any]										=     32
					__UpperCAmelCase   :      Tuple										=     2
					__UpperCAmelCase   :      List[str]										=     4
					__UpperCAmelCase   :      int										=     37
					__UpperCAmelCase   :      str										=     """gelu"""
					__UpperCAmelCase   :      Optional[int]										=     0.1
					__UpperCAmelCase   :      List[str]										=     0.1
					__UpperCAmelCase   :      Tuple										=     512
					__UpperCAmelCase   :      str										=     16
					__UpperCAmelCase   :      Optional[Any]										=     False
					__UpperCAmelCase   :      Any										=     -1
					__UpperCAmelCase   :      Optional[int]										=     True
					__UpperCAmelCase   :      Union[str, Any]										=     2
					__UpperCAmelCase   :      Optional[Any]										=     0.02
					__UpperCAmelCase   :      Optional[Any]										=     3
					__UpperCAmelCase   :      str										=     4
					__UpperCAmelCase   :      Union[str, Any]										=     None





		def 							__A       (     self				)       ->     Union[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase   :      Optional[int]										=     ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size				)

					__UpperCAmelCase   :      Tuple										=     None
					if self.use_input_mask:
								__UpperCAmelCase   :      Any										=     random_attention_mask([self.batch_size, self.seq_length]				)

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

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

					__UpperCAmelCase   :      Union[str, Any]										=     DebertaConfig(
					    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 ,       max_relative_positions=self.max_relative_positions ,       position_biased_input=self.position_biased_input ,       initializer_range=self.initializer_range ,       return_dict=__UpperCAmelCase ,       )

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





		def 							__A       (     self ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase				)       ->     Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase   :      str										=     TFDebertaModel(config=__UpperCAmelCase				)
					__UpperCAmelCase   :      int										=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

					__UpperCAmelCase   :      List[Any]										=     [input_ids, input_mask]
					__UpperCAmelCase   :      str										=     model(__UpperCAmelCase				)

					__UpperCAmelCase   :      str										=     model(__UpperCAmelCase				)

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





		def 							__A       (     self ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase				)       ->     List[Any]:

					'''simple docstring'''
					__UpperCAmelCase   :      Optional[int]										=     TFDebertaForMaskedLM(config=__UpperCAmelCase				)
					__UpperCAmelCase   :      Dict										=     {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					__UpperCAmelCase   :      Union[str, Any]										=     model(__UpperCAmelCase				)
					self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.vocab_size)				)





		def 							__A       (     self ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase				)       ->     Any:

					'''simple docstring'''
					__UpperCAmelCase   :      Tuple										=     self.num_labels
					__UpperCAmelCase   :      int										=     TFDebertaForSequenceClassification(config=__UpperCAmelCase				)
					__UpperCAmelCase   :      List[Any]										=     {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					__UpperCAmelCase   :      List[str]										=     model(__UpperCAmelCase				)
					self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.num_labels)				)





		def 							__A       (     self ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase				)       ->     List[Any]:

					'''simple docstring'''
					__UpperCAmelCase   :      Union[str, Any]										=     self.num_labels
					__UpperCAmelCase   :      Union[str, Any]										=     TFDebertaForTokenClassification(config=__UpperCAmelCase				)
					__UpperCAmelCase   :      Tuple										=     {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					__UpperCAmelCase   :      Optional[int]										=     model(__UpperCAmelCase				)
					self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.num_labels)				)





		def 							__A       (     self ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase ,       __UpperCAmelCase				)       ->     Any:

					'''simple docstring'''
					__UpperCAmelCase   :      List[str]										=     TFDebertaForQuestionAnswering(config=__UpperCAmelCase				)
					__UpperCAmelCase   :      Union[str, Any]										=     {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					__UpperCAmelCase   :      int										=     model(__UpperCAmelCase				)
					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 							__A       (     self				)       ->     Dict:

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



@require_tf
class _A  (    __SCREAMING_SNAKE_CASE	,				__SCREAMING_SNAKE_CASE	,				unittest.TestCase    ):
		_SCREAMING_SNAKE_CASE					:    Any						      =			(
		    (
		        TFDebertaModel,
		        TFDebertaForMaskedLM,
		        TFDebertaForQuestionAnswering,
		        TFDebertaForSequenceClassification,
		        TFDebertaForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		_SCREAMING_SNAKE_CASE					:    Union[str, Any]						      =			(
		    {
		        "feature-extraction": TFDebertaModel,
		        "fill-mask": TFDebertaForMaskedLM,
		        "question-answering": TFDebertaForQuestionAnswering,
		        "text-classification": TFDebertaForSequenceClassification,
		        "token-classification": TFDebertaForTokenClassification,
		        "zero-shot": TFDebertaForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)

		_SCREAMING_SNAKE_CASE					:    Optional[Any]						      =			False
		_SCREAMING_SNAKE_CASE					:    Optional[int]						      =			False





		def 							__A       (     self				)       ->     Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase   :      List[Any]										=     TFDebertaModelTester(self				)
					__UpperCAmelCase   :      Dict										=     ConfigTester(self ,       config_class=__UpperCAmelCase ,       hidden_size=37				)





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

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





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

					'''simple docstring'''
					__UpperCAmelCase   :      Any										=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__UpperCAmelCase				)





		def 							__A       (     self				)       ->     Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase   :      str										=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase				)





		def 							__A       (     self				)       ->     Dict:

					'''simple docstring'''
					__UpperCAmelCase   :      int										=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase				)





		def 							__A       (     self				)       ->     str:

					'''simple docstring'''
					__UpperCAmelCase   :      Optional[Any]										=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase				)





		def 							__A       (     self				)       ->     Dict:

					'''simple docstring'''
					__UpperCAmelCase   :      List[str]										=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase				)





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

					'''simple docstring'''
					__UpperCAmelCase   :      Optional[int]										=     TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""				)
					self.assertIsNotNone(__UpperCAmelCase				)



@require_tf
class _A  (    unittest.TestCase    ):





		@unittest.skip(reason="""Model not available yet"""				)
		def 							__A       (     self				)       ->     List[str]:

					'''simple docstring'''
					pass





		@slow
		def 							__A       (     self				)       ->     Tuple:

					'''simple docstring'''
					__UpperCAmelCase   :      int										=     TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""				)
					__UpperCAmelCase   :      Dict										=     tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]				)
					__UpperCAmelCase   :      Optional[int]										=     tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
					__UpperCAmelCase   :      Any										=     model(__UpperCAmelCase ,       attention_mask=__UpperCAmelCase				)[0]

					__UpperCAmelCase   :      Tuple										=     tf.constant(
					    [
					        [
					            [-0.5985_5896, -0.8055_2566, -0.846_2135],
					            [1.448_4025, -0.9348_3794, -0.8059_3085],
					            [0.312_2741, 0.0031_6059, -1.413_1377],
					        ]
					    ]				)
					tf.debugging.assert_near(output[:, 1:4, 1:4] ,       __UpperCAmelCase ,       atol=1E-4				)









'''simple docstring'''
from .chunk_utils import chunk_layer
from .data_transforms import make_atomaa_masks
from .feats import atomaa_to_atomaa, frames_and_literature_positions_to_atomaa_pos, torsion_angles_to_frames
from .loss import compute_predicted_aligned_error, compute_tm
from .protein import Protein as OFProtein
from .protein import to_pdb
from .rigid_utils import Rigid, Rotation
from .tensor_utils import dict_multimap, flatten_final_dims, permute_final_dims




