






import logging
import os
from dataclasses import dataclass, field
from importlib import import_module
from typing import Dict, List, Optional, Tuple

import numpy as np
from seqeval.metrics import classification_report, fa_score, precision_score, recall_score
from utils_ner import Split, TFTokenClassificationDataset, TokenClassificationTask

from transformers import (
    AutoConfig,
    AutoTokenizer,
    EvalPrediction,
    HfArgumentParser,
    TFAutoModelForTokenClassification,
    TFTrainer,
    TFTrainingArguments,
)
from transformers.utils import logging as hf_logging


hf_logging.set_verbosity_info()
hf_logging.enable_default_handler()
hf_logging.enable_explicit_format()


A										=      logging.getLogger(__name__)


@dataclass
class 				__a				:





		'''simple docstring'''



		UpperCAmelCase__   :					str					     =    field(
		    metadata={"""help""": """Path to pretrained model or model identifier from huggingface.co/models"""}    )
		UpperCAmelCase__   :					Optional[str]					     =    field(
		    default=SCREAMING_SNAKE_CASE__			,						metadata={"""help""": """Pretrained config name or path if not the same as model_name"""}    )
		UpperCAmelCase__   :					Optional[str]					     =    field(
		    default="""NER"""			,						metadata={"""help""": """Task type to fine tune in training (e.g. NER, POS, etc)"""}    )
		UpperCAmelCase__   :					Optional[str]					     =    field(
		    default=SCREAMING_SNAKE_CASE__			,						metadata={"""help""": """Pretrained tokenizer name or path if not the same as model_name"""}    )
		UpperCAmelCase__   :					bool					     =    field(default=SCREAMING_SNAKE_CASE__			,						metadata={"""help""": """Set this flag to use fast tokenization."""}    )
		# If you want to tweak more attributes on your tokenizer, you should do it in a distinct script,
		# or just modify its tokenizer_config.json.
		UpperCAmelCase__   :					Optional[str]					     =    field(
		    default=SCREAMING_SNAKE_CASE__			,						metadata={"""help""": """Where do you want to store the pretrained models downloaded from huggingface.co"""}			,						)






@dataclass
class 				__a				:





		'''simple docstring'''



		UpperCAmelCase__   :					str					     =    field(
		    metadata={"""help""": """The input data dir. Should contain the .txt files for a CoNLL-2003-formatted task."""}    )
		UpperCAmelCase__   :					Optional[str]					     =    field(
		    metadata={"""help""": """Path to a file containing all labels. If not specified, CoNLL-2003 labels are used."""}    )
		UpperCAmelCase__   :					int					     =    field(
		    default=128			,						metadata={
		        """help""": (
		            """The maximum total input sequence length after tokenization. Sequences longer """
		            """than this will be truncated, sequences shorter will be padded."""
		        )
		    }			,						)
		UpperCAmelCase__   :					bool					     =    field(
		    default=SCREAMING_SNAKE_CASE__			,						metadata={"""help""": """Overwrite the cached training and evaluation sets"""}    )






