



import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


class    _lowercase (TensorFormatter[Mapping, np.ndarray, Mapping]   ):
				'''simple docstring'''







				def __init__(			self  ,			snake_case__=None  ,			**snake_case__     ):

									'''simple docstring'''


									super().__init__(features=snake_case__     )
									UpperCamelCase_			= np_array_kwargs

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									if isinstance(snake_case__  ,			snake_case__     ):
														if column and all(
														    isinstance(snake_case__  ,			np.ndarray     ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column     ):
																			return np.stack(snake_case__     )
														else:
																			# don't use np.array(column, dtype=object)
																			# since it fails in certain cases
																			# see https://stackoverflow.com/q/51005699
																			UpperCamelCase_			= np.empty(len(snake_case__     )  ,			dtype=snake_case__     )
																			UpperCamelCase_			= column
																			return out
									return column

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									if isinstance(snake_case__  ,			(str, bytes, type(snake_case__     ))     ):
														return value
									elif isinstance(snake_case__  ,			(np.character, np.ndarray)     ) and np.issubdtype(value.dtype  ,			np.character     ):
														return value
									elif isinstance(snake_case__  ,			np.number     ):
														return value

									UpperCamelCase_			= {}

									if isinstance(snake_case__  ,			np.ndarray     ) and np.issubdtype(value.dtype  ,			np.integer     ):
														UpperCamelCase_			= {"dtype": np.intaa}
									elif isinstance(snake_case__  ,			np.ndarray     ) and np.issubdtype(value.dtype  ,			np.floating     ):
														UpperCamelCase_			= {"dtype": np.floataa}
									elif config.PIL_AVAILABLE and "PIL" in sys.modules:
														import PIL.Image

														if isinstance(snake_case__  ,			PIL.Image.Image     ):
																			return np.asarray(snake_case__  ,			**self.np_array_kwargs     )

									return np.asarray(snake_case__  ,			**{**default_dtype, **self.np_array_kwargs}     )

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									if config.TORCH_AVAILABLE and "torch" in sys.modules:
														import torch

														if isinstance(snake_case__  ,			torch.Tensor     ):
																			return self._tensorize(data_struct.detach().cpu().numpy()[()]     )
									if hasattr(snake_case__  ,			"__array__"     ) and not isinstance(snake_case__  ,			(np.ndarray, np.character, np.number)     ):
														UpperCamelCase_			= data_struct.__array__()
									# support for nested types like struct of list of struct
									if isinstance(snake_case__  ,			np.ndarray     ):
														if data_struct.dtype == object:
																			return self._consolidate([self.recursive_tensorize(snake_case__     ) for substruct in data_struct]     )
									if isinstance(snake_case__  ,			(list, tuple)     ):
														return self._consolidate([self.recursive_tensorize(snake_case__     ) for substruct in data_struct]     )
									return self._tensorize(snake_case__     )

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									return map_nested(self._recursive_tensorize  ,			snake_case__  ,			map_list=snake_case__     )

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									UpperCamelCase_			= self.numpy_arrow_extractor().extract_row(snake_case__     )
									UpperCamelCase_			= self.python_features_decoder.decode_row(snake_case__     )
									return self.recursive_tensorize(snake_case__     )

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									UpperCamelCase_			= self.numpy_arrow_extractor().extract_column(snake_case__     )
									UpperCamelCase_			= self.python_features_decoder.decode_column(snake_case__  ,			pa_table.column_names[0]     )
									UpperCamelCase_			= self.recursive_tensorize(snake_case__     )
									UpperCamelCase_			= self._consolidate(snake_case__     )
									return column

				def    _lowerCamelCase       (			self  ,			snake_case__     ):

									'''simple docstring'''


									UpperCamelCase_			= self.numpy_arrow_extractor().extract_batch(snake_case__     )
									UpperCamelCase_			= self.python_features_decoder.decode_batch(snake_case__     )
									UpperCamelCase_			= self.recursive_tensorize(snake_case__     )
									for column_name in batch:
														UpperCamelCase_			= self._consolidate(batch[column_name]     )
									return batch




'''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
