





import argparse
import os
from pathlib import Path

import torch
from bark.generation import _load_model as _bark_load_model
from huggingface_hub import hf_hub_download

from transformers import EncodecConfig, EncodecModel, set_seed
from transformers.models.bark.configuration_bark import (
    BarkCoarseConfig,
    BarkConfig,
    BarkFineConfig,
    BarkSemanticConfig,
)
from transformers.models.bark.generation_configuration_bark import (
    BarkCoarseGenerationConfig,
    BarkFineGenerationConfig,
    BarkGenerationConfig,
    BarkSemanticGenerationConfig,
)
from transformers.models.bark.modeling_bark import BarkCoarseModel, BarkFineModel, BarkModel, BarkSemanticModel
from transformers.utils import logging


logging.set_verbosity_info()
_lowerCAmelCase								=  logging.get_logger(__name__)

set_seed(770)


_lowerCAmelCase								=  {
    """c_attn""": """att_proj""",
    """c_proj""": """out_proj""",
    """c_fc""": """in_proj""",
    """transformer.""": """""",
    """h.""": """layers.""",
    """ln_1""": """layernorm_1""",
    """ln_2""": """layernorm_2""",
    """ln_f""": """layernorm_final""",
    """wpe""": """position_embeds_layer""",
    """wte""": """input_embeds_layer""",
}


_lowerCAmelCase								=  {
    """text_small""": {
        """repo_id""": """suno/bark""",
        """file_name""": """text.pt""",
    },
    """coarse_small""": {
        """repo_id""": """suno/bark""",
        """file_name""": """coarse.pt""",
    },
    """fine_small""": {
        """repo_id""": """suno/bark""",
        """file_name""": """fine.pt""",
    },
    """text""": {
        """repo_id""": """suno/bark""",
        """file_name""": """text_2.pt""",
    },
    """coarse""": {
        """repo_id""": """suno/bark""",
        """file_name""": """coarse_2.pt""",
    },
    """fine""": {
        """repo_id""": """suno/bark""",
        """file_name""": """fine_2.pt""",
    },
}

_lowerCAmelCase								=  os.path.dirname(os.path.abspath(__file__))
_lowerCAmelCase								=  os.path.join(os.path.expanduser("""~"""), """.cache""")
_lowerCAmelCase								=  os.path.join(os.getenv("""XDG_CACHE_HOME""", default_cache_dir), """suno""", """bark_v0""")



def      _lowerCAmelCase		(	_lowerCAmelCase	,_lowerCAmelCase=False  ):
   '''simple docstring'''


   A_  :					Tuple         =						model_type
   if use_small:
      key += "_small"
   return os.path.join(__snake_case	,REMOTE_MODEL_PATHS[key]["""file_name"""]  )



def      _lowerCAmelCase		(	_lowerCAmelCase	,_lowerCAmelCase  ):
   '''simple docstring'''


   os.makedirs(__snake_case	,exist_ok=__snake_case  )
   hf_hub_download(repo_id=__snake_case	,filename=__snake_case	,local_dir=__snake_case  )



