


'''simple docstring'''


from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


UpperCAmelCase_		:       Tuple							       =		logging.get_logger(__name__)

UpperCAmelCase_		:       str							       =		{
    'facebook/m2m100_418M': 'https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json',
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}





class    lowercase__  (						_snake_case ):





							'''simple docstring'''


							A_							:				Optional[Any]				     =  """m2m_100"""
							A_							:				Any				     =  ["""past_key_values"""]
							A_							:				List[Any]				     =  {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}






							def __init__(   self   , __snake_case=12_8112   , __snake_case=1024   , __snake_case=12   , __snake_case=4096   , __snake_case=16   , __snake_case=12   , __snake_case=4096   , __snake_case=16   , __snake_case=0.05   , __snake_case=0.05   , __snake_case=True   , __snake_case=True   , __snake_case="relu"   , __snake_case=1024   , __snake_case=0.1   , __snake_case=0.1   , __snake_case=0.0   , __snake_case=0.02   , __snake_case=2   , __snake_case=True   , __snake_case=1   , __snake_case=0   , __snake_case=2   , **__snake_case   , ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				vocab_size
											_SCREAMING_SNAKE_CASE			:	Any							=				max_position_embeddings
											_SCREAMING_SNAKE_CASE			:	List[str]							=				d_model
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				encoder_ffn_dim
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				encoder_layers
											_SCREAMING_SNAKE_CASE			:	Tuple							=				encoder_attention_heads
											_SCREAMING_SNAKE_CASE			:	Tuple							=				decoder_ffn_dim
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				decoder_layers
											_SCREAMING_SNAKE_CASE			:	Dict							=				decoder_attention_heads
											_SCREAMING_SNAKE_CASE			:	Any							=				dropout
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				attention_dropout
											_SCREAMING_SNAKE_CASE			:	List[str]							=				activation_dropout
											_SCREAMING_SNAKE_CASE			:	Tuple							=				activation_function
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				init_std
											_SCREAMING_SNAKE_CASE			:	int							=				encoder_layerdrop
											_SCREAMING_SNAKE_CASE			:	List[str]							=				decoder_layerdrop
											_SCREAMING_SNAKE_CASE			:	Tuple							=				use_cache
											_SCREAMING_SNAKE_CASE			:	Dict							=				encoder_layers
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				scale_embedding  # scale factor will be sqrt(d_model) if True

											super().__init__(
											    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   , **__snake_case   , )





class    lowercase__  (						_snake_case ):





							'''simple docstring'''


							@property
							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	str							=				OrderedDict(
											    [
											        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
											        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
											    ]  )

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

											if self.use_past:
															self.fill_with_past_key_values_(__snake_case   , direction="""inputs"""  )
											return common_inputs






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case = -1   , __snake_case = -1   , __snake_case = False   , __snake_case = 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
											_SCREAMING_SNAKE_CASE			:	Tuple							=				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
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				tokenizer.num_special_tokens_to_add(__snake_case  )
											_SCREAMING_SNAKE_CASE			:	int							=				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
											_SCREAMING_SNAKE_CASE			:	Tuple							=				[""" """.join([tokenizer.unk_token]  ) * seq_length] * batch_size
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				dict(tokenizer(__snake_case   , return_tensors=__snake_case  )  )
											return common_inputs






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case = -1   , __snake_case = -1   , __snake_case = False   , __snake_case = None   , ):
											_SCREAMING_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
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				seq_length if not self.use_past else 1
											_SCREAMING_SNAKE_CASE			:	int							=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
											    __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case  )
											_SCREAMING_SNAKE_CASE			:	Any							=				{f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				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
															_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	int							=				common_inputs["""input_ids"""].shape
															_SCREAMING_SNAKE_CASE			:	int							=				common_inputs["""decoder_input_ids"""].shape[1]
															_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Optional[int]							=				self.num_attention_heads
															_SCREAMING_SNAKE_CASE			:	int							=				(
															    batch,
															    num_encoder_attention_heads,
															    encoder_seq_length,
															    self._config.hidden_size // num_encoder_attention_heads,
															)
															_SCREAMING_SNAKE_CASE			:	List[Any]							=				decoder_seq_length + 3
															_SCREAMING_SNAKE_CASE			:	Tuple							=				(
															    batch,
															    num_decoder_attention_heads,
															    decoder_past_length,
															    self._config.hidden_size // num_decoder_attention_heads,
															)

															_SCREAMING_SNAKE_CASE			:	int							=				torch.cat(
															    [common_inputs["""decoder_attention_mask"""], torch.ones(__snake_case   , __snake_case  )]   , dim=1  )

															_SCREAMING_SNAKE_CASE			:	Optional[int]							=				[]
															# If the number of encoder and decoder layers are present in the model configuration, both are considered
															_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	List[Any]							=				self.num_layers
															_SCREAMING_SNAKE_CASE			:	int							=				min(__snake_case   , __snake_case  )
															_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				max(__snake_case   , __snake_case  ) - min_num_layers
															_SCREAMING_SNAKE_CASE			:	List[str]							=				"""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.
															_SCREAMING_SNAKE_CASE			:	Optional[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



							A_							:				Union[str, Any]				     =  _generate_dummy_inputs_for_default_and_seqaseq_lm








'''simple docstring'''


def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





				if len(str(SCREAMING_SNAKE_CASE__					)					) == 1 or len(str(SCREAMING_SNAKE_CASE__					)					) == 1:
								return a * b

				_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				max(len(str(SCREAMING_SNAKE_CASE__					)					)							,				len(str(SCREAMING_SNAKE_CASE__					)					)					)
				_SCREAMING_SNAKE_CASE			:	Tuple							=				ma // 2

				_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Optional[int]							=				divmod(SCREAMING_SNAKE_CASE__							,				10**ma					)
				_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Optional[int]							=				divmod(SCREAMING_SNAKE_CASE__							,				10**ma					)

				_SCREAMING_SNAKE_CASE			:	Dict							=				karatsuba(SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					)
				_SCREAMING_SNAKE_CASE			:	List[Any]							=				karatsuba((aa + aa)							,				(ba + ba)					)
				_SCREAMING_SNAKE_CASE			:	List[Any]							=				karatsuba(SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					)

				return (z * 10 ** (2 * ma)) + ((y - z - x) * 10 ** (ma)) + (x)







def       snake_case_       (  ):







				"""simple docstring"""





				print(karatsuba(1_5463							,				2_3489					)					)


if __name__ == "__main__":
				main()




