





# 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 tensorflow as tf




class 					UpperCamelCase_    (       TensorFormatter[Mapping, "tf.Tensor", Mapping]      ):


							def __init__(							self      :Any							,			__A      :str=None							,			**__A      :List[str]						)				->				str:



									"""simple docstring"""



									super().__init__(features=__A						)
									SCREAMING_SNAKE_CASE__								= tf_tensor_kwargs
									import tensorflow as tf  # noqa: import tf at initialization


							def        _snake_case					(							self      :Any							,			__A      :Optional[Any]						)				->				List[Any]:



									"""simple docstring"""



									import tensorflow as tf

									if isinstance(__A							,			__A						) and column:
											if all(
											    isinstance(__A							,			tf.Tensor						) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column						):
													return tf.stack(__A						)
											elif all(
											    isinstance(__A							,			(tf.Tensor, tf.RaggedTensor)						) and x.ndim == 1 and x.dtype == column[0].dtype
											    for x in column						):
													# only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
													return tf.ragged.stack(__A						)

									return column


							def        _snake_case					(							self      :str							,			__A      :List[str]						)				->				Dict:



									"""simple docstring"""



									import tensorflow as tf

									if value is None:
											return value

									SCREAMING_SNAKE_CASE__								= {}

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

											if isinstance(__A							,			PIL.Image.Image						):
													SCREAMING_SNAKE_CASE__								= np.asarray(__A						)

									return tf.convert_to_tensor(__A							,			**{**default_dtype, **self.tf_tensor_kwargs}						)


							def        _snake_case					(							self      :List[str]							,			__A      :Tuple						)				->				List[str]:



									"""simple docstring"""



									import tensorflow as tf

									# 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							,			tf.Tensor						):
											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:  # tf 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        _snake_case					(							self      :List[str]							,			__A      :dict						)				->				Tuple:



									"""simple docstring"""



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


							def        _snake_case					(							self      :str							,			__A      :pa.Table						)				->				Mapping:



									"""simple docstring"""



									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        _snake_case					(							self      :List[str]							,			__A      :pa.Table						)				->				"tf.Tensor":



									"""simple docstring"""



									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        _snake_case					(							self      :Dict							,			__A      :pa.Table						)				->				Mapping:



									"""simple docstring"""



									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






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


_lowerCamelCase							=     logging.get_logger(__name__)

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




class 					UpperCamelCase_    (       UpperCamelCase__      ):
							lowerCamelCase_          =   "videomae"


							def __init__(							self      :Dict							,			__A      :List[str]=224							,			__A      :List[Any]=16							,			__A      :int=3							,			__A      :Optional[Any]=16							,			__A      :Optional[int]=2							,			__A      :Optional[Any]=768							,			__A      :List[str]=12							,			__A      :Optional[Any]=12							,			__A      :List[str]=3072							,			__A      :Tuple="gelu"							,			__A      :Optional[int]=0.0							,			__A      :Union[str, Any]=0.0							,			__A      :int=0.0_2							,			__A      :Union[str, Any]=1E-12							,			__A      :Optional[Any]=True							,			__A      :Union[str, Any]=True							,			__A      :Optional[int]=6							,			__A      :Tuple=384							,			__A      :str=4							,			__A      :List[str]=1536							,			__A      :Dict=True							,			**__A      :int							,			)				->				Optional[int]:



									"""simple docstring"""



									super().__init__(**__A						)

									SCREAMING_SNAKE_CASE__								= image_size
									SCREAMING_SNAKE_CASE__								= patch_size
									SCREAMING_SNAKE_CASE__								= num_channels
									SCREAMING_SNAKE_CASE__								= num_frames
									SCREAMING_SNAKE_CASE__								= tubelet_size

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

									SCREAMING_SNAKE_CASE__								= decoder_num_attention_heads
									SCREAMING_SNAKE_CASE__								= decoder_hidden_size
									SCREAMING_SNAKE_CASE__								= decoder_num_hidden_layers
									SCREAMING_SNAKE_CASE__								= decoder_intermediate_size
									SCREAMING_SNAKE_CASE__								= norm_pix_loss