def      _lowerCAmelCase		(	_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase=False	,_lowerCAmelCase="text"  ):
   '''simple docstring'''


   if model_type == "text":
      A_  :					Optional[Any]         =						BarkSemanticModel
      A_  :					Dict         =						BarkSemanticConfig
      A_  :					Optional[int]         =						BarkSemanticGenerationConfig
   elif model_type == "coarse":
      A_  :					Dict         =						BarkCoarseModel
      A_  :					str         =						BarkCoarseConfig
      A_  :					List[Any]         =						BarkCoarseGenerationConfig
   elif model_type == "fine":
      A_  :					str         =						BarkFineModel
      A_  :					int         =						BarkFineConfig
      A_  :					int         =						BarkFineGenerationConfig
   else:
      raise NotImplementedError()
   A_  :					Optional[int]         =						f"""{model_type}_small""" if use_small else model_type
   A_  :					List[Any]         =						REMOTE_MODEL_PATHS[model_key]
   if not os.path.exists(__snake_case  ):
      logger.info(f"""{model_type} model not found, downloading into `{CACHE_DIR}`."""  )
      _download(model_info["""repo_id"""]	,model_info["""file_name"""]  )
   A_  :					int         =						torch.load(__snake_case	,map_location=__snake_case  )
   # this is a hack
   A_  :					Tuple         =						checkpoint["""model_args"""]
   if "input_vocab_size" not in model_args:
      A_  :					Tuple         =						model_args["""vocab_size"""]
      A_  :					List[str]         =						model_args["""vocab_size"""]
      del model_args["vocab_size"]

   # convert Bark model arguments to HF Bark model arguments
   A_  :					Optional[Any]         =						model_args.pop("""n_head"""  )
   A_  :					Dict         =						model_args.pop("""n_embd"""  )
   A_  :					int         =						model_args.pop("""n_layer"""  )

   A_  :					List[Any]         =						ConfigClass(**checkpoint["""model_args"""]  )
   A_  :					Optional[int]         =						ModelClass(config=__snake_case  )
   A_  :					List[str]         =						GenerationConfigClass()

   A_  :					List[str]         =						model_generation_config
   A_  :					int         =						checkpoint["""model"""]
   # fixup checkpoint
   A_  :					Tuple         =						"""_orig_mod."""
   for k, v in list(state_dict.items()  ):
      if k.startswith(__snake_case  ):
         # replace part of the key with corresponding layer name in HF implementation
         A_  :					int         =						k[len(__snake_case  ) :]
         for old_layer_name in new_layer_name_dict:
            A_  :					int         =						new_k.replace(__snake_case	,new_layer_name_dict[old_layer_name]  )

         A_  :					List[str]         =						state_dict.pop(__snake_case  )

   A_  :					str         =						set(state_dict.keys()  ) - set(model.state_dict().keys()  )
   A_  :					int         =						{k for k in extra_keys if not k.endswith(""".attn.bias"""  )}
   A_  :					Tuple         =						set(model.state_dict().keys()  ) - set(state_dict.keys()  )
   A_  :					Any         =						{k for k in missing_keys if not k.endswith(""".attn.bias"""  )}
   if len(__snake_case  ) != 0:
      raise ValueError(f"""extra keys found: {extra_keys}"""  )
   if len(__snake_case  ) != 0:
      raise ValueError(f"""missing keys: {missing_keys}"""  )
   model.load_state_dict(__snake_case	,strict=__snake_case  )
   A_  :					Dict         =						model.num_parameters(exclude_embeddings=__snake_case  )
   A_  :					List[str]         =						checkpoint["""best_val_loss"""].item()
   logger.info(f"""model loaded: {round(n_params/1e6	,1  )}M params, {round(__snake_case	,3  )} loss"""  )
   model.eval()
   model.to(__snake_case  )
   del checkpoint, state_dict

   return model



def      _lowerCAmelCase		(	_lowerCAmelCase	,_lowerCAmelCase=False	,_lowerCAmelCase="text"  ):
   '''simple docstring'''


   if model_type not in ("text", "coarse", "fine"):
      raise NotImplementedError()

   A_  :					Optional[int]         =						"""cpu"""  # do conversion on cpu

   A_  :					Optional[int]         =						_get_ckpt_path(__snake_case	,use_small=__snake_case  )
   A_  :					Any         =						_load_model(__snake_case	,__snake_case	,model_type=__snake_case	,use_small=__snake_case  )

   # load bark initial model
   A_  :					Dict         =						_bark_load_model(__snake_case	,"""cpu"""	,model_type=__snake_case	,use_small=__snake_case  )

   if model_type == "text":
      A_  :					List[Any]         =						bark_model["""model"""]

   if model.num_parameters(exclude_embeddings=__snake_case  ) != bark_model.get_num_params():
      raise ValueError("""initial and new models don\'t have the same number of parameters"""  )

   # check if same output as the bark model
   A_  :					Optional[int]         =						5
   A_  :					List[Any]         =						1_0

   if model_type in ["text", "coarse"]:
      A_  :					List[str]         =						torch.randint(2_5_6	,(batch_size, sequence_length)	,dtype=torch.int  )
      A_  :					List[Any]         =						bark_model(__snake_case  )[0]

      A_  :					Tuple         =						model(__snake_case  )

      # take last logits
      A_  :					Optional[int]         =						output_new_model_total.logits[:, [-1], :]

   else:
      A_  :					int         =						3
      A_  :					List[str]         =						8
      A_  :					Optional[int]         =						torch.randint(2_5_6	,(batch_size, sequence_length, n_codes_total)	,dtype=torch.int  )

      A_  :					Dict         =						model(__snake_case	,__snake_case  )
      A_  :					Optional[int]         =						bark_model(__snake_case	,__snake_case  )

      A_  :					int         =						output_new_model_total.logits

   # output difference should come from the difference of self-attention implementation design
   if output_new_model.shape != output_old_model.shape:
      raise ValueError("""initial and new outputs don\'t have the same shape"""  )
   if (output_new_model - output_old_model).abs().max().item() > 1e-3:
      raise ValueError("""initial and new outputs are not equal"""  )

   Path(__snake_case  ).mkdir(exist_ok=__snake_case  )
   model.save_pretrained(__snake_case  )



