



"""simple docstring"""


import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


if TYPE_CHECKING:
						from ... import PreTrainedTokenizerBase, TensorType

__A   :							Any										=   logging.get_logger(__name__)
class 			_a (					lowerCAmelCase):
			"""simple docstring"""
			UpperCamelCase__			      =	"""vision-encoder-decoder"""
			UpperCamelCase__			      =	True



			def __init__(		self     :    Union[str, Any]				,   **__UpperCamelCase     :    Optional[int]   )->Tuple:
							super().__init__(**__UpperCamelCase   )
							if "encoder" not in kwargs or "decoder" not in kwargs:
											raise ValueError(
											    F'A configuraton of type {self.model_type} cannot be instantiated because '
											    F'not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}'   )

							_UpperCAmelCase					=    kwargs.pop('''encoder'''   )
							_UpperCAmelCase					=    encoder_config.pop('''model_type'''   )
							_UpperCAmelCase					=    kwargs.pop('''decoder'''   )
							_UpperCAmelCase					=    decoder_config.pop('''model_type'''   )

							_UpperCAmelCase					=    AutoConfig.for_model(__UpperCamelCase				,   **__UpperCamelCase   )
							_UpperCAmelCase					=    AutoConfig.for_model(__UpperCamelCase				,   **__UpperCamelCase   )
							_UpperCAmelCase					=    True



			@classmethod
			def  lowercase__						(		cls     :    int				,   __UpperCamelCase     :    PretrainedConfig				,   __UpperCamelCase     :    PretrainedConfig				,   **__UpperCamelCase     :    List[Any]   )->PretrainedConfig:
							logger.info('''Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config'''   )
							_UpperCAmelCase					=    True
							_UpperCAmelCase					=    True

							return cls(encoder=encoder_config.to_dict()				,   decoder=decoder_config.to_dict()				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    Dict   )->int:
							_UpperCAmelCase					=    copy.deepcopy(self.__dict__   )
							_UpperCAmelCase					=    self.encoder.to_dict()
							_UpperCAmelCase					=    self.decoder.to_dict()
							_UpperCAmelCase					=    self.__class__.model_type
							return output



class 			_a (					lowerCAmelCase):
			"""simple docstring"""
			UpperCamelCase__			      =	version.parse("""1.11""")



			@property
			def  lowercase__						(		self     :    Optional[int]   )->Mapping[str, Mapping[int, str]]:
							return OrderedDict(
							    [
							        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
							    ]   )



			@property
			def  lowercase__						(		self     :    List[Any]   )->float:
							return 1e-4



			@property
			def  lowercase__						(		self     :    List[str]   )->Mapping[str, Mapping[int, str]]:
							return OrderedDict({'''last_hidden_state''': {0: '''batch''', 1: '''encoder_sequence'''}}   )



