





"""simple docstring"""





import logging
import os
import time
from argparse import Namespace
from pathlib import Path

import datasets
import torch
from accelerate import Accelerator, DistributedType
from accelerate.utils import ProjectConfiguration
from arguments import TrainingArguments
from datasets import load_dataset
from huggingface_hub import Repository
from torch.optim import AdamW
from torch.utils.data import IterableDataset
from torch.utils.data.dataloader import DataLoader
from torch.utils.data.datapipes.iter.combinatorics import ShufflerIterDataPipe

import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer, HfArgumentParser, get_scheduler, set_seed





class       snake_case		(       SCREAMING_SNAKE_CASE__       ):

      def __init__(      self       :Optional[Any]						,							_lowerCamelCase       :str						,							_lowerCamelCase       :Optional[int]						,							_lowerCamelCase       :List[Any]=False						,							_lowerCamelCase       :Optional[int]=1_0_2_4						,							_lowerCamelCase       :Tuple=1_0_2_4						,							_lowerCamelCase       :Dict=3.6						,							_lowerCamelCase       :List[Any]=False						,							):
       __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	tokenizer
       __SCREAMING_SNAKE_CASE			:      List[str] 							=	tokenizer.bos_token_id
       __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	dataset
       __SCREAMING_SNAKE_CASE			:      Any 							=	seq_length
       __SCREAMING_SNAKE_CASE			:      List[str] 							=	0
       __SCREAMING_SNAKE_CASE			:      List[Any] 							=	infinite
       __SCREAMING_SNAKE_CASE			:      str 							=	0
       __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	tokenized

       if self.tokenized:
        __SCREAMING_SNAKE_CASE			:      str 							=	seq_length * num_of_sequences
        __SCREAMING_SNAKE_CASE			:      List[str] 							=	'''input_ids'''
       else:
        __SCREAMING_SNAKE_CASE			:      List[Any] 							=	seq_length * chars_per_token * num_of_sequences
        __SCREAMING_SNAKE_CASE			:      str 							=	'''content'''

      def __iter__(      self       :int						):
       __SCREAMING_SNAKE_CASE			:      List[str] 							=	iter(self.dataset						)
       __SCREAMING_SNAKE_CASE			:      List[str] 							=	True
       while more_examples:
        __SCREAMING_SNAKE_CASE							,				__SCREAMING_SNAKE_CASE			:      Dict 							=	[], 0
        while True:
         if buffer_len >= self.max_buffer_size:
          break
         try:
          buffer.append(next(_lowerCamelCase						)[self.content_field]						)
          buffer_len += len(buffer[-1]						)
         except StopIteration:
          if self.infinite:
           __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	iter(self.dataset						)
           self.epoch += 1
           logger.info(f'''Dataset epoch: {self.epoch}'''						)
          else:
           __SCREAMING_SNAKE_CASE			:      Any 							=	False
           break
        if self.tokenized:
         __SCREAMING_SNAKE_CASE			:      Tuple 							=	buffer
        else:
         __SCREAMING_SNAKE_CASE			:      List[str] 							=	self.tokenizer(_lowerCamelCase						,							truncation=_lowerCamelCase						)['''input_ids''']
        __SCREAMING_SNAKE_CASE			:      Tuple 							=	[]
        for tokenized_input in tokenized_inputs:
         all_token_ids.extend(tokenized_input + [self.concat_token_id]						)
        for i in range(0						,							len(_lowerCamelCase						)						,							self.seq_length						):
         __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	all_token_ids[i : i + self.seq_length]
         if len(_lowerCamelCase						) == self.seq_length:
          self.current_size += 1
          yield torch.tensor(_lowerCamelCase						)



      def 						SCREAMING_SNAKE_CASE_      (      self       :Any						,							_lowerCamelCase       :int=1_0_0_0						):
       return ShufflerIterDataPipe(self						,							buffer_size=_lowerCamelCase						)







