





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


__UpperCAmelCase						=      logging.get_logger(__name__)

__UpperCAmelCase						=      {
    '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 		__a							(	__UpperCamelCase      ):
       __snake_case						:   str      =		"""bigbird_pegasus"""
       __snake_case						:   Optional[int]      =		["""past_key_values"""]
       __snake_case						:   Any      =		{
           """num_attention_heads""": """encoder_attention_heads""",
           """hidden_size""": """d_model""",
           """attention_probs_dropout_prob""": """attention_dropout""",
       }



       def __init__(     self	:   Any					,			UpperCAmelCase	:   Tuple=9_61_03					,			UpperCAmelCase	:   List[str]=40_96					,			UpperCAmelCase	:   str=16					,			UpperCAmelCase	:   Any=40_96					,			UpperCAmelCase	:   Dict=16					,			UpperCAmelCase	:   List[Any]=16					,			UpperCAmelCase	:   str=40_96					,			UpperCAmelCase	:   Optional[Any]=16					,			UpperCAmelCase	:   str=0.0					,			UpperCAmelCase	:   Dict=0.0					,			UpperCAmelCase	:   List[str]=True					,			UpperCAmelCase	:   Tuple=True					,			UpperCAmelCase	:   str="gelu_new"					,			UpperCAmelCase	:   Tuple=10_24					,			UpperCAmelCase	:   Optional[Any]=0.1					,			UpperCAmelCase	:   Any=0.0					,			UpperCAmelCase	:   Dict=0.0					,			UpperCAmelCase	:   int=0.02					,			UpperCAmelCase	:   Dict=2					,			UpperCAmelCase	:   List[str]=0.0					,			UpperCAmelCase	:   Optional[int]=True					,			UpperCAmelCase	:   List[Any]=0					,			UpperCAmelCase	:   List[str]=2					,			UpperCAmelCase	:   Tuple=1					,			UpperCAmelCase	:   Optional[Any]="block_sparse"					,			UpperCAmelCase	:   List[str]=64					,			UpperCAmelCase	:   Any=3					,			UpperCAmelCase	:   Any=False					,			**UpperCAmelCase	:   str					,			):
           lowerCAmelCase_					:	Union[str, Any]						=   vocab_size
           lowerCAmelCase_					:	Dict						=   max_position_embeddings
           lowerCAmelCase_					:	str						=   d_model
           lowerCAmelCase_					:	Optional[int]						=   encoder_ffn_dim
           lowerCAmelCase_					:	str						=   encoder_layers
           lowerCAmelCase_					:	Optional[int]						=   encoder_attention_heads
           lowerCAmelCase_					:	Optional[Any]						=   decoder_ffn_dim
           lowerCAmelCase_					:	int						=   decoder_layers
           lowerCAmelCase_					:	List[Any]						=   decoder_attention_heads
           lowerCAmelCase_					:	Tuple						=   dropout
           lowerCAmelCase_					:	Dict						=   attention_dropout
           lowerCAmelCase_					:	str						=   activation_dropout
           lowerCAmelCase_					:	str						=   activation_function
           lowerCAmelCase_					:	Optional[int]						=   init_std
           lowerCAmelCase_					:	List[Any]						=   encoder_layerdrop
           lowerCAmelCase_					:	Tuple						=   decoder_layerdrop
           lowerCAmelCase_					:	int						=   classifier_dropout
           lowerCAmelCase_					:	List[str]						=   use_cache
           lowerCAmelCase_					:	Dict						=   encoder_layers
           lowerCAmelCase_					:	List[Any]						=   scale_embedding  # scale factor will be sqrt(d_model) if True

           # extra config
           lowerCAmelCase_					:	Any						=   attention_type
           lowerCAmelCase_					:	List[Any]						=   block_size
           lowerCAmelCase_					:	Optional[int]						=   num_random_blocks
           lowerCAmelCase_					:	Dict						=   use_bias

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






class 		__a							(	__UpperCamelCase      ):



       @property
       def  A							(     self	:   Optional[Any]			):
           if self.task in ["default", "seq2seq-lm"]:
               lowerCAmelCase_					:	List[Any]						=   OrderedDict(
                   [
                       ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                       ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                   ]			)

               if self.use_past:
                   lowerCAmelCase_					:	Optional[Any]						=   {0: """batch"""}
                   lowerCAmelCase_					:	int						=   {0: """batch""", 1: """past_decoder_sequence + sequence"""}
               else:
                   lowerCAmelCase_					:	Any						=   {0: """batch""", 1: """decoder_sequence"""}
                   lowerCAmelCase_					:	List[Any]						=   {0: """batch""", 1: """decoder_sequence"""}

               if self.use_past:
                   self.fill_with_past_key_values_(UpperCAmelCase					,			direction="""inputs"""			)
           elif self.task == "causal-lm":
               # TODO: figure this case out.
               lowerCAmelCase_					:	int						=   OrderedDict(
                   [
                       ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                       ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                   ]			)
               if self.use_past:
                   lowerCAmelCase_		,		lowerCAmelCase_					:	List[str]						=   self.num_layers
                   for i in range(UpperCAmelCase			):
                       lowerCAmelCase_					:	Dict						=   {0: """batch""", 2: """past_sequence + sequence"""}
                       lowerCAmelCase_					:	Tuple						=   {0: """batch""", 2: """past_sequence + sequence"""}
           else:
               lowerCAmelCase_					:	Any						=   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	:   Optional[Any]			):
           if self.task in ["default", "seq2seq-lm"]:
               lowerCAmelCase_					:	List[str]						=   super().outputs
           else:
               lowerCAmelCase_					:	List[str]						=   super(UpperCAmelCase					,			self			).outputs
               if self.use_past:
                   lowerCAmelCase_		,		lowerCAmelCase_					:	List[Any]						=   self.num_layers
                   for i in range(UpperCAmelCase			):
                       lowerCAmelCase_					:	Optional[int]						=   {0: """batch""", 2: """past_sequence + sequence"""}
                       lowerCAmelCase_					:	Optional[int]						=   {0: """batch""", 2: """past_sequence + sequence"""}
           return common_outputs



       def  A							(     self	:   Dict					,			UpperCAmelCase	:   PreTrainedTokenizer					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   bool = False					,			UpperCAmelCase	:   Optional[TensorType] = None					,			):
           lowerCAmelCase_					:	List[str]						=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase			)

           # Generate decoder inputs
           lowerCAmelCase_					:	int						=   seq_length if not self.use_past else 1
           lowerCAmelCase_					:	Optional[Any]						=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase			)
           lowerCAmelCase_					:	List[Any]						=   {F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
           lowerCAmelCase_					:	Union[str, Any]						=   dict(**UpperCAmelCase					,			**UpperCAmelCase			)

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

               lowerCAmelCase_					:	List[str]						=   torch.cat(
                   [common_inputs["""decoder_attention_mask"""], torch.ones(UpperCAmelCase					,			UpperCAmelCase			)]					,			dim=1			)

               lowerCAmelCase_					:	List[Any]						=   []
               # If the number of encoder and decoder layers are present in the model configuration, both are considered
               lowerCAmelCase_		,		lowerCAmelCase_					:	Dict						=   self.num_layers
               lowerCAmelCase_					:	Optional[int]						=   min(UpperCAmelCase					,			UpperCAmelCase			)
               lowerCAmelCase_					:	Any						=   max(UpperCAmelCase					,			UpperCAmelCase			) - min_num_layers
               lowerCAmelCase_					:	str						=   """encoder""" if num_encoder_layers > num_decoder_layers else """decoder"""

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



       def  A							(     self	:   Optional[int]					,			UpperCAmelCase	:   PreTrainedTokenizer					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   bool = False					,			UpperCAmelCase	:   Optional[TensorType] = None					,			):
           lowerCAmelCase_					:	Optional[int]						=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase			)

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

               lowerCAmelCase_					:	Optional[Any]						=   common_inputs["""attention_mask"""].dtype
               lowerCAmelCase_					:	Optional[int]						=   torch.cat(
                   [common_inputs["""attention_mask"""], torch.ones(UpperCAmelCase					,			UpperCAmelCase					,			dtype=UpperCAmelCase			)]					,			dim=1			)
               lowerCAmelCase_					:	Dict						=   [
                   (torch.zeros(UpperCAmelCase			), torch.zeros(UpperCAmelCase			)) for _ in range(UpperCAmelCase			)
               ]
           return common_inputs



       def  A							(     self	:   int					,			UpperCAmelCase	:   PreTrainedTokenizer					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   bool = False					,			UpperCAmelCase	:   Optional[TensorType] = None					,			):
           # Copied from OnnxConfig.generate_dummy_inputs
           # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
           # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
           lowerCAmelCase_					:	List[Any]						=   compute_effective_axis_dimension(
               UpperCAmelCase					,			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
           lowerCAmelCase_					:	List[str]						=   tokenizer.num_special_tokens_to_add(UpperCAmelCase			)
           lowerCAmelCase_					:	str						=   compute_effective_axis_dimension(
               UpperCAmelCase					,			fixed_dimension=OnnxConfig.default_fixed_sequence					,			num_token_to_add=UpperCAmelCase			)

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



       def  A							(     self	:   int					,			UpperCAmelCase	:   PreTrainedTokenizer					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   int = -1					,			UpperCAmelCase	:   bool = False					,			UpperCAmelCase	:   Optional[TensorType] = None					,			):
           if self.task in ["default", "seq2seq-lm"]:
               lowerCAmelCase_					:	Any						=   self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                   UpperCAmelCase					,			batch_size=UpperCAmelCase					,			seq_length=UpperCAmelCase					,			is_pair=UpperCAmelCase					,			framework=UpperCAmelCase			)

           elif self.task == "causal-lm":
               lowerCAmelCase_					:	Any						=   self._generate_dummy_inputs_for_causal_lm(
                   UpperCAmelCase					,			batch_size=UpperCAmelCase					,			seq_length=UpperCAmelCase					,			is_pair=UpperCAmelCase					,			framework=UpperCAmelCase			)
           else:
               lowerCAmelCase_					:	int						=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                   UpperCAmelCase					,			batch_size=UpperCAmelCase					,			seq_length=UpperCAmelCase					,			is_pair=UpperCAmelCase					,			framework=UpperCAmelCase			)

           return common_inputs



       def  A							(     self	:   Tuple					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   Optional[Any]			):
           if self.task in ["default", "seq2seq-lm"]:
               lowerCAmelCase_					:	Tuple						=   super()._flatten_past_key_values_(UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase			)
           else:
               lowerCAmelCase_					:	List[str]						=   super(UpperCAmelCase					,			self			)._flatten_past_key_values_(
                   UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase					,			UpperCAmelCase			)









def 			__UpperCamelCase				(			lowercase__	:       set		,    lowercase__	:       set		)	->      set:
    '''simple docstring'''





    assert isinstance(lowercase__		,    lowercase__		), f'The input value of [set_a={set_a}] is not a set'
    assert isinstance(lowercase__		,    lowercase__		), f'The input value of [set_b={set_b}] is not a set'

    return {a + b for a in set_a for b in set_b}


if __name__ == "__main__":
  from doctest import testmod

  testmod()


