





import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roberta import RobertaTokenizer


_lowerCamelCase 					=      logging.get_logger(__name__)

_lowerCamelCase 					=      {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

_lowerCamelCase 					=      {
    'vocab_file': {
        'roberta-base': 'https://huggingface.co/roberta-base/resolve/main/vocab.json',
        'roberta-large': 'https://huggingface.co/roberta-large/resolve/main/vocab.json',
        'roberta-large-mnli': 'https://huggingface.co/roberta-large-mnli/resolve/main/vocab.json',
        'distilroberta-base': 'https://huggingface.co/distilroberta-base/resolve/main/vocab.json',
        'roberta-base-openai-detector': 'https://huggingface.co/roberta-base-openai-detector/resolve/main/vocab.json',
        'roberta-large-openai-detector': (
            'https://huggingface.co/roberta-large-openai-detector/resolve/main/vocab.json'
        ),
    },
    'merges_file': {
        'roberta-base': 'https://huggingface.co/roberta-base/resolve/main/merges.txt',
        'roberta-large': 'https://huggingface.co/roberta-large/resolve/main/merges.txt',
        'roberta-large-mnli': 'https://huggingface.co/roberta-large-mnli/resolve/main/merges.txt',
        'distilroberta-base': 'https://huggingface.co/distilroberta-base/resolve/main/merges.txt',
        'roberta-base-openai-detector': 'https://huggingface.co/roberta-base-openai-detector/resolve/main/merges.txt',
        'roberta-large-openai-detector': (
            'https://huggingface.co/roberta-large-openai-detector/resolve/main/merges.txt'
        ),
    },
    'tokenizer_file': {
        'roberta-base': 'https://huggingface.co/roberta-base/resolve/main/tokenizer.json',
        'roberta-large': 'https://huggingface.co/roberta-large/resolve/main/tokenizer.json',
        'roberta-large-mnli': 'https://huggingface.co/roberta-large-mnli/resolve/main/tokenizer.json',
        'distilroberta-base': 'https://huggingface.co/distilroberta-base/resolve/main/tokenizer.json',
        'roberta-base-openai-detector': (
            'https://huggingface.co/roberta-base-openai-detector/resolve/main/tokenizer.json'
        ),
        'roberta-large-openai-detector': (
            'https://huggingface.co/roberta-large-openai-detector/resolve/main/tokenizer.json'
        ),
    },
}

_lowerCamelCase 					=      {
    'roberta-base': 512,
    'roberta-large': 512,
    'roberta-large-mnli': 512,
    'distilroberta-base': 512,
    'roberta-base-openai-detector': 512,
    'roberta-large-openai-detector': 512,
}




class 	UpperCamelCase_							(  UpperCamelCase__     ):
							lowerCamelCase_							     =       VOCAB_FILES_NAMES
							lowerCamelCase_							     =       PRETRAINED_VOCAB_FILES_MAP
							lowerCamelCase_							     =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowerCamelCase_							     =       ["input_ids", "attention_mask"]
							lowerCamelCase_							     =       RobertaTokenizer


							def __init__(				self     :List[Any]				,					__A     :Tuple=None				,					__A     :str=None				,					__A     :Tuple=None				,					__A     :Tuple="replace"				,					__A     :List[Any]="<s>"				,					__A     :Union[str, Any]="</s>"				,					__A     :Any="</s>"				,					__A     :Dict="<s>"				,					__A     :Optional[Any]="<unk>"				,					__A     :List[str]="<pad>"				,					__A     :Any="<mask>"				,					__A     :Dict=False				,					__A     :Tuple=True				,					**__A     :Optional[Any]				,					) -> Optional[Any]:



									"""simple docstring"""



									super().__init__(
									    __A				,					__A				,					tokenizer_file=__A				,					errors=__A				,					bos_token=__A				,					eos_token=__A				,					sep_token=__A				,					cls_token=__A				,					unk_token=__A				,					pad_token=__A				,					mask_token=__A				,					add_prefix_space=__A				,					trim_offsets=__A				,					**__A				,					)

									SCREAMING_SNAKE_CASE__								=   json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()		)
									if pre_tok_state.get("""add_prefix_space"""				,					__A		) != add_prefix_space:
											SCREAMING_SNAKE_CASE__								=   getattr(__A				,					pre_tok_state.pop("""type"""		)		)
											SCREAMING_SNAKE_CASE__								=   add_prefix_space
											SCREAMING_SNAKE_CASE__								=   pre_tok_class(**__A		)

									SCREAMING_SNAKE_CASE__								=   add_prefix_space

									SCREAMING_SNAKE_CASE__								=   """post_processor"""
									SCREAMING_SNAKE_CASE__								=   getattr(self.backend_tokenizer				,					__A				,					__A		)
									if tokenizer_component_instance:
											SCREAMING_SNAKE_CASE__								=   json.loads(tokenizer_component_instance.__getstate__()		)

											# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
											if "sep" in state:
													SCREAMING_SNAKE_CASE__								=   tuple(state["""sep"""]		)
											if "cls" in state:
													SCREAMING_SNAKE_CASE__								=   tuple(state["""cls"""]		)

											SCREAMING_SNAKE_CASE__								=   False

											if state.get("""add_prefix_space"""				,					__A		) != add_prefix_space:
													SCREAMING_SNAKE_CASE__								=   add_prefix_space
													SCREAMING_SNAKE_CASE__								=   True

											if state.get("""trim_offsets"""				,					__A		) != trim_offsets:
													SCREAMING_SNAKE_CASE__								=   trim_offsets
													SCREAMING_SNAKE_CASE__								=   True

											if changes_to_apply:
													SCREAMING_SNAKE_CASE__								=   getattr(__A				,					state.pop("""type"""		)		)
													SCREAMING_SNAKE_CASE__								=   component_class(**__A		)
													setattr(self.backend_tokenizer				,					__A				,					__A		)


							@property
							def   _snake_case	(				self     :str		) -> str:



									"""simple docstring"""



									if self._mask_token is None:
											if self.verbose:
													logger.error("""Using mask_token, but it is not set yet."""		)
											return None
									return str(self._mask_token		)


							@mask_token.setter
							def   _snake_case	(				self     :List[str]				,					__A     :Tuple		) -> List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   AddedToken(__A				,					lstrip=__A				,					rstrip=__A		) if isinstance(__A				,					__A		) else value
									SCREAMING_SNAKE_CASE__								=   value


							def   _snake_case	(				self     :str				,					*__A     :int				,					**__A     :Tuple		) -> BatchEncoding:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   kwargs.get("""is_split_into_words"""				,					__A		)
									assert self.add_prefix_space or not is_split_into_words, (
									    f'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
									    "to use it with pretokenized inputs."
									)

									return super()._batch_encode_plus(*__A				,					**__A		)


							def   _snake_case	(				self     :Optional[Any]				,					*__A     :List[Any]				,					**__A     :Dict		) -> BatchEncoding:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   kwargs.get("""is_split_into_words"""				,					__A		)

									assert self.add_prefix_space or not is_split_into_words, (
									    f'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
									    "to use it with pretokenized inputs."
									)

									return super()._encode_plus(*__A				,					**__A		)


							def   _snake_case	(				self     :int				,					__A     :str				,					__A     :Optional[str] = None		) -> Tuple[str]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self._tokenizer.model.save(__A				,					name=__A		)
									return tuple(__A		)


							def   _snake_case	(				self     :Dict				,					__A     :Union[str, Any]				,					__A     :Optional[Any]=None		) -> Union[str, Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   [self.bos_token_id] + token_ids_a + [self.eos_token_id]
									if token_ids_a is None:
											return output

									return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]


							def   _snake_case	(				self     :Optional[int]				,					__A     :List[int]				,					__A     :Optional[List[int]] = None		) -> List[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   [self.sep_token_id]
									SCREAMING_SNAKE_CASE__								=   [self.cls_token_id]

									if token_ids_a is None:
											return len(cls + token_ids_a + sep		) * [0]
									return len(cls + token_ids_a + sep + sep + token_ids_a + sep		) * [0]

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    _snake_case (						UpperCAmelCase_				):


 def __init__(       self):


   '''simple docstring'''




   lowercase__	: List[Any]     		=   []


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_init_end""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_train_begin""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_train_end""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_epoch_begin""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_epoch_end""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_step_begin""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_step_end""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_evaluate""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_predict""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_save""")


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_log""")



 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.events.append("""on_prediction_step""")



