



from doctest import testmod
from math import sqrt





def     __lowerCamelCase							(   __magic_name__						:	int    ):
							a__:							list[int]									=[]
							if num < 1:
														return facs
							facs.append(1    )
							if num == 1:
														return facs
							facs.append(__magic_name__    )
							for i in range(2  ,			int(sqrt(__magic_name__    )    ) + 1    ):
														if num % i == 0:  # If i is a factor of num
																					facs.append(__magic_name__    )
																					a__:							List[Any]									=num // i  # num//i is the other factor of num
																					if d != i:  # If d and i are distinct
																												facs.append(__magic_name__    )  # we have found another factor
							facs.sort()
							return facs


if __name__ == "__main__":
		testmod(name='''factors_of_a_number''', verbose=True)










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 						lowerCamelCase__			(		_a ):
						_lowerCAmelCase             =			'''bigbird_pegasus'''
						_lowerCAmelCase             =			['''past_key_values''']
						_lowerCAmelCase             =			{
						    '''num_attention_heads''': '''encoder_attention_heads''',
						    '''hidden_size''': '''d_model''',
						    '''attention_probs_dropout_prob''': '''attention_dropout''',
						}


						def __init__(			self    :	int   ,							_a    :	List[Any]=9_6_1_0_3   ,							_a    :	Tuple=4_0_9_6   ,							_a    :	int=1_6   ,							_a    :	Dict=4_0_9_6   ,							_a    :	List[str]=1_6   ,							_a    :	Tuple=1_6   ,							_a    :	Union[str, Any]=4_0_9_6   ,							_a    :	int=1_6   ,							_a    :	Any=0.0   ,							_a    :	Union[str, Any]=0.0   ,							_a    :	Tuple=True   ,							_a    :	List[str]=True   ,							_a    :	Union[str, Any]="gelu_new"   ,							_a    :	Tuple=1_0_2_4   ,							_a    :	List[str]=0.1   ,							_a    :	Tuple=0.0   ,							_a    :	Any=0.0   ,							_a    :	int=0.0_2   ,							_a    :	str=2   ,							_a    :	Dict=0.0   ,							_a    :	Dict=True   ,							_a    :	List[str]=0   ,							_a    :	Dict=2   ,							_a    :	Any=1   ,							_a    :	Union[str, Any]="block_sparse"   ,							_a    :	Tuple=6_4   ,							_a    :	Tuple=3   ,							_a    :	List[str]=False   ,							**_a    :	Optional[Any]   ,							):
													a__:							Any									=vocab_size
													a__:							str									=max_position_embeddings
													a__:							str									=d_model
													a__:							int									=encoder_ffn_dim
													a__:							Optional[Any]									=encoder_layers
													a__:							Any									=encoder_attention_heads
													a__:							int									=decoder_ffn_dim
													a__:							Dict									=decoder_layers
													a__:							Dict									=decoder_attention_heads
													a__:							Union[str, Any]									=dropout
													a__:							List[Any]									=attention_dropout
													a__:							int									=activation_dropout
													a__:							Union[str, Any]									=activation_function
													a__:							Optional[int]									=init_std
													a__:							List[Any]									=encoder_layerdrop
													a__:							Dict									=decoder_layerdrop
													a__:							int									=classifier_dropout
													a__:							List[Any]									=use_cache
													a__:							int									=encoder_layers
													a__:							List[Any]									=scale_embedding  # scale factor will be sqrt(d_model) if True

													# extra config
													a__:							Any									=attention_type
													a__:							Any									=block_size
													a__:							int									=num_random_blocks
													a__:							List[str]									=use_bias

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


