
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]						):






			def __init__(			self							, __UpperCamelCase=None							, **__UpperCamelCase     ):
									super().__init__(features=__UpperCamelCase     )
									_lowercase									=				np_array_kwargs






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






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

									_lowercase									=				{}

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

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

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






			def       UpperCamelCase_							(			self							, __UpperCamelCase     ):
									# support for torch, tf, jax etc.
									if config.TORCH_AVAILABLE and "torch" in sys.modules:
															import torch

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






			def       UpperCamelCase_							(			self							, __UpperCamelCase     ):
									return map_nested(self._recursive_tensorize							, __UpperCamelCase							, map_list=__UpperCamelCase     )






			def       UpperCamelCase_							(			self							, __UpperCamelCase     ):
									_lowercase									=				self.numpy_arrow_extractor().extract_row(__UpperCamelCase     )
									_lowercase									=				self.python_features_decoder.decode_row(__UpperCamelCase     )
									return self.recursive_tensorize(__UpperCamelCase     )






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






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

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


A		:   List[Any]         =    logging.get_logger(__name__)

A		:   str         =    {
    '''MCG-NJU/videomae-base''': '''https://huggingface.co/MCG-NJU/videomae-base/resolve/main/config.json''',
}



class       a_   ( _a						):
			a  : str				      =       '''videomae'''






			def __init__(			self							, __UpperCamelCase=224							, __UpperCamelCase=16							, __UpperCamelCase=3							, __UpperCamelCase=16							, __UpperCamelCase=2							, __UpperCamelCase=768							, __UpperCamelCase=12							, __UpperCamelCase=12							, __UpperCamelCase=3_072							, __UpperCamelCase="gelu"							, __UpperCamelCase=0.0							, __UpperCamelCase=0.0							, __UpperCamelCase=0.02							, __UpperCamelCase=1E-12							, __UpperCamelCase=True							, __UpperCamelCase=True							, __UpperCamelCase=6							, __UpperCamelCase=384							, __UpperCamelCase=4							, __UpperCamelCase=1_536							, __UpperCamelCase=True							, **__UpperCamelCase							, ):
									super().__init__(**__UpperCamelCase     )

									_lowercase									=				image_size
									_lowercase									=				patch_size
									_lowercase									=				num_channels
									_lowercase									=				num_frames
									_lowercase									=				tubelet_size

									_lowercase									=				hidden_size
									_lowercase									=				num_hidden_layers
									_lowercase									=				num_attention_heads
									_lowercase									=				intermediate_size
									_lowercase									=				hidden_act
									_lowercase									=				hidden_dropout_prob
									_lowercase									=				attention_probs_dropout_prob
									_lowercase									=				initializer_range
									_lowercase									=				layer_norm_eps
									_lowercase									=				qkv_bias
									_lowercase									=				use_mean_pooling

									_lowercase									=				decoder_num_attention_heads
									_lowercase									=				decoder_hidden_size
									_lowercase									=				decoder_num_hidden_layers
									_lowercase									=				decoder_intermediate_size
									_lowercase									=				norm_pix_loss