



"""simple docstring"""






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        __SCREAMING_SNAKE_CASE	(      __lowercase   ):


					'''simple docstring'''





					def __init__(       self							:  Tuple,  lowerCamelCase							:  List[str],  lowerCamelCase							:  List[Any]=13,  lowerCamelCase							:  int=7,  lowerCamelCase							:  List[str]=True,  lowerCamelCase							:  Optional[Any]=True,  lowerCamelCase							:  Dict=True,  lowerCamelCase							:  Any=True,  lowerCamelCase							:  int=99,  lowerCamelCase							:  List[Any]=32,  lowerCamelCase							:  Any=5,  lowerCamelCase							:  List[str]=4,  lowerCamelCase							:  List[str]=37,  lowerCamelCase							:  List[Any]="gelu",  lowerCamelCase							:  Dict=0.1,  lowerCamelCase							:  Any=0.1,  lowerCamelCase							:  Dict=512,  lowerCamelCase							:  Tuple=16,  lowerCamelCase							:  int=2,  lowerCamelCase							:  int=0.02,  lowerCamelCase							:  Dict=False,  lowerCamelCase							:  List[Any]=True,  lowerCamelCase							:  List[str]="None",  lowerCamelCase							:  Optional[int]=3,  lowerCamelCase							:  Optional[int]=4,  lowerCamelCase							:  Optional[int]=None,  )->					Union[str, Any]:
								lowerCamelCase__		:		Any			=parent
								lowerCamelCase__		:		Tuple			=batch_size
								lowerCamelCase__		:		str			=seq_length
								lowerCamelCase__		:		int			=is_training
								lowerCamelCase__		:		str			=use_input_mask
								lowerCamelCase__		:		Dict			=use_token_type_ids
								lowerCamelCase__		:		List[str]			=use_labels
								lowerCamelCase__		:		List[str]			=vocab_size
								lowerCamelCase__		:		Union[str, Any]			=hidden_size
								lowerCamelCase__		:		int			=num_hidden_layers
								lowerCamelCase__		:		int			=num_attention_heads
								lowerCamelCase__		:		Optional[Any]			=intermediate_size
								lowerCamelCase__		:		Any			=hidden_act
								lowerCamelCase__		:		List[Any]			=hidden_dropout_prob
								lowerCamelCase__		:		str			=attention_probs_dropout_prob
								lowerCamelCase__		:		Union[str, Any]			=max_position_embeddings
								lowerCamelCase__		:		List[Any]			=type_vocab_size
								lowerCamelCase__		:		Union[str, Any]			=type_sequence_label_size
								lowerCamelCase__		:		Dict			=initializer_range
								lowerCamelCase__		:		str			=num_labels
								lowerCamelCase__		:		Optional[Any]			=num_choices
								lowerCamelCase__		:		Dict			=relative_attention
								lowerCamelCase__		:		Optional[Any]			=position_biased_input
								lowerCamelCase__		:		Dict			=pos_att_type
								lowerCamelCase__		:		Optional[int]			=scope



					def 		snake_case       (       self							:  Any     )->					str:
								lowerCamelCase__		:		List[str]			=ids_tensor([self.batch_size, self.seq_length],  self.vocab_size     )

								lowerCamelCase__		:		Optional[Any]			=None
								if self.use_input_mask:
											lowerCamelCase__		:		List[Any]			=ids_tensor([self.batch_size, self.seq_length],  vocab_size=2     )

								lowerCamelCase__		:		str			=None
								if self.use_token_type_ids:
											lowerCamelCase__		:		Optional[int]			=ids_tensor([self.batch_size, self.seq_length],  self.type_vocab_size     )

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

								lowerCamelCase__		:		Union[str, Any]			=self.get_config()

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



					def 		snake_case       (       self							:  Any     )->					List[str]:
								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 		snake_case       (       self							:  Dict     )->					Dict:
								lowerCamelCase__		:		List[Any]			=self.get_config()
								lowerCamelCase__		:		Dict			=300
								return config



					def 		snake_case       (       self							:  List[str],  lowerCamelCase							:  List[Any]     )->					Union[str, Any]:
								self.parent.assertListEqual(list(result.loss.size()     ),  []     )



					def 		snake_case       (       self							:  Optional[int],  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  str,  lowerCamelCase							:  int,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Tuple     )->					Optional[int]:
								lowerCamelCase__		:		Any			=DebertaModel(config=SCREAMING_SNAKE_CASE__     )
								model.to(SCREAMING_SNAKE_CASE__     )
								model.eval()
								lowerCamelCase__		:		int			=model(SCREAMING_SNAKE_CASE__,  attention_mask=SCREAMING_SNAKE_CASE__,  token_type_ids=SCREAMING_SNAKE_CASE__     )[0]
								lowerCamelCase__		:		Union[str, Any]			=model(SCREAMING_SNAKE_CASE__,  token_type_ids=SCREAMING_SNAKE_CASE__     )[0]
								lowerCamelCase__		:		int			=model(SCREAMING_SNAKE_CASE__     )[0]

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



					def 		snake_case       (       self							:  str,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  int,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Dict,  lowerCamelCase							:  List[str]     )->					List[str]:
								lowerCamelCase__		:		List[str]			=DebertaForMaskedLM(config=SCREAMING_SNAKE_CASE__     )
								model.to(SCREAMING_SNAKE_CASE__     )
								model.eval()
								lowerCamelCase__		:		List[str]			=model(SCREAMING_SNAKE_CASE__,  attention_mask=SCREAMING_SNAKE_CASE__,  token_type_ids=SCREAMING_SNAKE_CASE__,  labels=SCREAMING_SNAKE_CASE__     )

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



					def 		snake_case       (       self							:  Tuple,  lowerCamelCase							:  Dict,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  int,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Dict     )->					List[str]:
								lowerCamelCase__		:		str			=self.num_labels
								lowerCamelCase__		:		Tuple			=DebertaForSequenceClassification(SCREAMING_SNAKE_CASE__     )
								model.to(SCREAMING_SNAKE_CASE__     )
								model.eval()
								lowerCamelCase__		:		Optional[Any]			=model(SCREAMING_SNAKE_CASE__,  attention_mask=SCREAMING_SNAKE_CASE__,  token_type_ids=SCREAMING_SNAKE_CASE__,  labels=SCREAMING_SNAKE_CASE__     )
								self.parent.assertListEqual(list(result.logits.size()     ),  [self.batch_size, self.num_labels]     )
								self.check_loss_output(SCREAMING_SNAKE_CASE__     )



					def 		snake_case       (       self							:  Optional[int],  lowerCamelCase							:  Any,  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  Any,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  List[str],  lowerCamelCase							:  int,  lowerCamelCase							:  Optional[int]     )->					Any:
								lowerCamelCase__		:		Optional[int]			=self.num_labels
								lowerCamelCase__		:		str			=DebertaForTokenClassification(config=SCREAMING_SNAKE_CASE__     )
								model.to(SCREAMING_SNAKE_CASE__     )
								model.eval()
								lowerCamelCase__		:		Optional[int]			=model(SCREAMING_SNAKE_CASE__,  attention_mask=SCREAMING_SNAKE_CASE__,  token_type_ids=SCREAMING_SNAKE_CASE__,  labels=SCREAMING_SNAKE_CASE__     )
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.seq_length, self.num_labels)     )



					def 		snake_case       (       self							:  int,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  str,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Any,  lowerCamelCase							:  str     )->					Any:
								lowerCamelCase__		:		List[Any]			=DebertaForQuestionAnswering(config=SCREAMING_SNAKE_CASE__     )
								model.to(SCREAMING_SNAKE_CASE__     )
								model.eval()
								lowerCamelCase__		:		Dict			=model(
								    SCREAMING_SNAKE_CASE__,  attention_mask=SCREAMING_SNAKE_CASE__,  token_type_ids=SCREAMING_SNAKE_CASE__,  start_positions=SCREAMING_SNAKE_CASE__,  end_positions=SCREAMING_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 		snake_case       (       self							:  str     )->					str:
								lowerCamelCase__		:		List[Any]			=self.prepare_config_and_inputs()
								(
								    (
								    lowerCamelCase__    
								)	,   (
								    lowerCamelCase__    
								)	,   (
								    lowerCamelCase__    
								)	,   (
								    lowerCamelCase__    
								)	,   (
								    lowerCamelCase__    
								)	,   (
								    lowerCamelCase__    
								)	,   (
								    lowerCamelCase__    
								)	,       
								)		:		Optional[Any]			=config_and_inputs
								lowerCamelCase__		:		Tuple			={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict





@require_torch
class        __SCREAMING_SNAKE_CASE	(      __lowercase		,   __lowercase		,   unittest.TestCase   ):


					'''simple docstring'''





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

					_a   			=							True
					_a   			=							False
					_a   			=							False
					_a   			=							False
					_a   			=							False



					def 		snake_case       (       self							:  List[str]     )->					Tuple:
								lowerCamelCase__		:		Optional[Any]			=DebertaModelTester(self     )
								lowerCamelCase__		:		str			=ConfigTester(self,  config_class=SCREAMING_SNAKE_CASE__,  hidden_size=37     )



					def 		snake_case       (       self							:  Optional[int]     )->					Any:
								self.config_tester.run_common_tests()



					def 		snake_case       (       self							:  Optional[int]     )->					Union[str, Any]:
								lowerCamelCase__		:		Optional[int]			=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*SCREAMING_SNAKE_CASE__     )



					def 		snake_case       (       self							:  List[str]     )->					Optional[Any]:
								lowerCamelCase__		:		Tuple			=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*SCREAMING_SNAKE_CASE__     )



					def 		snake_case       (       self							:  Any     )->					List[Any]:
								lowerCamelCase__		:		int			=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*SCREAMING_SNAKE_CASE__     )



					def 		snake_case       (       self							:  List[Any]     )->					Optional[Any]:
								lowerCamelCase__		:		str			=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*SCREAMING_SNAKE_CASE__     )



					def 		snake_case       (       self							:  Any     )->					Dict:
								lowerCamelCase__		:		int			=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*SCREAMING_SNAKE_CASE__     )




					@slow
					def 		snake_case       (       self							:  Tuple     )->					Optional[int]:
								for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											lowerCamelCase__		:		Dict			=DebertaModel.from_pretrained(SCREAMING_SNAKE_CASE__     )
											self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )





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


					'''simple docstring'''





					@unittest.skip(reason='''Model not available yet'''     )
					def 		snake_case       (       self							:  Dict     )->					List[str]:
								pass




					@slow
					def 		snake_case       (       self							:  Optional[Any]     )->					Optional[Any]:
								lowerCamelCase__		:		Optional[int]			=DebertaModel.from_pretrained('''microsoft/deberta-base'''     )

								lowerCamelCase__		:		Union[str, Any]			=torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]     )
								lowerCamelCase__		:		Union[str, Any]			=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
								with torch.no_grad():
											lowerCamelCase__		:		Tuple			=model(SCREAMING_SNAKE_CASE__,  attention_mask=SCREAMING_SNAKE_CASE__     )[0]
								# compare the actual values for a slice.
								lowerCamelCase__		:		Tuple			=torch.tensor(
								    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]]     )
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4],  SCREAMING_SNAKE_CASE__,  atol=1E-4     ),  F'''{output[:, 1:4, 1:4]}'''     )






