



'''simple docstring'''







import dataclasses
import enum
import functools
import math
import re

# The following script is adapted from the script of TaPas.
# Original: https://github.com/google-research/tapas/master/wikisql_utils.py
from typing import Any, List, Text


SCREAMING_SNAKE_CASE__     : Optional[Any]				=   """none"""
SCREAMING_SNAKE_CASE__     : Optional[int]				=   """none"""







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		SCREAMING_SNAKE_CASE_						:Optional[int]										=      value.split(SCREAMING_SNAKE_CASE     )
		return len(SCREAMING_SNAKE_CASE     ) > 1 and any((len(SCREAMING_SNAKE_CASE     ) == 3 for x in split)     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE     ):
		if isinstance(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
				return value
		if isinstance(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
				return float(SCREAMING_SNAKE_CASE     )
		if not isinstance(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
				raise ValueError('Argument value is not a string. Can\'t parse it as float'     )
		SCREAMING_SNAKE_CASE_						:Tuple										=      value

		try:
				# Example: 1,000.7
				if "." in sanitized and "," in sanitized:
						return float(sanitized.replace(',' ,		''     )     )
				# 1,000
				if "," in sanitized and _split_thousands(',' ,		SCREAMING_SNAKE_CASE     ):
						return float(sanitized.replace(',' ,		''     )     )
				# 5,5556
				if "," in sanitized and sanitized.count(','     ) == 1 and not _split_thousands(',' ,		SCREAMING_SNAKE_CASE     ):
						return float(sanitized.replace(',' ,		'.'     )     )
				# 0.0.0.1
				if sanitized.count('.'     ) > 1:
						return float(sanitized.replace('.' ,		''     )     )
				# 0,0,0,1
				if sanitized.count(','     ) > 1:
						return float(sanitized.replace(',' ,		''     )     )
				return float(SCREAMING_SNAKE_CASE     )
		except ValueError:
				# Avoid adding the sanitized value in the error message.
				raise ValueError('Unable to convert value to float'     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE     ):
		if answer is None:
				return None
		try:
				SCREAMING_SNAKE_CASE_						:List[str]										=      convert_to_float(SCREAMING_SNAKE_CASE     )
				if isinstance(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ) and math.isnan(SCREAMING_SNAKE_CASE     ):
						return None
				return value
		except ValueError:
				return answer.lower()


SCREAMING_SNAKE_CASE__     : Dict				=   {
    """text""": lambda x: x,
    """real""": convert_to_float,
}




class 				__lowerCAmelCase(							enum.Enum      ):
			__snake_case  :		int		=      0
			__snake_case  :		Optional[Any]		=      1
			__snake_case  :		Tuple		=      2
			__snake_case  :		Optional[Any]		=      3
			__snake_case  :		Dict		=      4
			__snake_case  :		int		=      5




class 				__lowerCAmelCase(							enum.Enum      ):
			__snake_case  :		int		=      0
			__snake_case  :		Dict		=      1
			__snake_case  :		Optional[int]		=      2




@dataclasses.dataclass
class 				__lowerCAmelCase:
			__snake_case  :		Text
			__snake_case  :		_Operator
			__snake_case  :		Any


SCREAMING_SNAKE_CASE__     : Dict				=   re.compile(r"""\w+|[^\w\s]+""", re.UNICODE | re.MULTILINE | re.DOTALL)







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE     ):
		return list(_TOKENIZER.findall(x.lower()     )     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		if operator == _Operator.EQUALS:
				return src == tgt
		elif operator == _Operator.GREATER:
				return src > tgt
		elif operator == _Operator.LESSER:
				return src < tgt
		raise ValueError(F'Unknown operator: {operator}'     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		SCREAMING_SNAKE_CASE_						:str										=      table['types']
		return _TYPE_CONVERTER[types[column]](SCREAMING_SNAKE_CASE     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE     ):
		return isinstance(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		for cond in conditions:
				SCREAMING_SNAKE_CASE_						:Dict										=      row[cond.column]

				SCREAMING_SNAKE_CASE_						:List[str]										=      _parse_value(SCREAMING_SNAKE_CASE ,		cond.column ,		cond.cmp_value     )

				if _is_string(SCREAMING_SNAKE_CASE     ) and _is_string(SCREAMING_SNAKE_CASE     ):
						SCREAMING_SNAKE_CASE_						:List[str]										=      _normalize_for_match(SCREAMING_SNAKE_CASE     )
						SCREAMING_SNAKE_CASE_						:Tuple										=      _normalize_for_match(SCREAMING_SNAKE_CASE     )

				if not isinstance(SCREAMING_SNAKE_CASE ,		type(SCREAMING_SNAKE_CASE     )     ):
						raise ValueError('Type difference {} != {}'.format(type(SCREAMING_SNAKE_CASE     ) ,		type(SCREAMING_SNAKE_CASE     )     )     )

				if not _compare(cond.operator ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
						return False
		return True







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		if not answer_coordinates:
				if aggregation_op == _Aggregation.COUNT:
						return 0.0
				else:
						return EMPTY_ANSWER_AGG

    # Count can support non numeric answers.
		if aggregation_op == _Aggregation.COUNT:
				return float(len(SCREAMING_SNAKE_CASE     )     )

		# If we have just one answer, if float returns it or try a conversion.
		SCREAMING_SNAKE_CASE_						:Dict										=      [table['rows'][i][j] for (i, j) in answer_coordinates]
		if len(SCREAMING_SNAKE_CASE     ) == 1:
				try:
						return convert_to_float(values[0]     )
				except ValueError as e:
						if aggregation_op != _Aggregation.NONE:
								raise e

		if aggregation_op == _Aggregation.NONE:
				return None

		# Other aggregation only support numeric values. Bail out if we have strings.
		if not all((isinstance(SCREAMING_SNAKE_CASE ,		(int, float)     ) for v in values)     ):
				return None

		if aggregation_op == _Aggregation.SUM:
				return float(sum(SCREAMING_SNAKE_CASE     )     )
		elif aggregation_op == _Aggregation.AVERAGE:
				return sum(SCREAMING_SNAKE_CASE     ) / len(SCREAMING_SNAKE_CASE     )
		else:
				raise ValueError(F'Unknown aggregation: {aggregation_op}'     )







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		SCREAMING_SNAKE_CASE_						:List[Any]										=      sql_query['agg']
		if aggregation_op_index >= 3:
				SCREAMING_SNAKE_CASE_						:Any										=      _Aggregation(SCREAMING_SNAKE_CASE     )
		else:
				SCREAMING_SNAKE_CASE_						:Any										=      _Aggregation.NONE

		SCREAMING_SNAKE_CASE_						:List[Any]										=      sql_query['sel']
		SCREAMING_SNAKE_CASE_						:Tuple										=      [
		    _Condition(SCREAMING_SNAKE_CASE ,		_Operator(SCREAMING_SNAKE_CASE     ) ,		SCREAMING_SNAKE_CASE     )
		    for column, operator, cmp_value in zip(
		        sql_query['conds']['column_index'] ,		sql_query['conds']['operator_index'] ,		sql_query['conds']['condition']     )
		]

		SCREAMING_SNAKE_CASE_						:Dict										=      []
		for row in range(len(table['rows']     )     ):
				if _respect_conditions(SCREAMING_SNAKE_CASE ,		table['rows'][row] ,		SCREAMING_SNAKE_CASE     ):
						indices.append((row, target_column)     )

		if not indices:
				return [], aggregation_op

		if len(SCREAMING_SNAKE_CASE     ) == 1:
				return indices, aggregation_op

		# Parsing of MIN/MAX.
		if aggregation_op_index in (1, 2):
				SCREAMING_SNAKE_CASE_						:Any										=      {2: min, 1: max}
				SCREAMING_SNAKE_CASE_						:List[str]										=      [(table['rows'][i][j], index) for index, (i, j) in enumerate(SCREAMING_SNAKE_CASE     )]
				SCREAMING_SNAKE_CASE_						:Dict										=      functools.reduce(operators[sql_query['agg']] ,		SCREAMING_SNAKE_CASE     )

				SCREAMING_SNAKE_CASE_						:Dict										=      [indices[reduced[1]]]
				return ret, _Aggregation.NONE

		return indices, aggregation_op







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		if float_answer is not None:
				return [str(SCREAMING_SNAKE_CASE     )]
		return [str(table['real_rows'][r][c]     ) for r, c in answer_coordinates]







def  SCREAMING_SNAKE_CASE__ (				SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     ):
		SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:Optional[int]										=      _get_answer_coordinates(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     )
		SCREAMING_SNAKE_CASE_						:List[str]										=      _get_float_answer(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     )
		SCREAMING_SNAKE_CASE_						:List[Any]										=      _get_answer_text(SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE ,		SCREAMING_SNAKE_CASE     )
		# keep the original data the same with TaPas
		if len(SCREAMING_SNAKE_CASE     ) == 0:
				SCREAMING_SNAKE_CASE_						:List[Any]										=      [EMPTY_ANSWER]
		return answer_text




'''simple docstring'''




from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCAmelCase	:		List[str]		  =						logging.get_logger(__name__)

_lowerCAmelCase	:		int		  =						{
    'facebook/opt-125m': 'https://huggingface.co/facebook/opt-125m/blob/main/config.json',
    'facebook/opt-350m': 'https://huggingface.co/facebook/opt-350m/blob/main/config.json',
    'facebook/opt-1.3b': 'https://huggingface.co/facebook/opt-1.3b/blob/main/config.json',
    'facebook/opt-2.7b': 'https://huggingface.co/facebook/opt-2.7b/blob/main/config.json',
    'facebook/opt-6.7b': 'https://huggingface.co/facebook/opt-6.7b/blob/main/config.json',
    'facebook/opt-13b': 'https://huggingface.co/facebook/opt-13b/blob/main/config.json',
}



class 			lowerCAmelCase					(					a				):
	_lowerCamelCase :       Dict         =			"""opt"""
	_lowerCamelCase :       Optional[Any]         =			["""past_key_values"""]



	def __init__(       self			,       snake_case__=5_0272			,       snake_case__=768			,       snake_case__=12			,       snake_case__=3072			,       snake_case__=2048			,       snake_case__=True			,       snake_case__=False			,       snake_case__=None			,       snake_case__=0.1			,       snake_case__=0.0			,       snake_case__=12			,       snake_case__="relu"			,       snake_case__=0.0			,       snake_case__=0.0_2			,       snake_case__=True			,       snake_case__=1			,       snake_case__=2			,       snake_case__=2			,       snake_case__=True			,       snake_case__=True			,       **snake_case__			,       ):
		super().__init__(
		    pad_token_id=snake_case__			,       bos_token_id=snake_case__			,       eos_token_id=snake_case__			,       **snake_case__			,       )
		lowerCAmelCase       :     Union[str, Any]   				=			vocab_size
		lowerCAmelCase       :     List[Any]   				=			max_position_embeddings
		lowerCAmelCase       :     List[str]   				=			num_attention_heads
		lowerCAmelCase       :     Dict   				=			word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
		lowerCAmelCase       :     Optional[Any]   				=			ffn_dim
		lowerCAmelCase       :     Optional[int]   				=			hidden_size
		lowerCAmelCase       :     List[str]   				=			num_hidden_layers
		lowerCAmelCase       :     Union[str, Any]   				=			dropout
		lowerCAmelCase       :     List[str]   				=			attention_dropout
		lowerCAmelCase       :     Union[str, Any]   				=			activation_function
		lowerCAmelCase       :     Optional[Any]   				=			init_std
		lowerCAmelCase       :     List[str]   				=			layerdrop
		lowerCAmelCase       :     Dict   				=			use_cache
		lowerCAmelCase       :     List[Any]   				=			do_layer_norm_before
		# We keep these variables at `True` for backward compatibility.
		lowerCAmelCase       :     List[str]   				=			enable_bias
		lowerCAmelCase       :     Dict   				=			layer_norm_elementwise_affine

		# Note that the only purpose of `_remove_final_layer_norm` is to keep backward compatibility
		# with checkpoints that have been fine-tuned before transformers v4.20.1
		# see https://github.com/facebookresearch/metaseq/pull/164
		lowerCAmelCase       :     Tuple   				=			_remove_final_layer_norm