class 			_a (					lowerCAmelCase):
			"""simple docstring"""



			@property
			def  lowercase__						(		self     :    List[str]   )->Mapping[str, Mapping[int, str]]:
							_UpperCAmelCase					=    OrderedDict()
							_UpperCAmelCase					=    {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
							_UpperCAmelCase					=    {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
							_UpperCAmelCase					=    {0: '''batch''', 1: '''encoder_sequence'''}

							return common_inputs



			def  lowercase__						(		self     :    List[str]				,   __UpperCamelCase     :    "PreTrainedTokenizerBase"				,   __UpperCamelCase     :    int = -1				,   __UpperCamelCase     :    int = -1				,   __UpperCamelCase     :    bool = False				,   __UpperCamelCase     :    Optional["TensorType"] = None				,   )->Mapping[str, Any]:
							import torch

							_UpperCAmelCase					=    OrderedDict()

							_UpperCAmelCase					=    super().generate_dummy_inputs(
							    __UpperCamelCase				,   batch_size=__UpperCamelCase				,   seq_length=__UpperCamelCase				,   is_pair=__UpperCamelCase				,   framework=__UpperCamelCase   )

							_UpperCAmelCase		,						_UpperCAmelCase					=    dummy_input['''input_ids'''].shape
							_UpperCAmelCase					=    (batch, encoder_sequence, self._config.encoder_hidden_size)
							_UpperCAmelCase					=    dummy_input.pop('''input_ids'''   )
							_UpperCAmelCase					=    dummy_input.pop('''attention_mask'''   )
							_UpperCAmelCase					=    torch.zeros(__UpperCamelCase   )

							return common_inputs



class 			_a (					lowerCAmelCase):
			"""simple docstring"""



			@property
			def  lowercase__						(		self     :    List[Any]   )->None:
							pass



			def  lowercase__						(		self     :    Any				,   __UpperCamelCase     :    PretrainedConfig   )->OnnxConfig:
							return VisionEncoderDecoderEncoderOnnxConfig(__UpperCamelCase   )



			def  lowercase__						(		self     :    Tuple				,   __UpperCamelCase     :    PretrainedConfig				,   __UpperCamelCase     :    PretrainedConfig				,   __UpperCamelCase     :    str = "default"   )->OnnxConfig:
							_UpperCAmelCase					=    encoder_config.hidden_size
							return VisionEncoderDecoderDecoderOnnxConfig(__UpperCamelCase				,   __UpperCamelCase   )








"""simple docstring"""


import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


__A   :							Any										=   "\\n@article{hendrycksmath2021,\n  title={Measuring Mathematical Problem Solving With the MATH Dataset},\n  author={Dan Hendrycks\n    and Collin Burns\n    and Saurav Kadavath\n    and Akul Arora\n    and Steven Basart\n    and Eric Tang\n    and Dawn Song\n    and Jacob Steinhardt},\n  journal={arXiv preprint arXiv:2103.03874},\n  year={2021}\n}\n"


__A   :							Optional[Any]										=   "\\nThis metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.\nIt first canonicalizes the inputs (e.g., converting \"1/2\" to \"\\frac{1}{2}\") and then computes accuracy.\n"


__A   :							Tuple										=   r"\nCalculates accuracy after canonicalizing inputs.\n\nArgs:\n    predictions: list of predictions to score. Each prediction\n        is a string that contains natural language and LaTex.\n    references: list of reference for each prediction. Each\n        reference is a string that contains natural language\n        and LaTex.\nReturns:\n    accuracy: accuracy after canonicalizing inputs\n        (e.g., converting \"1/2\" to \"\\frac{1}{2}\")\n\nExamples:\n    >>> metric = datasets.load_metric(\"competition_math\")\n    >>> results = metric.compute(references=[\"\\frac{1}{2}\"], predictions=[\"1/2\"])\n    >>> print(results)\n    {'accuracy': 1.0}\n"
@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION			,							_KWARGS_DESCRIPTION)
class 			_a (					datasets.Metric):
			"""simple docstring"""



			def  lowercase__						(		self     :    List[Any]   )->Dict:
							return datasets.MetricInfo(
							    description=_DESCRIPTION				,   citation=_CITATION				,   inputs_description=_KWARGS_DESCRIPTION				,   features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''string'''   ),
							            '''references''': datasets.Value('''string'''   ),
							        }   )				,   homepage='''https://github.com/hendrycks/math'''				,   codebase_urls=['''https://github.com/hendrycks/math''']				,   )



			def  lowercase__						(		self     :    int				,   __UpperCamelCase     :    List[str]				,   __UpperCamelCase     :    Union[str, Any]   )->Tuple:
							_UpperCAmelCase					=    0.0
							for i, j in zip(__UpperCamelCase				,   __UpperCamelCase   ):
											n_correct += 1.0 if math_equivalence.is_equiv(__UpperCamelCase				,   __UpperCamelCase   ) else 0.0
							_UpperCAmelCase					=    n_correct / len(__UpperCamelCase   )
							return {
							    "accuracy": accuracy,
							}