def        _lowerCamelCase(      ):





				'''simple docstring'''







				SCREAMING_SNAKE_CASE_ :						Optional[int]    				= HfArgumentParser((ModelArguments, DataTrainingArguments, TFTrainingArguments)   )
				SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= parser.parse_args_into_dataclasses()

				if (
				    os.path.exists(training_args.output_dir   )
				    and os.listdir(training_args.output_dir   )
				    and training_args.do_train
				    and not training_args.overwrite_output_dir
				):
								raise ValueError(
								    F'''Output directory ({training_args.output_dir}) already exists and is not empty. Use'''
								    ' --overwrite_output_dir to overcome.'   )

				SCREAMING_SNAKE_CASE_ :						Tuple    				= import_module('tasks'   )

				try:
								SCREAMING_SNAKE_CASE_ :						Dict    				= getattr(_UpperCamelCase     ,     model_args.task_type   )
								SCREAMING_SNAKE_CASE_ :						Tuple    				= token_classification_task_clazz()
				except AttributeError:
								raise ValueError(
								    F'''Task {model_args.task_type} needs to be defined as a TokenClassificationTask subclass in {module}. '''
								    F'''Available tasks classes are: {TokenClassificationTask.__subclasses__()}'''   )

				# Setup logging
				logging.basicConfig(
				    format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'     ,     datefmt='%m/%d/%Y %H:%M:%S'     ,     level=logging.INFO     ,     )
				logger.info(
				    'n_replicas: %s, distributed training: %s, 16-bits training: %s'     ,     training_args.n_replicas     ,     bool(training_args.n_replicas > 1   )     ,     training_args.fpaa     ,     )
				logger.info('Training/evaluation parameters %s'     ,     _UpperCamelCase   )

				# Prepare Token Classification task
				SCREAMING_SNAKE_CASE_ :						int    				= token_classification_task.get_labels(data_args.labels   )
				SCREAMING_SNAKE_CASE_ :						List[Any]    				= dict(enumerate(_UpperCamelCase   )   )
				SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= len(_UpperCamelCase   )

				# Load pretrained model and tokenizer
				#
				# Distributed training:
				# The .from_pretrained methods guarantee that only one local process can concurrently
				# download model & vocab.

				SCREAMING_SNAKE_CASE_ :						List[Any]    				= AutoConfig.from_pretrained(
				    model_args.config_name if model_args.config_name else model_args.model_name_or_path     ,     num_labels=_UpperCamelCase     ,     idalabel=_UpperCamelCase     ,     labelaid={label: i for i, label in enumerate(_UpperCamelCase   )}     ,     cache_dir=model_args.cache_dir     ,     )
				SCREAMING_SNAKE_CASE_ :						Tuple    				= AutoTokenizer.from_pretrained(
				    model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path     ,     cache_dir=model_args.cache_dir     ,     use_fast=model_args.use_fast     ,     )

				with training_args.strategy.scope():
								SCREAMING_SNAKE_CASE_ :						Any    				= TFAutoModelForTokenClassification.from_pretrained(
								    model_args.model_name_or_path     ,     from_pt=bool('.bin' in model_args.model_name_or_path   )     ,     config=_UpperCamelCase     ,     cache_dir=model_args.cache_dir     ,     )

				# Get datasets
				SCREAMING_SNAKE_CASE_ :						int    				= (
				    TFTokenClassificationDataset(
				        token_classification_task=_UpperCamelCase     ,     data_dir=data_args.data_dir     ,     tokenizer=_UpperCamelCase     ,     labels=_UpperCamelCase     ,     model_type=config.model_type     ,     max_seq_length=data_args.max_seq_length     ,     overwrite_cache=data_args.overwrite_cache     ,     mode=Split.train     ,     )
				    if training_args.do_train
				    else None
				)
				SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= (
				    TFTokenClassificationDataset(
				        token_classification_task=_UpperCamelCase     ,     data_dir=data_args.data_dir     ,     tokenizer=_UpperCamelCase     ,     labels=_UpperCamelCase     ,     model_type=config.model_type     ,     max_seq_length=data_args.max_seq_length     ,     overwrite_cache=data_args.overwrite_cache     ,     mode=Split.dev     ,     )
				    if training_args.do_eval
				    else None
				)

				def align_predictions(lowerCAmelCase__					:		np.ndarray     ,     lowerCAmelCase__					:		np.ndarray   ) -> Tuple[List[int], List[int]]:
								SCREAMING_SNAKE_CASE_ :						List[Any]    				= np.argmax(_UpperCamelCase     ,     axis=2   )
								SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= preds.shape
								SCREAMING_SNAKE_CASE_ :						str    				= [[] for _ in range(_UpperCamelCase   )]
								SCREAMING_SNAKE_CASE_ :						Any    				= [[] for _ in range(_UpperCamelCase   )]

								for i in range(_UpperCamelCase   ):
												for j in range(_UpperCamelCase   ):
																if label_ids[i, j] != -100:
																				out_label_list[i].append(label_map[label_ids[i][j]]   )
																				preds_list[i].append(label_map[preds[i][j]]   )

								return preds_list, out_label_list

				def compute_metrics(lowerCAmelCase__					:		EvalPrediction   ) -> Dict:
								SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						List[str]    				= align_predictions(p.predictions     ,     p.label_ids   )

								return {
								    "precision": precision_score(_UpperCamelCase     ,     _UpperCamelCase   ),
								    "recall": recall_score(_UpperCamelCase     ,     _UpperCamelCase   ),
								    "f1": fa_score(_UpperCamelCase     ,     _UpperCamelCase   ),
								}

				# Initialize our Trainer
				SCREAMING_SNAKE_CASE_ :						List[str]    				= TFTrainer(
				    model=_UpperCamelCase     ,     args=_UpperCamelCase     ,     train_dataset=train_dataset.get_dataset() if train_dataset else None     ,     eval_dataset=eval_dataset.get_dataset() if eval_dataset else None     ,     compute_metrics=_UpperCamelCase     ,     )

				# Training
				if training_args.do_train:
								trainer.train()
								trainer.save_model()
								tokenizer.save_pretrained(training_args.output_dir   )

				# Evaluation
				SCREAMING_SNAKE_CASE_ :						Dict    				= {}
				if training_args.do_eval:
								logger.info('*** Evaluate ***'   )

								SCREAMING_SNAKE_CASE_ :						Optional[int]    				= trainer.evaluate()
								SCREAMING_SNAKE_CASE_ :						Tuple    				= os.path.join(training_args.output_dir     ,     'eval_results.txt'   )

								with open(_UpperCamelCase     ,     'w'   ) as writer:
												logger.info('***** Eval results *****'   )

												for key, value in result.items():
																logger.info('  %s = %s'     ,     _UpperCamelCase     ,     _UpperCamelCase   )
																writer.write('%s = %s\n' % (key, value)   )

												results.update(_UpperCamelCase   )

    # Predict
				if training_args.do_predict:
								SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= TFTokenClassificationDataset(
								    token_classification_task=_UpperCamelCase     ,     data_dir=data_args.data_dir     ,     tokenizer=_UpperCamelCase     ,     labels=_UpperCamelCase     ,     model_type=config.model_type     ,     max_seq_length=data_args.max_seq_length     ,     overwrite_cache=data_args.overwrite_cache     ,     mode=Split.test     ,     )

								SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						Tuple    				= trainer.predict(test_dataset.get_dataset()   )
								SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						List[Any]    				= align_predictions(_UpperCamelCase     ,     _UpperCamelCase   )
								SCREAMING_SNAKE_CASE_ :						Dict    				= classification_report(_UpperCamelCase     ,     _UpperCamelCase   )

								logger.info('\n%s'     ,     _UpperCamelCase   )

								SCREAMING_SNAKE_CASE_ :						str    				= os.path.join(training_args.output_dir     ,     'test_results.txt'   )

								with open(_UpperCamelCase     ,     'w'   ) as writer:
												writer.write('%s\n' % report   )

								# Save predictions
								SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= os.path.join(training_args.output_dir     ,     'test_predictions.txt'   )

								with open(_UpperCamelCase     ,     'w'   ) as writer:
												with open(os.path.join(data_args.data_dir     ,     'test.txt'   )     ,     'r'   ) as f:
																SCREAMING_SNAKE_CASE_ :						str    				= 0

																for line in f:
																				if line.startswith('-DOCSTART-'   ) or line == "" or line == "\n":
																								writer.write(_UpperCamelCase   )

																								if not preds_list[example_id]:
																												example_id += 1
																				elif preds_list[example_id]:
																								SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= line.split()[0] + ' ' + preds_list[example_id].pop(0   ) + '\n'

																								writer.write(_UpperCamelCase   )
																				else:
																								logger.warning('Maximum sequence length exceeded: No prediction for \'%s\'.'     ,     line.split()[0]   )

				return results


if __name__ == "__main__":
				main()



'''simple docstring'''

from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


__lowercase:		int    						=  logging.get_logger(__name__)

__lowercase:		Tuple    						=  {
    "facebook/mbart-large-cc25": "https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json",
    # See all MBART models at https://huggingface.co/models?filter=mbart
}







class 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__):
 _lowerCamelCase			:       List[str]            =       'mbart'
 _lowerCamelCase			:       str            =       ['past_key_values']
 _lowerCamelCase			:       List[str]            =       {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}

 def __init__(			self			:						Tuple,       a_			:						Union[str, Any]=5_0265,       a_			:						Union[str, Any]=1024,       a_			:						Optional[int]=12,       a_			:						str=4096,       a_			:						Optional[Any]=16,       a_			:						str=12,       a_			:						Union[str, Any]=4096,       a_			:						List[Any]=16,       a_			:						Optional[Any]=0.0,       a_			:						int=0.0,       a_			:						Any=True,       a_			:						Optional[Any]=True,       a_			:						Any="gelu",       a_			:						int=1024,       a_			:						Any=0.1,       a_			:						Optional[int]=0.0,       a_			:						Tuple=0.0,       a_			:						Optional[Any]=0.02,       a_			:						Any=0.0,       a_			:						Optional[Any]=False,       a_			:						Any=1,       a_			:						Optional[Any]=0,       a_			:						List[str]=2,       a_			:						Any=2,       **a_			:						int,       ):





    """simple docstring"""



    UpperCamelCase__			    =    vocab_size
    UpperCamelCase__			    =    max_position_embeddings
    UpperCamelCase__			    =    d_model
    UpperCamelCase__			    =    encoder_ffn_dim
    UpperCamelCase__			    =    encoder_layers
    UpperCamelCase__			    =    encoder_attention_heads
    UpperCamelCase__			    =    decoder_ffn_dim
    UpperCamelCase__			    =    decoder_layers
    UpperCamelCase__			    =    decoder_attention_heads
    UpperCamelCase__			    =    dropout
    UpperCamelCase__			    =    attention_dropout
    UpperCamelCase__			    =    activation_dropout
    UpperCamelCase__			    =    activation_function
    UpperCamelCase__			    =    init_std
    UpperCamelCase__			    =    encoder_layerdrop
    UpperCamelCase__			    =    decoder_layerdrop
    UpperCamelCase__			    =    classifier_dropout
    UpperCamelCase__			    =    use_cache
    UpperCamelCase__			    =    encoder_layers
    UpperCamelCase__			    =    scale_embedding  # scale factor will be sqrt(d_model) if True
    super().__init__(
        pad_token_id=a_,       bos_token_id=a_,       eos_token_id=a_,       is_encoder_decoder=a_,       forced_eos_token_id=a_,       **a_,       )







