


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

_UpperCAmelCase			:  Any     ={
    """Helsinki-NLP/opus-mt-en-de""": """https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json""",
    # See all Marian models at https://huggingface.co/models?filter=marian
}







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Union[str, Any]					=							"""marian"""
						SCREAMING_SNAKE_CASE__      :  Union[str, Any]					=							["""past_key_values"""]
						SCREAMING_SNAKE_CASE__      :  Optional[Any]					=							{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}




						def __init__(				self   ,						__lowercase=5_8_1_0_1   ,						__lowercase=None   ,						__lowercase=1_0_2_4   ,						__lowercase=1_2   ,						__lowercase=4_0_9_6   ,						__lowercase=1_6   ,						__lowercase=1_2   ,						__lowercase=4_0_9_6   ,						__lowercase=1_6   ,						__lowercase=0.0   ,						__lowercase=0.0   ,						__lowercase=True   ,						__lowercase=True   ,						__lowercase="gelu"   ,						__lowercase=1_0_2_4   ,						__lowercase=0.1   ,						__lowercase=0.0   ,						__lowercase=0.0   ,						__lowercase=0.02   ,						__lowercase=5_8_1_0_0   ,						__lowercase=False   ,						__lowercase=5_8_1_0_0   ,						__lowercase=0   ,						__lowercase=0   ,						__lowercase=True   ,						**__lowercase   ,						)					->    List[str]:
										lowerCAmelCase_ :      Union[str, Any]    				=				vocab_size
										lowerCAmelCase_ :      Union[str, Any]    				=				decoder_vocab_size or vocab_size
										lowerCAmelCase_ :      Optional[Any]    				=				max_position_embeddings
										lowerCAmelCase_ :      Union[str, Any]    				=				d_model
										lowerCAmelCase_ :      List[Any]    				=				encoder_ffn_dim
										lowerCAmelCase_ :      Optional[int]    				=				encoder_layers
										lowerCAmelCase_ :      Union[str, Any]    				=				encoder_attention_heads
										lowerCAmelCase_ :      List[str]    				=				decoder_ffn_dim
										lowerCAmelCase_ :      Optional[int]    				=				decoder_layers
										lowerCAmelCase_ :      Union[str, Any]    				=				decoder_attention_heads
										lowerCAmelCase_ :      Union[str, Any]    				=				dropout
										lowerCAmelCase_ :      str    				=				attention_dropout
										lowerCAmelCase_ :      Any    				=				activation_dropout
										lowerCAmelCase_ :      Union[str, Any]    				=				activation_function
										lowerCAmelCase_ :      Optional[Any]    				=				init_std
										lowerCAmelCase_ :      Optional[int]    				=				encoder_layerdrop
										lowerCAmelCase_ :      Tuple    				=				decoder_layerdrop
										lowerCAmelCase_ :      str    				=				use_cache
										lowerCAmelCase_ :      Union[str, Any]    				=				encoder_layers
										lowerCAmelCase_ :      Any    				=				scale_embedding  # scale factor will be sqrt(d_model) if True
										lowerCAmelCase_ :      Any    				=				share_encoder_decoder_embeddings
										super().__init__(
										    pad_token_id=__lowercase   ,						eos_token_id=__lowercase   ,						is_encoder_decoder=__lowercase   ,						decoder_start_token_id=__lowercase   ,						forced_eos_token_id=__lowercase   ,						**__lowercase   ,						)







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						@property
						# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
						def 						lowercase_ (				self							)					->    Mapping[str, Mapping[int, str]]:
										if self.task in ["default", "seq2seq-lm"]:
														lowerCAmelCase_ :      List[str]    				=				OrderedDict(
														    [
														        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
														        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
														    ]							)

														if self.use_past:
																		lowerCAmelCase_ :      Tuple    				=				{0: '''batch'''}
																		lowerCAmelCase_ :      Dict    				=				{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
														else:
																		lowerCAmelCase_ :      Union[str, Any]    				=				{0: '''batch''', 1: '''decoder_sequence'''}
																		lowerCAmelCase_ :      Dict    				=				{0: '''batch''', 1: '''decoder_sequence'''}

														if self.use_past:
																		self.fill_with_past_key_values_(__lowercase   ,						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_ :      int    				=				self.num_layers
																		for i in range(__lowercase							):
																						lowerCAmelCase_ :      str    				=				{0: '''batch''', 2: '''past_sequence + sequence'''}
																						lowerCAmelCase_ :      int    				=				{0: '''batch''', 2: '''past_sequence + sequence'''}
										else:
														lowerCAmelCase_ :      Optional[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
						# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
						def 						lowercase_ (				self							)					->    Mapping[str, Mapping[int, str]]:
										if self.task in ["default", "seq2seq-lm"]:
														lowerCAmelCase_ :      int    				=				super().outputs
										else:
														lowerCAmelCase_ :      Dict    				=				super(__lowercase   ,						self							).outputs
														if self.use_past:
																		lowerCAmelCase_				,  lowerCAmelCase_ :      Dict    				=				self.num_layers
																		for i in range(__lowercase							):
																						lowerCAmelCase_ :      Tuple    				=				{0: '''batch''', 2: '''past_sequence + sequence'''}
																						lowerCAmelCase_ :      List[Any]    				=				{0: '''batch''', 2: '''past_sequence + sequence'''}
										return common_outputs




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = -1   ,						__lowercase = -1   ,						__lowercase = False   ,						__lowercase = None   ,						)					->    Mapping[str, Any]:
										lowerCAmelCase_ :      Optional[int]    				=				self._generate_dummy_inputs_for_encoder_and_decoder(
										    __lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)

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

										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_ :      str    				=				common_inputs['''input_ids'''].shape
														lowerCAmelCase_ :      List[str]    				=				common_inputs['''decoder_input_ids'''].shape[1]
														lowerCAmelCase_				,  lowerCAmelCase_ :      Optional[int]    				=				self.num_attention_heads
														lowerCAmelCase_ :      Any    				=				(
														    batch,
														    num_encoder_attention_heads,
														    encoder_seq_length,
														    self._config.hidden_size // num_encoder_attention_heads,
														)
														lowerCAmelCase_ :      int    				=				decoder_seq_length + 3
														lowerCAmelCase_ :      List[Any]    				=				(
														    batch,
														    num_decoder_attention_heads,
														    decoder_past_length,
														    self._config.hidden_size // num_decoder_attention_heads,
														)

														lowerCAmelCase_ :      Tuple    				=				torch.cat(
														    [common_inputs['''decoder_attention_mask'''], torch.ones(__lowercase   ,						__lowercase							)]   ,						dim=1							)

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

														for _ in range(__lowercase							):
																		common_inputs["past_key_values"].append(
																		    (
																		        torch.zeros(__lowercase							),
																		        torch.zeros(__lowercase							),
																		        torch.zeros(__lowercase							),
																		        torch.zeros(__lowercase							),
																		    )							)
														# TODO: test this.
														lowerCAmelCase_ :      Union[str, Any]    				=				encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
														for _ in range(__lowercase   ,						__lowercase							):
																		common_inputs["past_key_values"].append((torch.zeros(__lowercase							), torch.zeros(__lowercase							))							)
										return common_inputs




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = -1   ,						__lowercase = -1   ,						__lowercase = False   ,						__lowercase = None   ,						)					->    Mapping[str, Any]:
										lowerCAmelCase_ :      Optional[int]    				=				self._generate_dummy_inputs_for_encoder_and_decoder(
										    __lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)

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

														lowerCAmelCase_ :      List[Any]    				=				common_inputs['''attention_mask'''].dtype
														lowerCAmelCase_ :      str    				=				torch.cat(
														    [common_inputs['''attention_mask'''], torch.ones(__lowercase   ,						__lowercase   ,						dtype=__lowercase							)]   ,						dim=1							)
														lowerCAmelCase_ :      Tuple    				=				[
														    (torch.zeros(__lowercase							), torch.zeros(__lowercase							)) for _ in range(__lowercase							)
														]
										return common_inputs




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = -1   ,						__lowercase = -1   ,						__lowercase = False   ,						__lowercase = None   ,						)					->    Mapping[str, Any]:
										# 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_ :      Dict    				=				compute_effective_axis_dimension(
										    __lowercase   ,						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_ :      Optional[int]    				=				tokenizer.num_special_tokens_to_add(__lowercase							)
										lowerCAmelCase_ :      int    				=				compute_effective_axis_dimension(
										    __lowercase   ,						fixed_dimension=OnnxConfig.default_fixed_sequence   ,						num_token_to_add=__lowercase							)

										# Generate dummy inputs according to compute batch and sequence
										lowerCAmelCase_ :      Optional[int]    				=				[''' '''.join([tokenizer.unk_token]							) * seq_length] * batch_size
										lowerCAmelCase_ :      Optional[int]    				=				dict(tokenizer(__lowercase   ,						return_tensors=__lowercase							)							)
										return common_inputs




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase = -1   ,						__lowercase = -1   ,						__lowercase = False   ,						__lowercase = None   ,						)					->    Mapping[str, Any]:
										if self.task in ["default", "seq2seq-lm"]:
														lowerCAmelCase_ :      Tuple    				=				self._generate_dummy_inputs_for_default_and_seqaseq_lm(
														    __lowercase   ,						batch_size=__lowercase   ,						seq_length=__lowercase   ,						is_pair=__lowercase   ,						framework=__lowercase							)

										else:
														lowerCAmelCase_ :      Dict    				=				self._generate_dummy_inputs_for_causal_lm(
														    __lowercase   ,						batch_size=__lowercase   ,						seq_length=__lowercase   ,						is_pair=__lowercase   ,						framework=__lowercase							)

										return common_inputs




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    Optional[Any]:
										if self.task in ["default", "seq2seq-lm"]:
														lowerCAmelCase_ :      Optional[Any]    				=				super()._flatten_past_key_values_(__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)
										else:
														lowerCAmelCase_ :      Optional[Any]    				=				super(__lowercase   ,						self							)._flatten_past_key_values_(
														    __lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)




						@property
						def 						lowercase_ (				self							)					->    float:
										return 1e-4



import re



def 			lowerCAmelCase (		lowerCAmelCase_ )-> bool:
				lowerCAmelCase_ :      Tuple    				=				re.compile(r'''^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$''' )
				if match := re.search(lowerCAmelCase_ ,   lowerCAmelCase_ ):
								return match.string == phone
				return False


if __name__ == "__main__":
						print(indian_phone_validator("""+918827897895"""))