






'''simple docstring'''


import warnings
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


lowerCamelCase_				: Union[str, Any]    	=							logging.get_logger(__name__)

lowerCamelCase_				: Optional[Any]    	=							{
    '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/config.json''',
    # See all BART models at https://huggingface.co/models?filter=bart
}
class    _SCREAMING_SNAKE_CASE							(		__a	):


			'''simple docstring'''





			__a							:							Union[str, Any]					     =					'''bart'''
			__a							:							Optional[int]					     =					['''past_key_values''']
			__a							:							List[str]					     =					{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}






			def __init__(   self							:						List[Any] ,      lowercase							:						Union[str, Any]=5_0_2_6_5 ,      lowercase							:						int=1_0_2_4 ,      lowercase							:						Optional[Any]=1_2 ,      lowercase							:						Dict=4_0_9_6 ,      lowercase							:						Dict=1_6 ,      lowercase							:						int=1_2 ,      lowercase							:						Optional[Any]=4_0_9_6 ,      lowercase							:						Optional[Any]=1_6 ,      lowercase							:						Tuple=0.0 ,      lowercase							:						Dict=0.0 ,      lowercase							:						Optional[Any]="gelu" ,      lowercase							:						Dict=1_0_2_4 ,      lowercase							:						Any=0.1 ,      lowercase							:						List[Any]=0.0 ,      lowercase							:						str=0.0 ,      lowercase							:						Optional[int]=0.0_2 ,      lowercase							:						Optional[int]=0.0 ,      lowercase							:						List[str]=False ,      lowercase							:						Tuple=True ,      lowercase							:						List[Any]=3 ,      lowercase							:						str=1 ,      lowercase							:						Tuple=0 ,      lowercase							:						Union[str, Any]=2 ,      lowercase							:						Optional[int]=True ,      lowercase							:						Optional[Any]=2 ,      lowercase							:						List[str]=2 ,      **lowercase							:						Tuple ,      )							->    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__(
									    num_labels=snake_case__ ,      pad_token_id=snake_case__ ,      bos_token_id=snake_case__ ,      eos_token_id=snake_case__ ,      is_encoder_decoder=snake_case__ ,      decoder_start_token_id=snake_case__ ,      forced_eos_token_id=snake_case__ ,      **snake_case__ ,      )

									# ensure backward compatibility for BART CNN models
									if self.forced_bos_token_id is None and kwargs.get("""force_bos_token_to_be_generated""" ,      snake_case__			):
															UpperCamelCase__         = self.bos_token_id
															warnings.warn(
															    f"Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. "
															    """The config can simply be saved and uploaded again to be fixed."""			)
class    _SCREAMING_SNAKE_CASE							(		__a	):


			'''simple docstring'''





			@property
			def 				A      (   self							:						List[str]			)							->    List[str]:

									'''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_(snake_case__ ,      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(snake_case__			):
																											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 				A      (   self							:						int			)							->    str:

									'''simple docstring'''







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






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

									'''simple docstring'''







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

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

									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(snake_case__ ,      snake_case__			)] ,      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(snake_case__ ,      snake_case__			)
															UpperCamelCase__         = max(snake_case__ ,      snake_case__			) - min_num_layers
															UpperCamelCase__         = """encoder""" if num_encoder_layers > num_decoder_layers else """decoder"""

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






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						PreTrainedTokenizer ,      lowercase							:						int = -1 ,      lowercase							:						int = -1 ,      lowercase							:						bool = False ,      lowercase							:						Optional[TensorType] = None ,      )							->    Any:

									'''simple docstring'''







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

									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(snake_case__ ,      snake_case__ ,      dtype=snake_case__			)] ,      dim=1			)
															UpperCamelCase__         = [
															    (torch.zeros(snake_case__			), torch.zeros(snake_case__			)) for _ in range(snake_case__			)
															]
									return common_inputs






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						PreTrainedTokenizer ,      lowercase							:						int = -1 ,      lowercase							:						int = -1 ,      lowercase							:						bool = False ,      lowercase							:						Optional[TensorType] = None ,      )							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = compute_effective_axis_dimension(
									    snake_case__ ,      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(snake_case__			)
									UpperCamelCase__         = compute_effective_axis_dimension(
									    snake_case__ ,      fixed_dimension=OnnxConfig.default_fixed_sequence ,      num_token_to_add=snake_case__			)

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






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						PreTrainedTokenizer ,      lowercase							:						int = -1 ,      lowercase							:						int = -1 ,      lowercase							:						bool = False ,      lowercase							:						Optional[TensorType] = None ,      )							->    List[Any]:

									'''simple docstring'''







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

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

									return common_inputs







			def 				A      (   self							:						Tuple ,      lowercase							:						Union[str, Any] ,      lowercase							:						List[str] ,      lowercase							:						Union[str, Any] ,      lowercase							:						int			)							->    Tuple:

									'''simple docstring'''







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














'''simple docstring'''


import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, ClassLabel, Features
from .base import TaskTemplate
@dataclass(frozen=SCREAMING_SNAKE_CASE	)
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			__a							:							str					     =					field(default="audio-classification"       ,metadata={"include_in_asdict_even_if_is_default": True}	)
			__a							:							ClassVar[Features]					     =					Features({"audio": Audio()}	)
			__a							:							ClassVar[Features]					     =					Features({"labels": ClassLabel}	)
			__a							:							str					     =					"audio"
			__a							:							str					     =					"labels"






			def 				A      (   self							:						List[Any] ,      lowercase							:						List[Any]			)							->    Any:

									'''simple docstring'''







									if self.label_column not in features:
															raise ValueError(f"Column {self.label_column} is not present in features."			)
									if not isinstance(features[self.label_column] ,      lowercase			):
															raise ValueError(f"Column {self.label_column} is not a ClassLabel."			)
									UpperCamelCase__         = copy.deepcopy(self			)
									UpperCamelCase__         = self.label_schema.copy()
									UpperCamelCase__         = features[self.label_column]
									UpperCamelCase__         = label_schema
									return task_template







			@property
			def 				A      (   self							:						int			)							->    Dict[str, str]:

									'''simple docstring'''







									return {
									    self.audio_column: "audio",
									    self.label_column: "labels",
									}