class 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__):

 @property
 def 		lowercase_    (			self			:						Optional[Any]       ):





    """simple docstring"""



    if self.task in ["default", "seq2seq-lm"]:
       UpperCamelCase__			    =    OrderedDict(
           [
               ("input_ids", {0: "batch", 1: "encoder_sequence"}),
               ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
           ]       )

       if self.use_past:
          UpperCamelCase__			    =    {0: "batch"}
          UpperCamelCase__			    =    {0: "batch", 1: "past_decoder_sequence + sequence"}
       else:
          UpperCamelCase__			    =    {0: "batch", 1: "decoder_sequence"}
          UpperCamelCase__			    =    {0: "batch", 1: "decoder_sequence"}

       if self.use_past:
          self.fill_with_past_key_values_(a_,       direction="inputs"       )
    elif self.task == "causal-lm":
       # TODO: figure this case out.
       UpperCamelCase__			    =    OrderedDict(
           [
               ("input_ids", {0: "batch", 1: "encoder_sequence"}),
               ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
           ]       )
       if self.use_past:
          UpperCamelCase__    ,		UpperCamelCase__			    =    self.num_layers
          for i in range(a_       ):
             UpperCamelCase__			    =    {0: "batch", 2: "past_sequence + sequence"}
             UpperCamelCase__			    =    {0: "batch", 2: "past_sequence + sequence"}
    else:
       UpperCamelCase__			    =    OrderedDict(
           [
               ("input_ids", {0: "batch", 1: "encoder_sequence"}),
               ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
               ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
               ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
           ]       )

    return common_inputs

 @property
 def 		lowercase_    (			self			:						Any       ):





    """simple docstring"""



    if self.task in ["default", "seq2seq-lm"]:
       UpperCamelCase__			    =    super().outputs
    else:
       UpperCamelCase__			    =    super(a_,       self       ).outputs
       if self.use_past:
          UpperCamelCase__    ,		UpperCamelCase__			    =    self.num_layers
          for i in range(a_       ):
             UpperCamelCase__			    =    {0: "batch", 2: "past_sequence + sequence"}
             UpperCamelCase__			    =    {0: "batch", 2: "past_sequence + sequence"}
    return common_outputs

 def 		lowercase_    (			self			:						str,       a_			:						PreTrainedTokenizer,       a_			:						int = -1,       a_			:						int = -1,       a_			:						bool = False,       a_			:						Optional[TensorType] = None,       ):





    """simple docstring"""



    UpperCamelCase__			    =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        a_,       a_,       a_,       a_,       a_       )

    # Generate decoder inputs
    UpperCamelCase__			    =    seq_length if not self.use_past else 1
    UpperCamelCase__			    =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        a_,       a_,       a_,       a_,       a_       )
    UpperCamelCase__			    =    {f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
    UpperCamelCase__			    =    dict(**a_,       **a_       )

    if self.use_past:
       if not is_torch_available():
          raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."       )
       else:
          import torch
       UpperCamelCase__    ,		UpperCamelCase__			    =    common_inputs["input_ids"].shape
       UpperCamelCase__			    =    common_inputs["decoder_input_ids"].shape[1]
       UpperCamelCase__    ,		UpperCamelCase__			    =    self.num_attention_heads
       UpperCamelCase__			    =    (
           batch,
           num_encoder_attention_heads,
           encoder_seq_length,
           self._config.hidden_size // num_encoder_attention_heads,
       )
       UpperCamelCase__			    =    decoder_seq_length + 3
       UpperCamelCase__			    =    (
           batch,
           num_decoder_attention_heads,
           decoder_past_length,
           self._config.hidden_size // num_decoder_attention_heads,
       )

       UpperCamelCase__			    =    torch.cat(
           [common_inputs["decoder_attention_mask"], torch.ones(a_,       a_       )],       dim=1       )

       UpperCamelCase__			    =    []
       # If the number of encoder and decoder layers are present in the model configuration, both are considered
       UpperCamelCase__    ,		UpperCamelCase__			    =    self.num_layers
       UpperCamelCase__			    =    min(a_,       a_       )
       UpperCamelCase__			    =    max(a_,       a_       ) - min_num_layers
       UpperCamelCase__			    =    "encoder" if num_encoder_layers > num_decoder_layers else "decoder"

       for _ in range(a_       ):
          common_inputs["past_key_values"].append(
              (
                  torch.zeros(a_       ),
                  torch.zeros(a_       ),
                  torch.zeros(a_       ),
                  torch.zeros(a_       ),
              )       )
       # TODO: test this.
       UpperCamelCase__			    =    encoder_shape if remaining_side_name == "encoder" else decoder_shape
       for _ in range(a_,       a_       ):
          common_inputs["past_key_values"].append((torch.zeros(a_       ), torch.zeros(a_       ))       )
    return common_inputs

 def 		lowercase_    (			self			:						Optional[int],       a_			:						PreTrainedTokenizer,       a_			:						int = -1,       a_			:						int = -1,       a_			:						bool = False,       a_			:						Optional[TensorType] = None,       ):





    """simple docstring"""



    UpperCamelCase__			    =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        a_,       a_,       a_,       a_,       a_       )

    if self.use_past:
       if not is_torch_available():
          raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."       )
       else:
          import torch
       UpperCamelCase__    ,		UpperCamelCase__			    =    common_inputs["input_ids"].shape
       # Not using the same length for past_key_values
       UpperCamelCase__			    =    seqlen + 2
       UpperCamelCase__    ,		UpperCamelCase__			    =    self.num_layers
       UpperCamelCase__    ,		UpperCamelCase__			    =    self.num_attention_heads
       UpperCamelCase__			    =    (
           batch,
           num_encoder_attention_heads,
           past_key_values_length,
           self._config.hidden_size // num_encoder_attention_heads,
       )

       UpperCamelCase__			    =    common_inputs["attention_mask"].dtype
       UpperCamelCase__			    =    torch.cat(
           [common_inputs["attention_mask"], torch.ones(a_,       a_,       dtype=a_       )],       dim=1       )
       UpperCamelCase__			    =    [
           (torch.zeros(a_       ), torch.zeros(a_       )) for _ in range(a_       )
       ]
    return common_inputs

 def 		lowercase_    (			self			:						List[Any],       a_			:						PreTrainedTokenizer,       a_			:						int = -1,       a_			:						int = -1,       a_			:						bool = False,       a_			:						Optional[TensorType] = None,       ):





    """simple docstring"""



    UpperCamelCase__			    =    compute_effective_axis_dimension(
        a_,       fixed_dimension=OnnxConfig.default_fixed_batch,       num_token_to_add=0       )

    # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
    UpperCamelCase__			    =    tokenizer.num_special_tokens_to_add(a_       )
    UpperCamelCase__			    =    compute_effective_axis_dimension(
        a_,       fixed_dimension=OnnxConfig.default_fixed_sequence,       num_token_to_add=a_       )

    # Generate dummy inputs according to compute batch and sequence
    UpperCamelCase__			    =    [" ".join([tokenizer.unk_token]       ) * seq_length] * batch_size
    UpperCamelCase__			    =    dict(tokenizer(a_,       return_tensors=a_       )       )
    return common_inputs

 def 		lowercase_    (			self			:						Union[str, Any],       a_			:						PreTrainedTokenizer,       a_			:						int = -1,       a_			:						int = -1,       a_			:						bool = False,       a_			:						Optional[TensorType] = None,       ):





    """simple docstring"""



    if self.task in ["default", "seq2seq-lm"]:
       UpperCamelCase__			    =    self._generate_dummy_inputs_for_default_and_seqaseq_lm(
           a_,       batch_size=a_,       seq_length=a_,       is_pair=a_,       framework=a_       )

    elif self.task == "causal-lm":
       UpperCamelCase__			    =    self._generate_dummy_inputs_for_causal_lm(
           a_,       batch_size=a_,       seq_length=a_,       is_pair=a_,       framework=a_       )
    else:
       UpperCamelCase__			    =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           a_,       batch_size=a_,       seq_length=a_,       is_pair=a_,       framework=a_       )

    return common_inputs

 def 		lowercase_    (			self			:						Dict,       a_			:						int,       a_			:						str,       a_			:						List[Any],       a_			:						int       ):





    """simple docstring"""



    if self.task in ["default", "seq2seq-lm"]:
       UpperCamelCase__			    =    super()._flatten_past_key_values_(a_,       a_,       a_,       a_       )
    else:
       UpperCamelCase__			    =    super(a_,       self       )._flatten_past_key_values_(
           a_,       a_,       a_,       a_       )