import shutil
import tempfile
import unittest
from unittest.mock import patch

from transformers import (
    DefaultFlowCallback,
    IntervalStrategy,
    PrinterCallback,
    ProgressCallback,
    Trainer,
    TrainerCallback,
    TrainingArguments,
    is_torch_available,
)
from transformers.testing_utils import require_torch


if is_torch_available():
					from transformers.trainer import DEFAULT_CALLBACKS

					from .test_trainer import RegressionDataset, RegressionModelConfig, RegressionPreTrainedModel

class    lowerCAmelCase__     (	__lowercase			):






		def __init__(		self		:							int  )     ->							Optional[int]:
						__lowerCamelCase    					=	[]






		def  __A       (		self		:							Any							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							str							,			**SCREAMING_SNAKE_CASE__		:							List[Any]  )     ->							Tuple:
						self.events.append('''on_init_end'''  )






		def  __A       (		self		:							Tuple							,			SCREAMING_SNAKE_CASE__		:							Optional[int]							,			SCREAMING_SNAKE_CASE__		:							Optional[Any]							,			SCREAMING_SNAKE_CASE__		:							Optional[int]							,			**SCREAMING_SNAKE_CASE__		:							Optional[Any]  )     ->							Any:
						self.events.append('''on_train_begin'''  )






		def  __A       (		self		:							str							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							Any							,			SCREAMING_SNAKE_CASE__		:							Dict							,			**SCREAMING_SNAKE_CASE__		:							int  )     ->							Any:
						self.events.append('''on_train_end'''  )






		def  __A       (		self		:							Union[str, Any]							,			SCREAMING_SNAKE_CASE__		:							Dict							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			**SCREAMING_SNAKE_CASE__		:							List[Any]  )     ->							int:
						self.events.append('''on_epoch_begin'''  )






		def  __A       (		self		:							Optional[Any]							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							Any							,			SCREAMING_SNAKE_CASE__		:							Optional[Any]							,			**SCREAMING_SNAKE_CASE__		:							Tuple  )     ->							Optional[Any]:
						self.events.append('''on_epoch_end'''  )






		def  __A       (		self		:							str							,			SCREAMING_SNAKE_CASE__		:							Tuple							,			SCREAMING_SNAKE_CASE__		:							Optional[Any]							,			SCREAMING_SNAKE_CASE__		:							Union[str, Any]							,			**SCREAMING_SNAKE_CASE__		:							str  )     ->							List[Any]:
						self.events.append('''on_step_begin'''  )






		def  __A       (		self		:							Any							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							Any							,			**SCREAMING_SNAKE_CASE__		:							Optional[int]  )     ->							Tuple:
						self.events.append('''on_step_end'''  )






		def  __A       (		self		:							int							,			SCREAMING_SNAKE_CASE__		:							List[str]							,			SCREAMING_SNAKE_CASE__		:							List[str]							,			SCREAMING_SNAKE_CASE__		:							int							,			**SCREAMING_SNAKE_CASE__		:							List[Any]  )     ->							Union[str, Any]:
						self.events.append('''on_evaluate'''  )






		def  __A       (		self		:							Union[str, Any]							,			SCREAMING_SNAKE_CASE__		:							List[str]							,			SCREAMING_SNAKE_CASE__		:							List[str]							,			SCREAMING_SNAKE_CASE__		:							str							,			**SCREAMING_SNAKE_CASE__		:							str  )     ->							str:
						self.events.append('''on_predict'''  )






		def  __A       (		self		:							Optional[int]							,			SCREAMING_SNAKE_CASE__		:							int							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							Optional[int]							,			**SCREAMING_SNAKE_CASE__		:							Optional[Any]  )     ->							Tuple:
						self.events.append('''on_save'''  )






		def  __A       (		self		:							Optional[int]							,			SCREAMING_SNAKE_CASE__		:							Dict							,			SCREAMING_SNAKE_CASE__		:							Union[str, Any]							,			SCREAMING_SNAKE_CASE__		:							Union[str, Any]							,			**SCREAMING_SNAKE_CASE__		:							List[str]  )     ->							List[str]:
						self.events.append('''on_log'''  )







		def  __A       (		self		:							int							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							List[str]							,			SCREAMING_SNAKE_CASE__		:							List[Any]							,			**SCREAMING_SNAKE_CASE__		:							Optional[int]  )     ->							str:
						self.events.append('''on_prediction_step'''  )





