




import argparse
import os
import re

import packaging.version


__A        =    "examples/"
__A        =    {
    "examples": (re.compile(R"^check_min_version\(\"[^\"]+\"\)\s*$", re.MULTILINE), "check_min_version(\"VERSION\")\n"),
    "init": (re.compile(R"^__version__\s+=\s+\"([^\"]+)\"\s*$", re.MULTILINE), "__version__ = \"VERSION\"\n"),
    "setup": (re.compile(R"^(\s*)version\s*=\s*\"[^\"]+\",", re.MULTILINE), R"\1version=\"VERSION\","),
    "doc": (re.compile(R"^(\s*)release\s*=\s*\"[^\"]+\"$", re.MULTILINE), "release = \"VERSION\"\n"),
}
__A        =    {
    "init": "src/transformers/__init__.py",
    "setup": "setup.py",
}
__A        =    "README.md"







def 			lowerCamelCase_		(       UpperCamelCase__				:      Dict ,     UpperCamelCase__				:      List[Any] ,     UpperCamelCase__				:      Tuple      )     ->       int:





				"""simple docstring"""


				with open(UpperCamelCase__ ,     'r' ,     encoding='utf-8' ,     newline='\n'      ) as f:
								__lowerCamelCase		       =    f.read()
				__lowerCamelCase       ,						__lowerCamelCase		       =    REPLACE_PATTERNS[pattern]
				__lowerCamelCase		       =    replace.replace('VERSION' ,     UpperCamelCase__      )
				__lowerCamelCase		       =    re_pattern.sub(UpperCamelCase__ ,     UpperCamelCase__      )
				with open(UpperCamelCase__ ,     'w' ,     encoding='utf-8' ,     newline='\n'      ) as f:
								f.write(UpperCamelCase__      )







def 			lowerCamelCase_		(       UpperCamelCase__				:      List[Any]      )     ->       Optional[Any]:





				"""simple docstring"""


				for folder, directories, fnames in os.walk(UpperCamelCase__      ):
								# Removing some of the folders with non-actively maintained examples from the walk
								if "research_projects" in directories:
												directories.remove('research_projects'      )
								if "legacy" in directories:
												directories.remove('legacy'      )
								for fname in fnames:
												if fname.endswith('.py'      ):
																update_version_in_file(os.path.join(UpperCamelCase__ ,     UpperCamelCase__      ) ,     UpperCamelCase__ ,     pattern='examples'      )







def 			lowerCamelCase_		(       UpperCamelCase__				:      Optional[Any] ,     UpperCamelCase__				:      Any=False      )     ->       Tuple:





				"""simple docstring"""


				for pattern, fname in REPLACE_FILES.items():
								update_version_in_file(UpperCamelCase__ ,     UpperCamelCase__ ,     UpperCamelCase__      )
				if not patch:
								update_version_in_examples(UpperCamelCase__      )







def 			lowerCamelCase_		(       )     ->       Any:





				"""simple docstring"""


				__lowerCamelCase		       =    '🤗 Transformers currently provides the following architectures'
				__lowerCamelCase		       =    '1. Want to contribute a new model?'
				with open(UpperCamelCase__ ,     'r' ,     encoding='utf-8' ,     newline='\n'      ) as f:
								__lowerCamelCase		       =    f.readlines()

				# Find the start of the list.
				__lowerCamelCase		       =    0
				while not lines[start_index].startswith(_start_prompt      ):
								start_index += 1
				start_index += 1

				__lowerCamelCase		       =    start_index
				# Update the lines in the model list.
				while not lines[index].startswith(_end_prompt      ):
								if lines[index].startswith('1.'      ):
												__lowerCamelCase		       =    lines[index].replace(
												    'https://huggingface.co/docs/transformers/main/model_doc' ,     'https://huggingface.co/docs/transformers/model_doc' ,     )
								index += 1

				with open(UpperCamelCase__ ,     'w' ,     encoding='utf-8' ,     newline='\n'      ) as f:
								f.writelines(UpperCamelCase__      )







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





				"""simple docstring"""


				with open(REPLACE_FILES['init'] ,     'r'      ) as f:
								__lowerCamelCase		       =    f.read()
				__lowerCamelCase		       =    REPLACE_PATTERNS['init'][0].search(UpperCamelCase__      ).groups()[0]
				return packaging.version.parse(UpperCamelCase__      )







