

# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

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


if TYPE_CHECKING:
					import torch

class 				a  (	TensorFormatter[Mapping, "torch.Tensor", Mapping]				):


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







										'''simple docstring'''


										super().__init__(features=A_	)
										_UpperCAmelCase       :		Dict 		=    torch_tensor_kwargs
										import torch  # noqa import torch at initialization


						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										import torch

										if isinstance(A_						,					A_	) and column:
														if all(
														    isinstance(A_						,					torch.Tensor	) and x.shape == column[0].shape and x.dtype == column[0].dtype
														    for x in column	):
																		return torch.stack(A_	)
										return column


						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										import torch

										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.tolist()

										_UpperCAmelCase       :		Dict 		=    {}

										if isinstance(A_						,					(np.number, np.ndarray)	) and np.issubdtype(value.dtype						,					np.integer	):
														_UpperCAmelCase       :		List[Any] 		=    {"dtype": torch.intaa}
										elif isinstance(A_						,					(np.number, np.ndarray)	) and np.issubdtype(value.dtype						,					np.floating	):
														_UpperCAmelCase       :		int 		=    {"dtype": torch.floataa}
										elif config.PIL_AVAILABLE and "PIL" in sys.modules:
														import PIL.Image

														if isinstance(A_						,					PIL.Image.Image	):
																		_UpperCAmelCase       :		str 		=    np.asarray(A_	)
										return torch.tensor(A_						,					**{**default_dtype, **self.torch_tensor_kwargs}	)


						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										import torch

										# support for torch, tf, jax etc.
										if hasattr(A_						,					"__array__"	) and not isinstance(A_						,					torch.Tensor	):
														_UpperCAmelCase       :		Optional[int] 		=    data_struct.__array__()
										# support for nested types like struct of list of struct
										if isinstance(A_						,					np.ndarray	):
														if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
																		return self._consolidate([self.recursive_tensorize(A_	) for substruct in data_struct]	)
										elif isinstance(A_						,					(list, tuple)	):
														return self._consolidate([self.recursive_tensorize(A_	) for substruct in data_struct]	)
										return self._tensorize(A_	)


						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


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


						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										_UpperCAmelCase       :		List[str] 		=    self.numpy_arrow_extractor().extract_row(A_	)
										_UpperCAmelCase       :		Any 		=    self.python_features_decoder.decode_row(A_	)
										return self.recursive_tensorize(A_	)


						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    self.numpy_arrow_extractor().extract_column(A_	)
										_UpperCAmelCase       :		List[str] 		=    self.python_features_decoder.decode_column(A_						,					pa_table.column_names[0]	)
										_UpperCAmelCase       :		List[Any] 		=    self.recursive_tensorize(A_	)
										_UpperCAmelCase       :		int 		=    self._consolidate(A_	)
										return column





						def        _UpperCAmelCase				(       self						,					A_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[Any] 		=    self.numpy_arrow_extractor().extract_batch(A_	)
										_UpperCAmelCase       :		Tuple 		=    self.python_features_decoder.decode_batch(A_	)
										_UpperCAmelCase       :		Optional[int] 		=    self.recursive_tensorize(A_	)
										for column_name in batch:
														_UpperCAmelCase       :		List[str] 		=    self._consolidate(batch[column_name]	)
										return batch





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


SCREAMING_SNAKE_CASE_        =      logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_        =      {
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}

class 				a  (	UpperCAmelCase				):
						_lowercase    						=			"megatron-bert"


						def __init__(       self						,					A_=29056						,					A_=1024						,					A_=24						,					A_=16						,					A_=4096						,					A_="gelu"						,					A_=0.1						,					A_=0.1						,					A_=512						,					A_=2						,					A_=0.02						,					A_=1e-12						,					A_=0						,					A_="absolute"						,					A_=True						,					**A_						,					):







										'''simple docstring'''


										super().__init__(pad_token_id=A_						,					**A_	)

										_UpperCAmelCase       :		Optional[Any] 		=    vocab_size
										_UpperCAmelCase       :		List[str] 		=    hidden_size
										_UpperCAmelCase       :		List[str] 		=    num_hidden_layers
										_UpperCAmelCase       :		Optional[Any] 		=    num_attention_heads
										_UpperCAmelCase       :		Any 		=    hidden_act
										_UpperCAmelCase       :		Optional[Any] 		=    intermediate_size
										_UpperCAmelCase       :		int 		=    hidden_dropout_prob
										_UpperCAmelCase       :		Optional[Any] 		=    attention_probs_dropout_prob
										_UpperCAmelCase       :		Any 		=    max_position_embeddings
										_UpperCAmelCase       :		str 		=    type_vocab_size
										_UpperCAmelCase       :		Optional[int] 		=    initializer_range
										_UpperCAmelCase       :		Dict 		=    layer_norm_eps
										_UpperCAmelCase       :		Tuple 		=    position_embedding_type
										_UpperCAmelCase       :		Tuple 		=    use_cache