@require_torch
class    lowerCAmelCase__     (	unittest.TestCase			):






		def  __A       (		self		:							Union[str, Any]  )     ->							Optional[Any]:
						__lowerCamelCase    					=	tempfile.mkdtemp()






		def  __A       (		self		:							int  )     ->							List[str]:
						shutil.rmtree(self.output_dir  )






		def  __A       (		self		:							Tuple							,			SCREAMING_SNAKE_CASE__		:							List[Any]=0							,			SCREAMING_SNAKE_CASE__		:							Any=0							,			SCREAMING_SNAKE_CASE__		:							List[str]=64							,			SCREAMING_SNAKE_CASE__		:							Optional[int]=64							,			SCREAMING_SNAKE_CASE__		:							Optional[int]=None							,			SCREAMING_SNAKE_CASE__		:							Optional[int]=False							,			**SCREAMING_SNAKE_CASE__		:							Optional[Any]  )     ->							Union[str, Any]:
						# disable_tqdm in TrainingArguments has a flaky default since it depends on the level of logging. We make sure
						# its set to False since the tests later on depend on its value.
						__lowerCamelCase    					=	RegressionDataset(length=SCREAMING_SNAKE_CASE__  )
						__lowerCamelCase    					=	RegressionDataset(length=SCREAMING_SNAKE_CASE__  )
						__lowerCamelCase    					=	RegressionModelConfig(a=SCREAMING_SNAKE_CASE__							,			b=SCREAMING_SNAKE_CASE__  )
						__lowerCamelCase    					=	RegressionPreTrainedModel(SCREAMING_SNAKE_CASE__  )

						__lowerCamelCase    					=	TrainingArguments(self.output_dir							,			disable_tqdm=SCREAMING_SNAKE_CASE__							,			report_to=[]							,			**SCREAMING_SNAKE_CASE__  )
						return Trainer(
						    SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__							,			train_dataset=SCREAMING_SNAKE_CASE__							,			eval_dataset=SCREAMING_SNAKE_CASE__							,			callbacks=SCREAMING_SNAKE_CASE__							,			)






		def  __A       (		self		:							List[Any]							,			SCREAMING_SNAKE_CASE__		:							List[str]							,			SCREAMING_SNAKE_CASE__		:							str  )     ->							Optional[int]:
						self.assertEqual(len(SCREAMING_SNAKE_CASE__  )							,			len(SCREAMING_SNAKE_CASE__  )  )

						# Order doesn't matter
						__lowerCamelCase    					=	sorted(SCREAMING_SNAKE_CASE__							,			key=lambda SCREAMING_SNAKE_CASE__  : cb.__name__ if isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ) else cb.__class__.__name__  )
						__lowerCamelCase    					=	sorted(SCREAMING_SNAKE_CASE__							,			key=lambda SCREAMING_SNAKE_CASE__  : cb.__name__ if isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ) else cb.__class__.__name__  )

						for cba, cba in zip(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ):
										if isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ) and isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ):
														self.assertEqual(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  )
										elif isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ) and not isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ):
														self.assertEqual(SCREAMING_SNAKE_CASE__							,			cba.__class__  )
										elif not isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ) and isinstance(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  ):
														self.assertEqual(cba.__class__							,			SCREAMING_SNAKE_CASE__  )
										else:
														self.assertEqual(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  )






		def  __A       (		self		:							Union[str, Any]							,			SCREAMING_SNAKE_CASE__		:							Optional[int]  )     ->							Tuple:
						__lowerCamelCase    					=	['''on_init_end''', '''on_train_begin''']
						__lowerCamelCase    					=	0
						__lowerCamelCase    					=	len(trainer.get_eval_dataloader()  )
						__lowerCamelCase    					=	['''on_prediction_step'''] * len(trainer.get_eval_dataloader()  ) + ['''on_log''', '''on_evaluate''']
						for _ in range(trainer.state.num_train_epochs  ):
										expected_events.append('''on_epoch_begin'''  )
										for _ in range(SCREAMING_SNAKE_CASE__  ):
														step += 1
														expected_events += ["on_step_begin", "on_step_end"]
														if step % trainer.args.logging_steps == 0:
																		expected_events.append('''on_log'''  )
														if trainer.args.evaluation_strategy == IntervalStrategy.STEPS and step % trainer.args.eval_steps == 0:
																		expected_events += evaluation_events.copy()
														if step % trainer.args.save_steps == 0:
																		expected_events.append('''on_save'''  )
										expected_events.append('''on_epoch_end'''  )
										if trainer.args.evaluation_strategy == IntervalStrategy.EPOCH:
														expected_events += evaluation_events.copy()
						expected_events += ["on_log", "on_train_end"]
						return expected_events






		def  __A       (		self		:							Union[str, Any]  )     ->							int:
						__lowerCamelCase    					=	self.get_trainer()
						__lowerCamelCase    					=	DEFAULT_CALLBACKS.copy() + [ProgressCallback]
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						# Callbacks passed at init are added to the default callbacks
						__lowerCamelCase    					=	self.get_trainer(callbacks=[MyTestTrainerCallback]  )
						expected_callbacks.append(SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						# TrainingArguments.disable_tqdm controls if use ProgressCallback or PrinterCallback
						__lowerCamelCase    					=	self.get_trainer(disable_tqdm=SCREAMING_SNAKE_CASE__  )
						__lowerCamelCase    					=	DEFAULT_CALLBACKS.copy() + [PrinterCallback]
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )






		def  __A       (		self		:							List[Any]  )     ->							str:
						__lowerCamelCase    					=	DEFAULT_CALLBACKS.copy() + [ProgressCallback]
						__lowerCamelCase    					=	self.get_trainer()

						# We can add, pop, or remove by class name
						trainer.remove_callback(SCREAMING_SNAKE_CASE__  )
						expected_callbacks.remove(SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						__lowerCamelCase    					=	self.get_trainer()
						__lowerCamelCase    					=	trainer.pop_callback(SCREAMING_SNAKE_CASE__  )
						self.assertEqual(cb.__class__							,			SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						trainer.add_callback(SCREAMING_SNAKE_CASE__  )
						expected_callbacks.insert(0							,			SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						# We can also add, pop, or remove by instance
						__lowerCamelCase    					=	self.get_trainer()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[0]
						trainer.remove_callback(SCREAMING_SNAKE_CASE__  )
						expected_callbacks.remove(SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						__lowerCamelCase    					=	self.get_trainer()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[0]
						__lowerCamelCase    					=	trainer.pop_callback(SCREAMING_SNAKE_CASE__  )
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )

						trainer.add_callback(SCREAMING_SNAKE_CASE__  )
						expected_callbacks.insert(0							,			SCREAMING_SNAKE_CASE__  )
						self.check_callbacks_equality(trainer.callback_handler.callbacks							,			SCREAMING_SNAKE_CASE__  )







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

						# XXX: for now ignore scatter_gather warnings in this test since it's not relevant to what's being tested
						warnings.simplefilter(action='''ignore'''							,			category=SCREAMING_SNAKE_CASE__  )

						__lowerCamelCase    					=	self.get_trainer(callbacks=[MyTestTrainerCallback]  )
						trainer.train()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[-2].events
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			self.get_expected_events(SCREAMING_SNAKE_CASE__  )  )

						# Independent log/save/eval
						__lowerCamelCase    					=	self.get_trainer(callbacks=[MyTestTrainerCallback]							,			logging_steps=5  )
						trainer.train()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[-2].events
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			self.get_expected_events(SCREAMING_SNAKE_CASE__  )  )

						__lowerCamelCase    					=	self.get_trainer(callbacks=[MyTestTrainerCallback]							,			save_steps=5  )
						trainer.train()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[-2].events
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			self.get_expected_events(SCREAMING_SNAKE_CASE__  )  )

						__lowerCamelCase    					=	self.get_trainer(callbacks=[MyTestTrainerCallback]							,			eval_steps=5							,			evaluation_strategy='''steps'''  )
						trainer.train()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[-2].events
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			self.get_expected_events(SCREAMING_SNAKE_CASE__  )  )

						__lowerCamelCase    					=	self.get_trainer(callbacks=[MyTestTrainerCallback]							,			evaluation_strategy='''epoch'''  )
						trainer.train()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[-2].events
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			self.get_expected_events(SCREAMING_SNAKE_CASE__  )  )

						# A bit of everything
						__lowerCamelCase    					=	self.get_trainer(
						    callbacks=[MyTestTrainerCallback]							,			logging_steps=3							,			save_steps=10							,			eval_steps=5							,			evaluation_strategy='''steps'''							,			)
						trainer.train()
						__lowerCamelCase    					=	trainer.callback_handler.callbacks[-2].events
						self.assertEqual(SCREAMING_SNAKE_CASE__							,			self.get_expected_events(SCREAMING_SNAKE_CASE__  )  )

						# warning should be emitted for duplicated callbacks
						with patch('''transformers.trainer_callback.logger.warning'''  ) as warn_mock:
										__lowerCamelCase    					=	self.get_trainer(
										    callbacks=[MyTestTrainerCallback, MyTestTrainerCallback]							,			)
										assert str(SCREAMING_SNAKE_CASE__  ) in warn_mock.call_args[0][0]



