



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:					str      =						logging.get_logger(__name__)

_lowercase:					List[Any]      =						{
    "google/bigbird-pegasus-large-arxiv": (
        "https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json"
    ),
    "google/bigbird-pegasus-large-pubmed": (
        "https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json"
    ),
    "google/bigbird-pegasus-large-bigpatent": (
        "https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json"
    ),
    # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
}



class       _lowercase				(  lowerCAmelCase      ):





	"""simple docstring"""
	__A		      =				"bigbird_pegasus"
	__A		      =				["past_key_values"]
	__A		      =				{
	    "num_attention_heads": "encoder_attention_heads",
	    "hidden_size": "d_model",
	    "attention_probs_dropout_prob": "attention_dropout",
	}




	def __init__(self						,			lowerCamelCase_=96103						,			lowerCamelCase_=4096						,			lowerCamelCase_=16						,			lowerCamelCase_=4096						,			lowerCamelCase_=16						,			lowerCamelCase_=16						,			lowerCamelCase_=4096						,			lowerCamelCase_=16						,			lowerCamelCase_=0.0						,			lowerCamelCase_=0.0						,			lowerCamelCase_=True						,			lowerCamelCase_=True						,			lowerCamelCase_="gelu_new"						,			lowerCamelCase_=1024						,			lowerCamelCase_=0.1						,			lowerCamelCase_=0.0						,			lowerCamelCase_=0.0						,			lowerCamelCase_=0.02						,			lowerCamelCase_=2						,			lowerCamelCase_=0.0						,			lowerCamelCase_=True						,			lowerCamelCase_=0						,			lowerCamelCase_=2						,			lowerCamelCase_=1						,			lowerCamelCase_="block_sparse"						,			lowerCamelCase_=64						,			lowerCamelCase_=3						,			lowerCamelCase_=False						,			**lowerCamelCase_						,			):
						"""simple docstring"""

						a   	=  vocab_size
						a   	=  max_position_embeddings
						a   	=  d_model
						a   	=  encoder_ffn_dim
						a   	=  encoder_layers
						a   	=  encoder_attention_heads
						a   	=  decoder_ffn_dim
						a   	=  decoder_layers
						a   	=  decoder_attention_heads
						a   	=  dropout
						a   	=  attention_dropout
						a   	=  activation_dropout
						a   	=  activation_function
						a   	=  init_std
						a   	=  encoder_layerdrop
						a   	=  decoder_layerdrop
						a   	=  classifier_dropout
						a   	=  use_cache
						a   	=  encoder_layers
						a   	=  scale_embedding  # scale factor will be sqrt(d_model) if True

						# extra config
						a   	=  attention_type
						a   	=  block_size
						a   	=  num_random_blocks
						a   	=  use_bias

						super().__init__(
						    pad_token_id=lowerCamelCase_						,			bos_token_id=lowerCamelCase_						,			eos_token_id=lowerCamelCase_						,			is_encoder_decoder=lowerCamelCase_						,			decoder_start_token_id=lowerCamelCase_						,			**lowerCamelCase_						,			)




class       _lowercase				(  lowerCAmelCase      ):





	"""simple docstring"""




	@property
	def 	UpperCamelCase_			(self						):
						"""simple docstring"""

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

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

											if self.use_past:
																self.fill_with_past_key_values_(lowerCamelCase_						,			direction="inputs"						)
						elif self.task == "causal-lm":
											# TODO: figure this case out.
											a   	=  OrderedDict(
											    [
											        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
											        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
											    ]						)
											if self.use_past:
																a	,							a   	=  self.num_layers
																for i in range(lowerCamelCase_						):
																					a   	=  {0: "batch", 2: "past_sequence + sequence"}
																					a   	=  {0: "batch", 2: "past_sequence + sequence"}
						else:
											a   	=  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 	UpperCamelCase_			(self						):
						"""simple docstring"""

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




	def 	UpperCamelCase_			(self						,			lowerCamelCase_						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = False						,			lowerCamelCase_ = None						,			):
						"""simple docstring"""

						a   	=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						)

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

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

											a   	=  torch.cat(
											    [common_inputs["decoder_attention_mask"], torch.ones(lowerCamelCase_						,			lowerCamelCase_						)]						,			dim=1						)

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

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




	def 	UpperCamelCase_			(self						,			lowerCamelCase_						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = False						,			lowerCamelCase_ = None						,			):
						"""simple docstring"""

						a   	=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						)

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

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




	def 	UpperCamelCase_			(self						,			lowerCamelCase_						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = False						,			lowerCamelCase_ = None						,			):
						"""simple docstring"""

						a   	=  compute_effective_axis_dimension(
						    lowerCamelCase_						,			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
						a   	=  tokenizer.num_special_tokens_to_add(lowerCamelCase_						)
						a   	=  compute_effective_axis_dimension(
						    lowerCamelCase_						,			fixed_dimension=OnnxConfig.default_fixed_sequence						,			num_token_to_add=lowerCamelCase_						)

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




	def 	UpperCamelCase_			(self						,			lowerCamelCase_						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = -1						,			lowerCamelCase_ = False						,			lowerCamelCase_ = None						,			):
						"""simple docstring"""

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

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

						return common_inputs




	def 	UpperCamelCase_			(self						,			lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						,			lowerCamelCase_						):
						"""simple docstring"""

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





import platform
from argparse import ArgumentParser

import huggingface_hub
import pandas
import pyarrow

from datasets import __version__ as version
from datasets.commands import BaseDatasetsCLICommand






def        a( A			:       Dict			)						->			Optional[int]:
					"""simple docstring"""





					return EnvironmentCommand()







class       _lowercase				(  lowerCAmelCase      ):





	"""simple docstring"""




	@staticmethod
	def 	UpperCamelCase_			(lowerCamelCase_						):
						"""simple docstring"""

						a   	=  parser.add_parser("env"						,			help="Print relevant system environment info."						)
						download_parser.set_defaults(func=lowerCamelCase_						)




	def 	UpperCamelCase_			(self						):
						"""simple docstring"""

						a   	=  {
						    "`datasets` version": version,
						    "Platform": platform.platform(),
						    "Python version": platform.python_version(),
						    "Huggingface_hub version": huggingface_hub.__version__,
						    "PyArrow version": pyarrow.__version__,
						    "Pandas version": pandas.__version__,
						}

						print("\nCopy-and-paste the text below in your GitHub issue.\n"						)
						print(self.format_dict(lowerCamelCase_						)						)

						return info




	@staticmethod
	def 	UpperCamelCase_			(lowerCamelCase_						):
						"""simple docstring"""

						return "\n".join([F'''- {prop}: {val}''' for prop, val in d.items()]						) + "\n"