def      _lowerCAmelCase		(	_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,):
   '''simple docstring'''


   A_  :					str         =						os.path.join(__snake_case	,__snake_case  )

   A_  :					Optional[int]         =						BarkSemanticConfig.from_pretrained(os.path.join(__snake_case	,"""config.json"""  )  )
   A_  :					Union[str, Any]         =						BarkCoarseConfig.from_pretrained(os.path.join(__snake_case	,"""config.json"""  )  )
   A_  :					Dict         =						BarkFineConfig.from_pretrained(os.path.join(__snake_case	,"""config.json"""  )  )
   A_  :					str         =						EncodecConfig.from_pretrained("""facebook/encodec_24khz"""  )

   A_  :					List[Any]         =						BarkSemanticModel.from_pretrained(__snake_case  )
   A_  :					Optional[Any]         =						BarkCoarseModel.from_pretrained(__snake_case  )
   A_  :					Dict         =						BarkFineModel.from_pretrained(__snake_case  )
   A_  :					Any         =						EncodecModel.from_pretrained("""facebook/encodec_24khz"""  )

   A_  :					int         =						BarkConfig.from_sub_model_configs(
       __snake_case	,__snake_case	,__snake_case	,__snake_case  )

   A_  :					Optional[Any]         =						BarkGenerationConfig.from_sub_model_configs(
       semantic.generation_config	,coarseAcoustic.generation_config	,fineAcoustic.generation_config  )

   A_  :					Dict         =						BarkModel(__snake_case  )

   A_  :					Union[str, Any]         =						semantic
   A_  :					Tuple         =						coarseAcoustic
   A_  :					List[str]         =						fineAcoustic
   A_  :					Dict         =						codec

   A_  :					Union[str, Any]         =						bark_generation_config

   Path(__snake_case  ).mkdir(exist_ok=__snake_case  )
   bark.save_pretrained(__snake_case	,repo_id=__snake_case	,push_to_hub=__snake_case  )


if __name__ == "__main__":
      _lowerCAmelCase								=  argparse.ArgumentParser()
      # Required parameters

      parser.add_argument("""model_type""", type=str, help="""text, coarse or fine.""")
      parser.add_argument("""pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model.""")
      parser.add_argument("""--is_small""", action="""store_true""", help="""convert the small version instead of the large.""")

      _lowerCAmelCase								=  parser.parse_args()

      load_model(args.pytorch_dump_folder_path, model_type=args.model_type, use_small=args.is_small)














