
'''simple docstring'''



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 				_a			(TensorFormatter[Mapping, np.ndarray, Mapping]):





       """simple docstring"""




       def __init__(							self    ,							A__=None    ,							**A__ )      ->     int:
          super().__init__(features=A__ )
          _SCREAMING_SNAKE_CASE       	=			np_array_kwargs






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






       def     UpperCamelCase			(							self    ,							A__ )      ->     Union[str, Any]:
          if isinstance(A__    ,							(str, bytes, type(A__ )) ):
             return value
          elif isinstance(A__    ,							(np.character, np.ndarray) ) and np.issubdtype(value.dtype    ,							np.character ):
             return value
          elif isinstance(A__    ,							np.number ):
             return value

          _SCREAMING_SNAKE_CASE       	=			{}

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

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

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






       def     UpperCamelCase			(							self    ,							A__ )      ->     str:
          # support for torch, tf, jax etc.
          if config.TORCH_AVAILABLE and "torch" in sys.modules:
             import torch

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






       def     UpperCamelCase			(							self    ,							A__ )      ->     List[str]:
          return map_nested(self._recursive_tensorize    ,							A__    ,							map_list=A__ )






       def     UpperCamelCase			(							self    ,							A__ )      ->     Mapping:
          _SCREAMING_SNAKE_CASE       	=			self.numpy_arrow_extractor().extract_row(A__ )
          _SCREAMING_SNAKE_CASE       	=			self.python_features_decoder.decode_row(A__ )
          return self.recursive_tensorize(A__ )






       def     UpperCamelCase			(							self    ,							A__ )      ->     np.ndarray:
          _SCREAMING_SNAKE_CASE       	=			self.numpy_arrow_extractor().extract_column(A__ )
          _SCREAMING_SNAKE_CASE       	=			self.python_features_decoder.decode_column(A__    ,							pa_table.column_names[0] )
          _SCREAMING_SNAKE_CASE       	=			self.recursive_tensorize(A__ )
          _SCREAMING_SNAKE_CASE       	=			self._consolidate(A__ )
          return column






       def     UpperCamelCase			(							self    ,							A__ )      ->     Mapping:
          _SCREAMING_SNAKE_CASE       	=			self.numpy_arrow_extractor().extract_batch(A__ )
          _SCREAMING_SNAKE_CASE       	=			self.python_features_decoder.decode_batch(A__ )
          _SCREAMING_SNAKE_CASE       	=			self.recursive_tensorize(A__ )
          for column_name in batch:
             _SCREAMING_SNAKE_CASE       	=			self._consolidate(batch[column_name] )
          return batch








'''simple docstring'''



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


UpperCamelCase__ :						int    							=					logging.get_logger(__name__)

UpperCamelCase__ :						Any    							=					{
    "openbmb/cpm-ant-10b": "https://huggingface.co/openbmb/cpm-ant-10b/blob/main/config.json"
    # See all CPMAnt models at https://huggingface.co/models?filter=cpmant
}

class 				_a			(_lowerCamelCase):





       """simple docstring"""




       SCREAMING_SNAKE_CASE =					'cpmant'






       def __init__(							self    ,							A__ = 3_07_20    ,							A__ = 40_96    ,							A__ = 32    ,							A__ = 1_28    ,							A__ = 1_02_40    ,							A__ = 48    ,							A__ = 0.0    ,							A__ = 5_12    ,							A__ = 20_48    ,							A__ = 1E-6    ,							A__ = 1.0    ,							A__ = 32    ,							A__ = 32    ,							A__ = 32    ,							A__ = True    ,							**A__    ,							)      ->     List[Any]:
          super().__init__(**A__ )
          _SCREAMING_SNAKE_CASE       	=			prompt_types
          _SCREAMING_SNAKE_CASE       	=			prompt_length
          _SCREAMING_SNAKE_CASE       	=			segment_types
          _SCREAMING_SNAKE_CASE       	=			hidden_size
          _SCREAMING_SNAKE_CASE       	=			num_attention_heads
          _SCREAMING_SNAKE_CASE       	=			dim_head
          _SCREAMING_SNAKE_CASE       	=			dim_ff
          _SCREAMING_SNAKE_CASE       	=			num_hidden_layers
          _SCREAMING_SNAKE_CASE       	=			position_bias_num_buckets
          _SCREAMING_SNAKE_CASE       	=			position_bias_max_distance
          _SCREAMING_SNAKE_CASE       	=			dropout_p
          _SCREAMING_SNAKE_CASE       	=			eps
          _SCREAMING_SNAKE_CASE       	=			use_cache
          _SCREAMING_SNAKE_CASE       	=			vocab_size
          _SCREAMING_SNAKE_CASE       	=			init_std