@require_torch
class    _snake_case (						unittest.TestCase				):


 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: Dict     		=   tempfile.mkdtemp()


 def   lowercase__  (       self):


   '''simple docstring'''




   shutil.rmtree(self.output_dir)


 def   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_=0       ,	SCREAMING_SNAKE_CASE_=0       ,	SCREAMING_SNAKE_CASE_=64       ,	SCREAMING_SNAKE_CASE_=64       ,	SCREAMING_SNAKE_CASE_=None       ,	SCREAMING_SNAKE_CASE_=False       ,	**SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__	: Any     		=   RegressionDataset(length=SCREAMING_SNAKE_CASE_)
   lowercase__	: Optional[int]     		=   RegressionDataset(length=SCREAMING_SNAKE_CASE_)
   lowercase__	: Dict     		=   RegressionModelConfig(a=SCREAMING_SNAKE_CASE_       ,	b=SCREAMING_SNAKE_CASE_)
   lowercase__	: Any     		=   RegressionPreTrainedModel(SCREAMING_SNAKE_CASE_)

   lowercase__	: Any     		=   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   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   self.assertEqual(len(SCREAMING_SNAKE_CASE_)       ,	len(SCREAMING_SNAKE_CASE_))

   # Order doesn't matter
   lowercase__	: str     		=   sorted(SCREAMING_SNAKE_CASE_       ,	key=lambda SCREAMING_SNAKE_CASE_: cb.__name__ if isinstance(SCREAMING_SNAKE_CASE_       ,	SCREAMING_SNAKE_CASE_) else cb.__class__.__name__)
   lowercase__	: Tuple     		=   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   lowercase__  (       self       ,	SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__	: int     		=   ["""on_init_end""", """on_train_begin"""]
   lowercase__	: Union[str, Any]     		=   0
   lowercase__	: Union[str, Any]     		=   len(trainer.get_eval_dataloader())
   lowercase__	: Dict     		=   ["""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   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: int     		=   self.get_trainer()
   lowercase__	: Union[str, Any]     		=   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
   lowercase__	: Any     		=   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
   lowercase__	: Any     		=   self.get_trainer(disable_tqdm=SCREAMING_SNAKE_CASE_)
   lowercase__	: Tuple     		=   DEFAULT_CALLBACKS.copy() + [PrinterCallback]
   self.check_callbacks_equality(trainer.callback_handler.callbacks       ,	SCREAMING_SNAKE_CASE_)


 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: Any     		=   DEFAULT_CALLBACKS.copy() + [ProgressCallback]
   lowercase__	: Tuple     		=   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_)

   lowercase__	: Optional[int]     		=   self.get_trainer()
   lowercase__	: List[Any]     		=   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
   lowercase__	: Union[str, Any]     		=   self.get_trainer()
   lowercase__	: Optional[Any]     		=   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_)

   lowercase__	: str     		=   self.get_trainer()
   lowercase__	: Optional[Any]     		=   trainer.callback_handler.callbacks[0]
   lowercase__	: Union[str, Any]     		=   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   lowercase__  (       self):


   '''simple docstring'''




   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_)

   lowercase__	: Union[str, Any]     		=   self.get_trainer(callbacks=[MyTestTrainerCallback])
   trainer.train()
   lowercase__	: Union[str, Any]     		=   trainer.callback_handler.callbacks[-2].events
   self.assertEqual(SCREAMING_SNAKE_CASE_       ,	self.get_expected_events(SCREAMING_SNAKE_CASE_))

   # Independent log/save/eval
   lowercase__	: List[Any]     		=   self.get_trainer(callbacks=[MyTestTrainerCallback]       ,	logging_steps=5)
   trainer.train()
   lowercase__	: List[str]     		=   trainer.callback_handler.callbacks[-2].events
   self.assertEqual(SCREAMING_SNAKE_CASE_       ,	self.get_expected_events(SCREAMING_SNAKE_CASE_))

   lowercase__	: Optional[Any]     		=   self.get_trainer(callbacks=[MyTestTrainerCallback]       ,	save_steps=5)
   trainer.train()
   lowercase__	: Dict     		=   trainer.callback_handler.callbacks[-2].events
   self.assertEqual(SCREAMING_SNAKE_CASE_       ,	self.get_expected_events(SCREAMING_SNAKE_CASE_))

   lowercase__	: Any     		=   self.get_trainer(callbacks=[MyTestTrainerCallback]       ,	eval_steps=5       ,	evaluation_strategy="""steps""")
   trainer.train()
   lowercase__	: int     		=   trainer.callback_handler.callbacks[-2].events
   self.assertEqual(SCREAMING_SNAKE_CASE_       ,	self.get_expected_events(SCREAMING_SNAKE_CASE_))

   lowercase__	: Tuple     		=   self.get_trainer(callbacks=[MyTestTrainerCallback]       ,	evaluation_strategy="""epoch""")
   trainer.train()
   lowercase__	: Optional[int]     		=   trainer.callback_handler.callbacks[-2].events
   self.assertEqual(SCREAMING_SNAKE_CASE_       ,	self.get_expected_events(SCREAMING_SNAKE_CASE_))

   # A bit of everything
   lowercase__	: Any     		=   self.get_trainer(
       callbacks=[MyTestTrainerCallback]       ,	logging_steps=3       ,	save_steps=10       ,	eval_steps=5       ,	evaluation_strategy="""steps"""       ,	)
   trainer.train()
   lowercase__	: str     		=   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:
     lowercase__	: Dict     		=   self.get_trainer(
         callbacks=[MyTestTrainerCallback, MyTestTrainerCallback]       ,	)
     assert str(SCREAMING_SNAKE_CASE_) in warn_mock.call_args[0][0]






