

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


lowercase     :       Dict        =       logging.get_logger(__name__)

lowercase     :       List[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 		SCREAMING_SNAKE_CASE__					(		UpperCAmelCase_   ):







						"""simple docstring"""




						lowercase  :				int											=							'm2m_100'
						lowercase  :				int											=							['past_key_values']
						lowercase  :				List[Any]											=							{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}

						def __init__(				self , __UpperCamelCase=12_81_12 , __UpperCamelCase=10_24 , __UpperCamelCase=12 , __UpperCamelCase=40_96 , __UpperCamelCase=16 , __UpperCamelCase=12 , __UpperCamelCase=40_96 , __UpperCamelCase=16 , __UpperCamelCase=0.05 , __UpperCamelCase=0.05 , __UpperCamelCase=True , __UpperCamelCase=True , __UpperCamelCase="relu" , __UpperCamelCase=10_24 , __UpperCamelCase=0.1 , __UpperCamelCase=0.1 , __UpperCamelCase=0.0 , __UpperCamelCase=0.02 , __UpperCamelCase=2 , __UpperCamelCase=True , __UpperCamelCase=1 , __UpperCamelCase=0 , __UpperCamelCase=2 , **__UpperCamelCase , )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      vocab_size
									__UpperCamelCase    :    Dict								=      max_position_embeddings
									__UpperCamelCase    :    Dict								=      d_model
									__UpperCamelCase    :    Union[str, Any]								=      encoder_ffn_dim
									__UpperCamelCase    :    Dict								=      encoder_layers
									__UpperCamelCase    :    List[Any]								=      encoder_attention_heads
									__UpperCamelCase    :    Tuple								=      decoder_ffn_dim
									__UpperCamelCase    :    List[Any]								=      decoder_layers
									__UpperCamelCase    :    Optional[int]								=      decoder_attention_heads
									__UpperCamelCase    :    Any								=      dropout
									__UpperCamelCase    :    Optional[int]								=      attention_dropout
									__UpperCamelCase    :    Any								=      activation_dropout
									__UpperCamelCase    :    int								=      activation_function
									__UpperCamelCase    :    str								=      init_std
									__UpperCamelCase    :    Optional[int]								=      encoder_layerdrop
									__UpperCamelCase    :    Any								=      decoder_layerdrop
									__UpperCamelCase    :    Dict								=      use_cache
									__UpperCamelCase    :    str								=      encoder_layers
									__UpperCamelCase    :    Optional[Any]								=      scale_embedding  # scale factor will be sqrt(d_model) if True

									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 		SCREAMING_SNAKE_CASE__					(		UpperCAmelCase_   ):







						"""simple docstring"""




						@property
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      OrderedDict(
									    [
									        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
									        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
									    ]    )

									if self.use_past:
												__UpperCamelCase    :    Tuple								=      {0: "batch"}
												__UpperCamelCase    :    List[str]								=      {0: "batch", 1: "past_decoder_sequence + sequence"}
									else:
												__UpperCamelCase    :    List[str]								=      {0: "batch", 1: "decoder_sequence"}
												__UpperCamelCase    :    str								=      {0: "batch", 1: "decoder_sequence"}

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

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase = -1 , __UpperCamelCase = -1 , __UpperCamelCase = False , __UpperCamelCase = None , )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      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
									__UpperCamelCase    :    str								=      tokenizer.num_special_tokens_to_add(__UpperCamelCase    )
									__UpperCamelCase    :    Dict								=      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
									__UpperCamelCase    :    Dict								=      [" ".join([tokenizer.unk_token]    ) * seq_length] * batch_size
									__UpperCamelCase    :    Tuple								=      dict(tokenizer(__UpperCamelCase , return_tensors=__UpperCamelCase    )    )
									return common_inputs

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase = -1 , __UpperCamelCase = -1 , __UpperCamelCase = False , __UpperCamelCase = None , )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase    )

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

												__UpperCamelCase    :    Any								=      torch.cat(
												    [common_inputs["decoder_attention_mask"], torch.ones(__UpperCamelCase , __UpperCamelCase    )] , dim=1    )

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




						lowercase  :				Optional[Any]											=							_generate_dummy_inputs_for_default_and_seqaseq_lm


import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowercase     :       Dict        =       "\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n"
class 		SCREAMING_SNAKE_CASE__					(		unittest.TestCase						,	lowerCamelCase__   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      load_tool("summarization"    )
									self.tool.setup()
									__UpperCamelCase    :    str								=      load_tool("summarization" , remote=__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      self.tool(__UpperCamelCase    )
									self.assertEqual(
									    __UpperCamelCase , "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM." , )

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      self.remote_tool(__UpperCamelCase    )
									self.assertEqual(
									    __UpperCamelCase , "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM." , )

						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      self.tool(text=__UpperCamelCase    )
									self.assertEqual(
									    __UpperCamelCase , "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM." , )




						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      self.remote_tool(text=__UpperCamelCase    )
									self.assertEqual(
									    __UpperCamelCase , "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM." , )