def 		lowerCAmelCase_     (  lowercase_       :							Any		):

 '''simple docstring'''






 __SCREAMING_SNAKE_CASE			:      Dict 							=	args.model_ckpt.split('''/'''		)[-1]
 __SCREAMING_SNAKE_CASE			:      List[str] 							=	logging.getLogger(__name__		)
 __SCREAMING_SNAKE_CASE			:      List[str] 							=	Path(args.save_dir		) / '''log/'''
 log_dir.mkdir(exist_ok=UpperCamelCase_		)
 __SCREAMING_SNAKE_CASE			:      List[str] 							=	F'''debug_{accelerator.process_index}.log'''
 logging.basicConfig(
     format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s'''			,				datefmt='''%m/%d/%Y %H:%M:%S'''			,				level=logging.INFO			,				handlers=[logging.FileHandler(log_dir / filename		), logging.StreamHandler()]			,				)
 if accelerator.is_main_process:  # we only want to setup logging once
  accelerator.init_trackers(UpperCamelCase_			,				vars(UpperCamelCase_		)		)
  __SCREAMING_SNAKE_CASE			:      Any 							=	accelerator.trackers[0].run.name
  logger.setLevel(logging.INFO		)
  datasets.utils.logging.set_verbosity_info()
  transformers.utils.logging.set_verbosity_info()
 else:
  __SCREAMING_SNAKE_CASE			:      Any 							=	''''''
  logger.setLevel(logging.ERROR		)
  datasets.utils.logging.set_verbosity_error()
  transformers.utils.logging.set_verbosity_error()
 return logger, run_name




def 		lowerCAmelCase_     (  lowercase_       :							int		):

 '''simple docstring'''






 __SCREAMING_SNAKE_CASE			:      List[str] 							=	{'''streaming''': True}
 __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	load_dataset(args.dataset_name_train			,				split='''train'''			,				**UpperCamelCase_		)
 __SCREAMING_SNAKE_CASE			:      List[str] 							=	train_data.shuffle(buffer_size=args.shuffle_buffer			,				seed=args.seed		)
 __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	load_dataset(args.dataset_name_valid			,				split='''train'''			,				**UpperCamelCase_		)
 __SCREAMING_SNAKE_CASE			:      List[Any] 							=	ConstantLengthDataset(
     UpperCamelCase_			,				UpperCamelCase_			,				infinite=UpperCamelCase_			,				seq_length=args.seq_length			,				tokenized=args.tokenized		)
 __SCREAMING_SNAKE_CASE			:      Any 							=	ConstantLengthDataset(
     UpperCamelCase_			,				UpperCamelCase_			,				infinite=UpperCamelCase_			,				seq_length=args.seq_length			,				tokenized=args.tokenized		)
 __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	train_dataset.shuffle(buffer_size=args.shuffle_buffer		)
 __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	DataLoader(UpperCamelCase_			,				batch_size=args.train_batch_size			,				shuffle=UpperCamelCase_		)
 __SCREAMING_SNAKE_CASE			:      Any 							=	DataLoader(UpperCamelCase_			,				batch_size=args.valid_batch_size		)
 return train_dataloader, eval_dataloader




def 		lowerCAmelCase_     (  lowercase_       :							Optional[Any]			,				lowercase_       :							Dict			,				lowercase_       :							List[Any]=["bias", "ln_1.weight", "ln_2.weight", "ln_f.weight"]		):

 '''simple docstring'''






 __SCREAMING_SNAKE_CASE							,				__SCREAMING_SNAKE_CASE			:      int 							=	[], []
 for n, p in model.named_parameters():
  if any(nd in n for nd in no_decay		):
   params_without_wd.append(UpperCamelCase_		)
  else:
   params_with_wd.append(UpperCamelCase_		)
 return [
     {"params": params_with_wd, "weight_decay": args.weight_decay},
     {"params": params_without_wd, "weight_decay": 0.0},
 ]




def 		lowerCAmelCase_     (  lowercase_       :							List[str]			,				lowercase_       :							Union[str, Any]		):

 '''simple docstring'''






 logger.info(F'''Step {step}: {metrics}'''		)
 if accelerator.is_main_process:
  accelerator.log(UpperCamelCase_			,				UpperCamelCase_		)




def 		lowerCAmelCase_     (  lowercase_       :							List[str]			,				lowercase_       :							Union[str, Any]			,				lowercase_       :							int		):

 '''simple docstring'''






 __SCREAMING_SNAKE_CASE			:      Dict 							=	accelerator.unwrap_model(UpperCamelCase_		).config
 __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	4 if args.gradient_checkpointing else 3
 __SCREAMING_SNAKE_CASE			:      List[Any] 							=	args.train_batch_size * accelerator.state.num_processes * args.gradient_accumulation_steps
 __SCREAMING_SNAKE_CASE			:      Dict 							=	24 * checkpoint_factor * batch_size * args.seq_length * config_model.n_layer * (config_model.n_embd**2)
 __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	factor * (
     1.0
     + (args.seq_length / (6.0 * config_model.n_embd))
     + (tokenizer.vocab_size / (16.0 * config_model.n_layer * config_model.n_embd))
 )
 __SCREAMING_SNAKE_CASE			:      List[str] 							=	flops_per_iteration / (elapsed_time * accelerator.state.num_processes * (10**12))
 return tflops




def 		lowerCAmelCase_     (  lowercase_       :							Optional[int]		):

 '''simple docstring'''






 model.eval()
 __SCREAMING_SNAKE_CASE			:      int 							=	[]
 for step, batch in enumerate(UpperCamelCase_		):
  with torch.no_grad():
   __SCREAMING_SNAKE_CASE			:      List[str] 							=	model(UpperCamelCase_			,				labels=UpperCamelCase_		)
  __SCREAMING_SNAKE_CASE			:      int 							=	outputs.loss.repeat(args.valid_batch_size		)
  losses.append(accelerator.gather(UpperCamelCase_		)		)
  if args.max_eval_steps > 0 and step >= args.max_eval_steps:
   break
 __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	torch.cat(UpperCamelCase_		)
 __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	losses[: eval_dataloader.dataset.current_size].mean()
 try:
  __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	torch.exp(UpperCamelCase_		)
 except OverflowError:
  __SCREAMING_SNAKE_CASE			:      Dict 							=	float('''inf'''		)
 return loss.item(), perplexity.item()


# Settings
_lowerCamelCase  					=     HfArgumentParser(TrainingArguments)
_lowerCamelCase  					=     parser.parse_args()

# Accelerator
_lowerCamelCase  					=     ProjectConfiguration(project_dir=args.save_dir, logging_dir='''log''')
_lowerCamelCase  					=     Accelerator(log_with=['''wandb''', '''tensorboard'''], project_config=config)
_lowerCamelCase  					=     {str(k): str(v) for k, v in accelerator.state.__dict__.items()}

_lowerCamelCase  					=     Namespace(**vars(args), **acc_state)
_lowerCamelCase  					=     accelerator.state.num_processes * args.train_batch_size
set_seed(args.seed)

# Clone model repository
if accelerator.is_main_process:
    _lowerCamelCase  					=     Repository(args.save_dir, clone_from=args.model_ckpt)

# Logging
_lowerCamelCase  					=     setup_logging(args)
logger.info(accelerator.state)

# Checkout new branch on repo
if accelerator.is_main_process:
    hf_repo.git_checkout(run_name, create_branch_ok=True)

# Load model and tokenizer
_lowerCamelCase  					=     AutoModelForCausalLM.from_pretrained(args.save_dir)
if args.gradient_checkpointing:
    model.gradient_checkpointing_enable()
_lowerCamelCase  					=     AutoTokenizer.from_pretrained(args.save_dir)

# Load dataset and dataloader
_lowerCamelCase  					=     create_dataloaders(args)

# Prepare the optimizer and learning rate scheduler
_lowerCamelCase  					=     AdamW(get_grouped_params(model, args), lr=args.learning_rate)
_lowerCamelCase  					=     get_scheduler(
    name=args.lr_scheduler_type,
    optimizer=optimizer,
    num_warmup_steps=args.num_warmup_steps,
    num_training_steps=args.max_train_steps,
)
accelerator.register_for_checkpointing(lr_scheduler)




def 		lowerCAmelCase_     (  ):

 '''simple docstring'''






 return optimizer.param_groups[0]["lr"]


# Prepare everything with our `accelerator`.
_lowerCamelCase  					=     accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)

# load in the weights and states from a previous save
if args.resume_from_checkpoint:
    if args.resume_from_checkpoint is not None or args.resume_from_checkpoint != "":
        accelerator.print(f'Resumed from checkpoint: {args.resume_from_checkpoint}')
        accelerator.load_state(args.resume_from_checkpoint)
        _lowerCamelCase  					=     os.path.basename(args.resume_from_checkpoint)
    else:
        # Get the most recent checkpoint
        _lowerCamelCase  					=     [f.name for f in os.scandir(args.save_dir) if f.is_dir() and "step" in str(f)]
        dirs.sort(key=os.path.getctime)
        _lowerCamelCase  					=     dirs[-1]  # Sorts folders by date modified, most recent checkpoint is the last
    # Extract the step of the checkpoint to continue from there
    _lowerCamelCase  					=     os.path.splitext(path)[0]
    _lowerCamelCase  					=     int(training_difference.replace('''step_''', ''''''))

# Train model
model.train()
_lowerCamelCase  					=     0
_lowerCamelCase  					=     time.time()
_lowerCamelCase  					=     0
for step, batch in enumerate(train_dataloader, start=1):
    if args.resume_from_checkpoint and step < resume_step:
        continue  # we need to skip steps until we reach the resumed step
    _lowerCamelCase  					=     model(batch, labels=batch, use_cache=False).loss
    _lowerCamelCase  					=     accelerator.gather(loss.repeat(args.train_batch_size)).mean()
    loss_tracking += avg_loss.item() / args.gradient_accumulation_steps
    log_metrics(step, {'''samples''': step * samples_per_step, '''loss_per_step/train''': loss.item()})
    _lowerCamelCase  					=     loss / args.gradient_accumulation_steps
    if step % args.gradient_accumulation_steps != 0:
        # Prevent backward from doing gradient all_reduce in every step
        if accelerator.distributed_type == DistributedType.MULTI_GPU:
            with model.no_sync():
                accelerator.backward(loss)
        else:
            accelerator.backward(loss)
    else:
        _lowerCamelCase  					=     get_lr()
        accelerator.backward(loss)
        accelerator.clip_grad_norm_(model.parameters(), 1.0)
        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        _lowerCamelCase  					=     time.time() - t_start
        _lowerCamelCase  					=     compute_tflops(elapsed_time, accelerator, args)
        log_metrics(
            step,
            {
                '''steps''': completed_steps,
                '''loss/train''': loss_tracking,
                '''lr''': lr,
                '''tflops''': tflops,
                '''time_per_iteration''': elapsed_time,
            },
        )
        _lowerCamelCase  					=     time.time()
        _lowerCamelCase  					=     0
        completed_steps += 1
    if step % args.save_checkpoint_steps == 0:
        logger.info('''Evaluating and saving model checkpoint''')
        _lowerCamelCase  					=     evaluate(args)
        log_metrics(step, {'''loss/eval''': eval_loss, '''perplexity''': perplexity})
        accelerator.wait_for_everyone()
        _lowerCamelCase  					=     os.path.join(args.save_dir, f'step_{step}')
        accelerator.save_state(save_dir)
        if accelerator.is_main_process:
            hf_repo.push_to_hub(commit_message=f'step {step}')
        model.train()
    if completed_steps >= args.max_train_steps:
        break

# Evaluate and save the last checkpoint
logger.info('''Evaluating and saving model after training''')
_lowerCamelCase  					=     evaluate(args)
log_metrics(step, {'''loss/eval''': eval_loss, '''perplexity''': perplexity})
accelerator.wait_for_everyone()
_lowerCamelCase  					=     accelerator.unwrap_model(model)
unwrapped_model.save_pretrained(args.save_dir, save_function=accelerator.save)
_lowerCamelCase  					=     os.path.join(args.save_dir, f'step_{step}')
accelerator.save_state(save_dir)
if accelerator.is_main_process:
    hf_repo.push_to_hub(commit_message='''final model''')








"""simple docstring"""





import json
import os
import shutil
import tempfile
import unittest

from transformers import is_speech_available, is_torch_available
from transformers.models.speechta import SpeechTaTokenizer
from transformers.testing_utils import get_tests_dir, require_torch
from transformers.utils import FEATURE_EXTRACTOR_NAME


if is_speech_available() and is_torch_available():
    from transformers import SpeechTaFeatureExtractor, SpeechTaProcessor

    from .test_feature_extraction_speechta import floats_list


_lowerCamelCase  					=     get_tests_dir('''fixtures/test_sentencepiece_bpe_char.model''')





@require_torch
class       snake_case		(       unittest.TestCase       ):

      def 						SCREAMING_SNAKE_CASE_      (      self       :Union[str, Any]						):
       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	tempfile.mkdtemp()

       __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	SpeechTaTokenizer(_lowerCamelCase						)
       tokenizer.save_pretrained(self.tmpdirname						)

       __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	{
           '''feature_size''': 1,
           '''padding_value''': 0.0,
           '''sampling_rate''': 1_6_0_0_0,
           '''do_normalize''': False,
           '''num_mel_bins''': 8_0,
           '''hop_length''': 1_6,
           '''win_length''': 6_4,
           '''win_function''': '''hann_window''',
           '''fmin''': 8_0,
           '''fmax''': 7_6_0_0,
           '''mel_floor''': 1e-10,
           '''reduction_factor''': 2,
           '''return_attention_mask''': True,
       }

       __SCREAMING_SNAKE_CASE			:      Any 							=	os.path.join(self.tmpdirname						,							_lowerCamelCase						)
       with open(self.feature_extraction_file						,							'''w'''						,							encoding='''utf-8'''						) as fp:
        fp.write(json.dumps(_lowerCamelCase						) + '''\n'''						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :str						,							**_lowerCamelCase       :str						):
       return SpeechTaTokenizer.from_pretrained(self.tmpdirname						,							**_lowerCamelCase						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :Dict						,							**_lowerCamelCase       :Dict						):
       return SpeechTaFeatureExtractor.from_pretrained(self.tmpdirname						,							**_lowerCamelCase						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :List[str]						):
       shutil.rmtree(self.tmpdirname						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :Union[str, Any]						):
       __SCREAMING_SNAKE_CASE			:      Any 							=	self.get_tokenizer()
       __SCREAMING_SNAKE_CASE			:      int 							=	self.get_feature_extractor()

       __SCREAMING_SNAKE_CASE			:      Any 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       processor.save_pretrained(self.tmpdirname						)
       __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	SpeechTaProcessor.from_pretrained(self.tmpdirname						)

       self.assertEqual(processor.tokenizer.get_vocab()						,							tokenizer.get_vocab()						)
       self.assertIsInstance(processor.tokenizer						,							_lowerCamelCase						)

       self.assertEqual(processor.feature_extractor.to_json_string()						,							feature_extractor.to_json_string()						)
       self.assertIsInstance(processor.feature_extractor						,							_lowerCamelCase						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :Union[str, Any]						):
       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	SpeechTaProcessor(tokenizer=self.get_tokenizer()						,							feature_extractor=self.get_feature_extractor()						)
       processor.save_pretrained(self.tmpdirname						)

       __SCREAMING_SNAKE_CASE			:      Tuple 							=	self.get_tokenizer(bos_token='''(BOS)'''						,							eos_token='''(EOS)'''						)
       __SCREAMING_SNAKE_CASE			:      List[str] 							=	self.get_feature_extractor(do_normalize=_lowerCamelCase						,							padding_value=1.0						)

       __SCREAMING_SNAKE_CASE			:      Any 							=	SpeechTaProcessor.from_pretrained(
           self.tmpdirname						,							bos_token='''(BOS)'''						,							eos_token='''(EOS)'''						,							do_normalize=_lowerCamelCase						,							padding_value=1.0						)

       self.assertEqual(processor.tokenizer.get_vocab()						,							tokenizer_add_kwargs.get_vocab()						)
       self.assertIsInstance(processor.tokenizer						,							_lowerCamelCase						)

       self.assertEqual(processor.feature_extractor.to_json_string()						,							feature_extractor_add_kwargs.to_json_string()						)
       self.assertIsInstance(processor.feature_extractor						,							_lowerCamelCase						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :str						):
       __SCREAMING_SNAKE_CASE			:      Optional[int] 							=	self.get_feature_extractor()
       __SCREAMING_SNAKE_CASE			:      Tuple 							=	self.get_tokenizer()

       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       __SCREAMING_SNAKE_CASE			:      int 							=	floats_list((3, 1_0_0_0)						)

       __SCREAMING_SNAKE_CASE			:      int 							=	feature_extractor(audio=_lowerCamelCase						,							return_tensors='''np'''						)
       __SCREAMING_SNAKE_CASE			:      List[str] 							=	processor(audio=_lowerCamelCase						,							return_tensors='''np'''						)

       for key in input_feat_extract.keys():
        self.assertAlmostEqual(input_feat_extract[key].sum()						,							input_processor[key].sum()						,							delta=1e-2						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :Tuple						):
       __SCREAMING_SNAKE_CASE			:      Any 							=	self.get_feature_extractor()
       __SCREAMING_SNAKE_CASE			:      int 							=	self.get_tokenizer()

       __SCREAMING_SNAKE_CASE			:      Any 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	floats_list((3, 1_0_0_0)						)

       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	feature_extractor(audio_target=_lowerCamelCase						,							return_tensors='''np'''						)
       __SCREAMING_SNAKE_CASE			:      List[Any] 							=	processor(audio_target=_lowerCamelCase						,							return_tensors='''np'''						)

       for key in input_feat_extract.keys():
        self.assertAlmostEqual(input_feat_extract[key].sum()						,							input_processor[key].sum()						,							delta=1e-2						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :List[Any]						):
       __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	self.get_feature_extractor()
       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	self.get_tokenizer()

       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       __SCREAMING_SNAKE_CASE			:      int 							=	'''This is a test string'''

       __SCREAMING_SNAKE_CASE			:      str 							=	processor(text=_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE			:      Union[str, Any] 							=	tokenizer(_lowerCamelCase						)

       for key in encoded_tok.keys():
        self.assertListEqual(encoded_tok[key]						,							encoded_processor[key]						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :Optional[int]						):
       __SCREAMING_SNAKE_CASE			:      int 							=	self.get_feature_extractor()
       __SCREAMING_SNAKE_CASE			:      str 							=	self.get_tokenizer()

       __SCREAMING_SNAKE_CASE			:      Tuple 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       __SCREAMING_SNAKE_CASE			:      Dict 							=	'''This is a test string'''

       __SCREAMING_SNAKE_CASE			:      str 							=	processor(text_target=_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE			:      Dict 							=	tokenizer(_lowerCamelCase						)

       for key in encoded_tok.keys():
        self.assertListEqual(encoded_tok[key]						,							encoded_processor[key]						)

      def 						SCREAMING_SNAKE_CASE_      (      self       :Optional[Any]						):
       __SCREAMING_SNAKE_CASE			:      Dict 							=	self.get_feature_extractor()
       __SCREAMING_SNAKE_CASE			:      Tuple 							=	self.get_tokenizer()

       __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

       __SCREAMING_SNAKE_CASE			:      List[Any] 							=	processor.batch_decode(_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE			:      List[Any] 							=	tokenizer.batch_decode(_lowerCamelCase						)

       self.assertListEqual(_lowerCamelCase						,							_lowerCamelCase						)



      def 						SCREAMING_SNAKE_CASE_      (      self       :Optional[Any]						):
       __SCREAMING_SNAKE_CASE			:      Optional[Any] 							=	self.get_feature_extractor()
       __SCREAMING_SNAKE_CASE			:      str 							=	self.get_tokenizer()

       __SCREAMING_SNAKE_CASE			:      str 							=	SpeechTaProcessor(tokenizer=_lowerCamelCase						,							feature_extractor=_lowerCamelCase						)

       self.assertListEqual(
           processor.model_input_names						,							feature_extractor.model_input_names						,							msg='''`processor` and `feature_extractor` model input names do not match'''						,							)