class 						lowerCamelCase__			(		_a ):


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

																				if self.use_past:
																											a__:							List[Any]									={0: "batch"}
																											a__:							int									={0: "batch", 1: "past_decoder_sequence + sequence"}
																				else:
																											a__:							List[str]									={0: "batch", 1: "decoder_sequence"}
																											a__:							Optional[int]									={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.
																				a__:							List[str]									=OrderedDict(
																				    [
																				        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																				        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																				    ]      )
																				if self.use_past:
																											a__				,      a__:							str									=self.num_layers
																											for i in range(_a      ):
																																		a__:							Any									={0: "batch", 2: "past_sequence + sequence"}
																																		a__:							Any									={0: "batch", 2: "past_sequence + sequence"}
													else:
																				a__:							int									=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 	_lowerCamelCase      (			self    :	Union[str, Any]      ):
													if self.task in ["default", "seq2seq-lm"]:
																				a__:							str									=super().outputs
													else:
																				a__:							Dict									=super(_a   ,							self      ).outputs
																				if self.use_past:
																											a__				,      a__:							Tuple									=self.num_layers
																											for i in range(_a      ):
																																		a__:							str									={0: "batch", 2: "past_sequence + sequence"}
																																		a__:							List[str]									={0: "batch", 2: "past_sequence + sequence"}
													return common_outputs


						def 	_lowerCamelCase      (			self    :	Union[str, Any]   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													a__:							Union[str, Any]									=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    _a   ,							_a   ,							_a   ,							_a   ,							_a      )

													# Generate decoder inputs
													a__:							str									=seq_length if not self.use_past else 1
													a__:							Dict									=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    _a   ,							_a   ,							_a   ,							_a   ,							_a      )
													a__:							List[str]									={F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
													a__:							str									=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
																				a__				,      a__:							str									=common_inputs["input_ids"].shape
																				a__:							List[str]									=common_inputs["decoder_input_ids"].shape[1]
																				a__				,      a__:							Any									=self.num_attention_heads
																				a__:							int									=(
																				    batch,
																				    num_encoder_attention_heads,
																				    encoder_seq_length,
																				    self._config.hidden_size // num_encoder_attention_heads,
																				)
																				a__:							str									=decoder_seq_length + 3
																				a__:							List[str]									=(
																				    batch,
																				    num_decoder_attention_heads,
																				    decoder_past_length,
																				    self._config.hidden_size // num_decoder_attention_heads,
																				)

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

																				a__:							List[str]									=[]
																				# If the number of encoder and decoder layers are present in the model configuration, both are considered
																				a__				,      a__:							int									=self.num_layers
																				a__:							List[Any]									=min(_a   ,							_a      )
																				a__:							str									=max(_a   ,							_a      ) - min_num_layers
																				a__:							Optional[Any]									="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.
																				a__:							Any									=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 	_lowerCamelCase      (			self    :	Any   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													a__:							Tuple									=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
																				a__				,      a__:							Tuple									=common_inputs["input_ids"].shape
																				# Not using the same length for past_key_values
																				a__:							str									=seqlen + 2
																				a__				,      a__:							List[str]									=self.num_layers
																				a__				,      a__:							Any									=self.num_attention_heads
																				a__:							Optional[int]									=(
																				    batch,
																				    num_encoder_attention_heads,
																				    past_key_values_length,
																				    self._config.hidden_size // num_encoder_attention_heads,
																				)

																				a__:							int									=common_inputs["attention_mask"].dtype
																				a__:							str									=torch.cat(
																				    [common_inputs["attention_mask"], torch.ones(_a   ,							_a   ,							dtype=_a      )]   ,							dim=1      )
																				a__:							int									=[
																				    (torch.zeros(_a      ), torch.zeros(_a      )) for _ in range(_a      )
																				]
													return common_inputs


						def 	_lowerCamelCase      (			self    :	Tuple   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	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
													a__:							List[str]									=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
													a__:							Optional[int]									=tokenizer.num_special_tokens_to_add(_a      )
													a__:							Any									=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
													a__:							Any									=[" ".join([tokenizer.unk_token]      ) * seq_length] * batch_size
													a__:							Optional[Any]									=dict(tokenizer(_a   ,							return_tensors=_a      )      )
													return common_inputs


						def 	_lowerCamelCase      (			self    :	Dict   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													if self.task in ["default", "seq2seq-lm"]:
																				a__:							Any									=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":
																				a__:							Dict									=self._generate_dummy_inputs_for_causal_lm(
																				    _a   ,							batch_size=_a   ,							seq_length=_a   ,							is_pair=_a   ,							framework=_a      )
													else:
																				a__:							int									=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 	_lowerCamelCase      (			self    :	List[str]   ,							_a    :	int   ,							_a    :	str   ,							_a    :	Any   ,							_a    :	str      ):
													if self.task in ["default", "seq2seq-lm"]:
																				a__:							Tuple									=super()._flatten_past_key_values_(_a   ,							_a   ,							_a   ,							_a      )
													else:
																				a__:							Tuple									=super(_a   ,							self      )._flatten_past_key_values_(
																				    _a   ,							_a   ,							_a   ,							_a      )





