

'''simple docstring'''


def 	_a       (				__lowerCAmelCase		:      int     ):

		"""simple docstring"""

		if a < 0:
				raise ValueError('''Input value must be a positive integer'''     )
		elif isinstance(__lowerCAmelCase   ,							__lowerCAmelCase     ):
				raise TypeError('''Input value must be a \'int\' type'''     )
		return bin(__lowerCAmelCase     ).count('''1'''     )


if __name__ == "__main__":
					import doctest

					doctest.testmod()






'''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__						:       Optional[Any]										=						logging.get_logger(__name__)

lowerCAmelCase__						:       Optional[int]										=						{
    """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     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




						__UpperCAmelCase			     =    """bart"""
						__UpperCAmelCase			     =    ["""past_key_values"""]
						__UpperCAmelCase			     =    {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}







						def __init__(							self					:      Optional[Any]			,			snake_case_					:      Tuple=5_0_2_6_5			,			snake_case_					:      Dict=1_0_2_4			,			snake_case_					:      int=1_2			,			snake_case_					:      int=4_0_9_6			,			snake_case_					:      str=1_6			,			snake_case_					:      List[Any]=1_2			,			snake_case_					:      List[Any]=4_0_9_6			,			snake_case_					:      Any=1_6			,			snake_case_					:      str=0.0			,			snake_case_					:      Optional[int]=0.0			,			snake_case_					:      List[Any]="gelu"			,			snake_case_					:      List[Any]=1_0_2_4			,			snake_case_					:      Union[str, Any]=0.1			,			snake_case_					:      int=0.0			,			snake_case_					:      Tuple=0.0			,			snake_case_					:      Optional[Any]=0.0_2			,			snake_case_					:      Dict=0.0			,			snake_case_					:      str=False			,			snake_case_					:      Optional[int]=True			,			snake_case_					:      Any=3			,			snake_case_					:      int=1			,			snake_case_					:      int=0			,			snake_case_					:      Optional[Any]=2			,			snake_case_					:      str=True			,			snake_case_					:      int=2			,			snake_case_					:      Union[str, Any]=2			,			**snake_case_					:      int			,			):



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  vocab_size
								snake_case__						:       int       						=  max_position_embeddings
								snake_case__						:       List[str]       						=  d_model
								snake_case__						:       Optional[int]       						=  encoder_ffn_dim
								snake_case__						:       Union[str, Any]       						=  encoder_layers
								snake_case__						:       Tuple       						=  encoder_attention_heads
								snake_case__						:       List[Any]       						=  decoder_ffn_dim
								snake_case__						:       Optional[Any]       						=  decoder_layers
								snake_case__						:       Tuple       						=  decoder_attention_heads
								snake_case__						:       Any       						=  dropout
								snake_case__						:       str       						=  attention_dropout
								snake_case__						:       Optional[int]       						=  activation_dropout
								snake_case__						:       Tuple       						=  activation_function
								snake_case__						:       Optional[int]       						=  init_std
								snake_case__						:       Optional[Any]       						=  encoder_layerdrop
								snake_case__						:       Tuple       						=  decoder_layerdrop
								snake_case__						:       Any       						=  classifier_dropout
								snake_case__						:       List[str]       						=  use_cache
								snake_case__						:       Tuple       						=  encoder_layers
								snake_case__						:       Union[str, Any]       						=  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_  ):
										snake_case__						:       Union[str, Any]       						=  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     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




						@property
						def       __magic_name__							(							self					:      List[str]  ):



								'''simple docstring'''



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

										if self.use_past:
												snake_case__						:       List[str]       						=  {0: '''batch'''}
												snake_case__						:       int       						=  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
										else:
												snake_case__						:       List[Any]       						=  {0: '''batch''', 1: '''decoder_sequence'''}
												snake_case__						:       Optional[int]       						=  {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.
										snake_case__						:       int       						=  OrderedDict(
										    [
										        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
										        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
										    ]  )
										if self.use_past:
												snake_case__						,       snake_case__						:       Tuple       						=  self.num_layers
												for i in range(snake_case_  ):
														snake_case__						:       List[str]       						=  {0: '''batch''', 2: '''past_sequence + sequence'''}
														snake_case__						:       Tuple       						=  {0: '''batch''', 2: '''past_sequence + sequence'''}
								else:
										snake_case__						:       List[str]       						=  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       __magic_name__							(							self					:      Optional[int]  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      Optional[Any]			,			snake_case_					:      PreTrainedTokenizer			,			snake_case_					:      int = -1			,			snake_case_					:      int = -1			,			snake_case_					:      bool = False			,			snake_case_					:      Optional[TensorType] = None			,			):



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    snake_case_			,			snake_case_			,			snake_case_			,			snake_case_			,			snake_case_  )

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

										snake_case__						:       Optional[Any]       						=  torch.cat(
										    [common_inputs['''decoder_attention_mask'''], torch.ones(snake_case_			,			snake_case_  )]			,			dim=1  )

										snake_case__						:       Any       						=  []
										# If the number of encoder and decoder layers are present in the model configuration, both are considered
										snake_case__						,       snake_case__						:       str       						=  self.num_layers
										snake_case__						:       Any       						=  min(snake_case_			,			snake_case_  )
										snake_case__						:       Union[str, Any]       						=  max(snake_case_			,			snake_case_  ) - min_num_layers
										snake_case__						:       Optional[int]       						=  '''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.
										snake_case__						:       int       						=  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       __magic_name__							(							self					:      List[str]			,			snake_case_					:      PreTrainedTokenizer			,			snake_case_					:      int = -1			,			snake_case_					:      int = -1			,			snake_case_					:      bool = False			,			snake_case_					:      Optional[TensorType] = None			,			):



								'''simple docstring'''



								snake_case__						:       Any       						=  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
										snake_case__						,       snake_case__						:       Dict       						=  common_inputs['''input_ids'''].shape
										# Not using the same length for past_key_values
										snake_case__						:       str       						=  seqlen + 2
										snake_case__						,       snake_case__						:       Union[str, Any]       						=  self.num_layers
										snake_case__						,       snake_case__						:       Optional[int]       						=  self.num_attention_heads
										snake_case__						:       str       						=  (
										    batch,
										    num_encoder_attention_heads,
										    past_key_values_length,
										    self._config.hidden_size // num_encoder_attention_heads,
										)

										snake_case__						:       List[Any]       						=  common_inputs['''attention_mask'''].dtype
										snake_case__						:       List[Any]       						=  torch.cat(
										    [common_inputs['''attention_mask'''], torch.ones(snake_case_			,			snake_case_			,			dtype=snake_case_  )]			,			dim=1  )
										snake_case__						:       Optional[Any]       						=  [
										    (torch.zeros(snake_case_  ), torch.zeros(snake_case_  )) for _ in range(snake_case_  )
										]
								return common_inputs







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



								'''simple docstring'''



								snake_case__						:       str       						=  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
								snake_case__						:       List[Any]       						=  tokenizer.num_special_tokens_to_add(snake_case_  )
								snake_case__						:       List[str]       						=  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
								snake_case__						:       Any       						=  [''' '''.join([tokenizer.unk_token]  ) * seq_length] * batch_size
								snake_case__						:       Any       						=  dict(tokenizer(snake_case_			,			return_tensors=snake_case_  )  )
								return common_inputs







						def       __magic_name__							(							self					:      Optional[Any]			,			snake_case_					:      PreTrainedTokenizer			,			snake_case_					:      int = -1			,			snake_case_					:      int = -1			,			snake_case_					:      bool = False			,			snake_case_					:      Optional[TensorType] = None			,			):



								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
										snake_case__						:       int       						=  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":
										snake_case__						:       Optional[Any]       						=  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:
										snake_case__						:       Optional[int]       						=  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       __magic_name__							(							self					:      Tuple			,			snake_case_					:      List[str]			,			snake_case_					:      Union[str, Any]			,			snake_case_					:      Any			,			snake_case_					:      Any  ):



								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
										snake_case__						:       Optional[Any]       						=  super()._flatten_past_key_values_(snake_case_			,			snake_case_			,			snake_case_			,			snake_case_  )
								else:
										snake_case__						:       Union[str, Any]       						=  super(snake_case_			,			self  )._flatten_past_key_values_(
										    snake_case_			,			snake_case_			,			snake_case_			,			snake_case_  )