"""simple docstring"""
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        UpperCamelCase__ (				a_):







    """simple docstring"""







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





           '''simple docstring'''

           __magic_name__      				=    []







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





           '''simple docstring'''

           self.events.append('on_init_end' )







    def 				a__			(		self :	Any				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	List[str]				,    **UpperCamelCase_ :	str ):





           '''simple docstring'''

           self.events.append('on_train_begin' )







    def 				a__			(		self :	str				,    UpperCamelCase_ :	Tuple				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	Optional[int]				,    **UpperCamelCase_ :	Dict ):





           '''simple docstring'''

           self.events.append('on_train_end' )







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





           '''simple docstring'''

           self.events.append('on_epoch_begin' )







    def 				a__			(		self :	Optional[int]				,    UpperCamelCase_ :	List[Any]				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	Tuple				,    **UpperCamelCase_ :	List[Any] ):





           '''simple docstring'''

           self.events.append('on_epoch_end' )







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





           '''simple docstring'''

           self.events.append('on_step_begin' )







    def 				a__			(		self :	List[str]				,    UpperCamelCase_ :	Optional[Any]				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	Any				,    **UpperCamelCase_ :	List[Any] ):





           '''simple docstring'''

           self.events.append('on_step_end' )







    def 				a__			(		self :	List[Any]				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	Tuple				,    **UpperCamelCase_ :	Dict ):





           '''simple docstring'''

           self.events.append('on_evaluate' )







    def 				a__			(		self :	str				,    UpperCamelCase_ :	Any				,    UpperCamelCase_ :	Optional[int]				,    UpperCamelCase_ :	Dict				,    **UpperCamelCase_ :	Any ):





           '''simple docstring'''

           self.events.append('on_predict' )







    def 				a__			(		self :	Any				,    UpperCamelCase_ :	Optional[int]				,    UpperCamelCase_ :	Union[str, Any]				,    UpperCamelCase_ :	str				,    **UpperCamelCase_ :	Optional[int] ):





           '''simple docstring'''

           self.events.append('on_save' )







    def 				a__			(		self :	Optional[Any]				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	Union[str, Any]				,    **UpperCamelCase_ :	Optional[int] ):





           '''simple docstring'''

           self.events.append('on_log' )







    def 				a__			(		self :	List[Any]				,    UpperCamelCase_ :	Optional[int]				,    UpperCamelCase_ :	List[Any]				,    UpperCamelCase_ :	str				,    **UpperCamelCase_ :	List[Any] ):





           '''simple docstring'''

           self.events.append('on_prediction_step' )



@require_torch
class        UpperCamelCase__ (				unittest.TestCase):







    """simple docstring"""







    def 				a__			(		self :	Optional[Any] ):





           '''simple docstring'''

           __magic_name__      				=    tempfile.mkdtemp()







    def 				a__			(		self :	List[Any] ):





           '''simple docstring'''

           shutil.rmtree(self.output_dir )







    def 				a__			(		self :	List[str]				,    UpperCamelCase_ :	Optional[int]=0				,    UpperCamelCase_ :	List[Any]=0				,    UpperCamelCase_ :	Optional[int]=6_4				,    UpperCamelCase_ :	Optional[int]=6_4				,    UpperCamelCase_ :	List[Any]=None				,    UpperCamelCase_ :	Optional[Any]=False				,    **UpperCamelCase_ :	str ):





           '''simple docstring'''

           __magic_name__      				=    RegressionDataset(length=UpperCamelCase_ )
           __magic_name__      				=    RegressionDataset(length=UpperCamelCase_ )
           __magic_name__      				=    RegressionModelConfig(a=UpperCamelCase_				,    b=UpperCamelCase_ )
           __magic_name__      				=    RegressionPreTrainedModel(UpperCamelCase_ )

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







    def 				a__			(		self :	Optional[int]				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	Dict ):





           '''simple docstring'''

           self.assertEqual(len(UpperCamelCase_ )				,    len(UpperCamelCase_ ) )

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

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







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





           '''simple docstring'''

           __magic_name__      				=    ['on_init_end', 'on_train_begin']
           __magic_name__      				=    0
           __magic_name__      				=    len(trainer.get_eval_dataloader() )
           __magic_name__      				=    ['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(UpperCamelCase_ ):
                         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 :	List[Any] ):





           '''simple docstring'''

           __magic_name__      				=    self.get_trainer()
           __magic_name__      				=    DEFAULT_CALLBACKS.copy() + [ProgressCallback]
           self.check_callbacks_equality(trainer.callback_handler.callbacks				,    UpperCamelCase_ )

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

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







    def 				a__			(		self :	List[str] ):





           '''simple docstring'''

           __magic_name__      				=    DEFAULT_CALLBACKS.copy() + [ProgressCallback]
           __magic_name__      				=    self.get_trainer()

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

           __magic_name__      				=    self.get_trainer()
           __magic_name__      				=    trainer.pop_callback(UpperCamelCase_ )
           self.assertEqual(cb.__class__				,    UpperCamelCase_ )
           self.check_callbacks_equality(trainer.callback_handler.callbacks				,    UpperCamelCase_ )

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

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

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

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







    def 				a__			(		self :	Any ):





           '''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=UpperCamelCase_ )

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

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

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

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

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

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

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