def 			lowerCamelCase_		(       UpperCamelCase__				:      Optional[int]=False      )     ->       List[Any]:





				"""simple docstring"""


				__lowerCamelCase		       =    get_version()
				if patch and default_version.is_devrelease:
								raise ValueError('Can\'t create a patch version from the dev branch, checkout a released version!'      )
				if default_version.is_devrelease:
								__lowerCamelCase		       =    default_version.base_version
				elif patch:
								__lowerCamelCase		       =    F"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
				else:
								__lowerCamelCase		       =    F"""{default_version.major}.{default_version.minor + 1}.0"""

				# Now let's ask nicely if that's the right one.
				__lowerCamelCase		       =    input(F"""Which version are you releasing? [{default_version}]"""      )
				if len(UpperCamelCase__      ) == 0:
								__lowerCamelCase		       =    default_version

				print(F"""Updating version to {version}."""      )
				global_version_update(UpperCamelCase__ ,     patch=UpperCamelCase__      )
				if not patch:
								print('Cleaning main README, don\'t forget to run `make fix-copies`.'      )
								clean_main_ref_in_model_list()







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





				"""simple docstring"""


				__lowerCamelCase		       =    get_version()
				__lowerCamelCase		       =    F"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
				__lowerCamelCase		       =    current_version.base_version

				# Check with the user we got that right.
				__lowerCamelCase		       =    input(F"""Which version are we developing now? [{dev_version}]"""      )
				if len(UpperCamelCase__      ) == 0:
								__lowerCamelCase		       =    dev_version

				print(F"""Updating version to {version}."""      )
				global_version_update(UpperCamelCase__      )
				print('Cleaning main README, don\'t forget to run `make fix-copies`.'      )
				clean_main_ref_in_model_list()


if __name__ == "__main__":
					__A        =    argparse.ArgumentParser()
					parser.add_argument("--post_release", action="store_true", help="Whether this is pre or post release.")
					parser.add_argument("--patch", action="store_true", help="Whether or not this is a patch release.")
					__A        =    parser.parse_args()
					if not args.post_release:
										pre_release_work(patch=args.patch)
					elif args.patch:
										print("Nothing to do after a patch :-)")
					else:
										post_release_work()








import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    DebertaForMaskedLM,
					    DebertaForQuestionAnswering,
					    DebertaForSequenceClassification,
					    DebertaForTokenClassification,
					    DebertaModel,
					)
					from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST







class     __lowerCAmelCase (       __magic_name__ ):

			"""simple docstring"""







			def __init__(      self			,						lowerCamelCase__			,						lowerCamelCase__=13			,						lowerCamelCase__=7			,						lowerCamelCase__=True			,						lowerCamelCase__=True			,						lowerCamelCase__=True			,						lowerCamelCase__=True			,						lowerCamelCase__=99			,						lowerCamelCase__=32			,						lowerCamelCase__=5			,						lowerCamelCase__=4			,						lowerCamelCase__=37			,						lowerCamelCase__="gelu"			,						lowerCamelCase__=0.1			,						lowerCamelCase__=0.1			,						lowerCamelCase__=512			,						lowerCamelCase__=16			,						lowerCamelCase__=2			,						lowerCamelCase__=0.02			,						lowerCamelCase__=False			,						lowerCamelCase__=True			,						lowerCamelCase__="None"			,						lowerCamelCase__=3			,						lowerCamelCase__=4			,						lowerCamelCase__=None			,						)    ->      int:



							'''simple docstring'''
							__lowerCamelCase		       =    parent
							__lowerCamelCase		       =    batch_size
							__lowerCamelCase		       =    seq_length
							__lowerCamelCase		       =    is_training
							__lowerCamelCase		       =    use_input_mask
							__lowerCamelCase		       =    use_token_type_ids
							__lowerCamelCase		       =    use_labels
							__lowerCamelCase		       =    vocab_size
							__lowerCamelCase		       =    hidden_size
							__lowerCamelCase		       =    num_hidden_layers
							__lowerCamelCase		       =    num_attention_heads
							__lowerCamelCase		       =    intermediate_size
							__lowerCamelCase		       =    hidden_act
							__lowerCamelCase		       =    hidden_dropout_prob
							__lowerCamelCase		       =    attention_probs_dropout_prob
							__lowerCamelCase		       =    max_position_embeddings
							__lowerCamelCase		       =    type_vocab_size
							__lowerCamelCase		       =    type_sequence_label_size
							__lowerCamelCase		       =    initializer_range
							__lowerCamelCase		       =    num_labels
							__lowerCamelCase		       =    num_choices
							__lowerCamelCase		       =    relative_attention
							__lowerCamelCase		       =    position_biased_input
							__lowerCamelCase		       =    pos_att_type
							__lowerCamelCase		       =    scope


			def       lowercase_    (      self							)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    ids_tensor([self.batch_size, self.seq_length]			,						self.vocab_size							)

							__lowerCamelCase		       =    None
							if self.use_input_mask:
											__lowerCamelCase		       =    ids_tensor([self.batch_size, self.seq_length]			,						vocab_size=2							)

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

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

							__lowerCamelCase		       =    self.get_config()

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


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



							'''simple docstring'''
							return 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			,						initializer_range=self.initializer_range			,						relative_attention=self.relative_attention			,						position_biased_input=self.position_biased_input			,						pos_att_type=self.pos_att_type			,						)


			def       lowercase_    (      self							)    ->      List[str]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.get_config()
							__lowerCamelCase		       =    300
							return config


			def       lowercase_    (      self			,						lowerCamelCase__							)    ->      Optional[int]:



							'''simple docstring'''
							self.parent.assertListEqual(list(result.loss.size()							)			,						[]							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Any:



							'''simple docstring'''
							__lowerCamelCase		       =    DebertaModel(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__							)[0]
							__lowerCamelCase		       =    model(lowerCamelCase__			,						token_type_ids=lowerCamelCase__							)[0]
							__lowerCamelCase		       =    model(lowerCamelCase__							)[0]

							self.parent.assertListEqual(list(sequence_output.size()							)			,						[self.batch_size, self.seq_length, self.hidden_size]							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Tuple:



							'''simple docstring'''
							__lowerCamelCase		       =    DebertaForMaskedLM(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)

							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size)							)


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



							'''simple docstring'''
							__lowerCamelCase		       =    self.num_labels
							__lowerCamelCase		       =    DebertaForSequenceClassification(lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)
							self.parent.assertListEqual(list(result.logits.size()							)			,						[self.batch_size, self.num_labels]							)
							self.check_loss_output(lowerCamelCase__							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Optional[int]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.num_labels
							__lowerCamelCase		       =    DebertaForTokenClassification(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.num_labels)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Dict:



							'''simple docstring'''
							__lowerCamelCase		       =    DebertaForQuestionAnswering(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(
							    lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						start_positions=lowerCamelCase__			,						end_positions=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       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.prepare_config_and_inputs()
							(
							    (
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						
							)		       =    config_and_inputs
							__lowerCamelCase		       =    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_torch
class     __lowerCAmelCase (       __magic_name__			,				__magic_name__			,				unittest.TestCase ):

			"""simple docstring"""







			snake_case_   		=       (
			    (
			        DebertaModel,
			        DebertaForMaskedLM,
			        DebertaForSequenceClassification,
			        DebertaForTokenClassification,
			        DebertaForQuestionAnswering,
			    )
			    if is_torch_available()
			    else ()
			)
			snake_case_   		=       (
			    {
			        '''feature-extraction''': DebertaModel,
			        '''fill-mask''': DebertaForMaskedLM,
			        '''question-answering''': DebertaForQuestionAnswering,
			        '''text-classification''': DebertaForSequenceClassification,
			        '''token-classification''': DebertaForTokenClassification,
			        '''zero-shot''': DebertaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)

			snake_case_   		=       True
			snake_case_   		=       False
			snake_case_   		=       False
			snake_case_   		=       False
			snake_case_   		=       False


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



							'''simple docstring'''
							__lowerCamelCase		       =    DebertaModelTester(self							)
							__lowerCamelCase		       =    ConfigTester(self			,						config_class=lowerCamelCase__			,						hidden_size=37							)


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



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


			def       lowercase_    (      self							)    ->      List[str]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_model(*lowerCamelCase__							)


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



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      Dict:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCamelCase__							)


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



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_question_answering(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_token_classification(*lowerCamelCase__							)






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



							'''simple docstring'''
							for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowerCamelCase		       =    DebertaModel.from_pretrained(lowerCamelCase__							)
											self.assertIsNotNone(lowerCamelCase__							)







@require_torch
@require_sentencepiece
@require_tokenizers
class     __lowerCAmelCase (       unittest.TestCase ):

			"""simple docstring"""







			@unittest.skip(reason='Model not available yet'							)
			def       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							pass






			@slow
			def       lowercase_    (      self							)    ->      Tuple:



							'''simple docstring'''
							__lowerCamelCase		       =    DebertaModel.from_pretrained('microsoft/deberta-base'							)

							__lowerCamelCase		       =    torch.tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]							)
							__lowerCamelCase		       =    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
							with torch.no_grad():
											__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__							)[0]
							# compare the actual values for a slice.
							__lowerCamelCase		       =    torch.tensor(
							    [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]]							)
							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,						lowerCamelCase__			,						atol=1e-4							)			,						f"""{output[:, 1:4, 1:4]}"""							)


