





import os
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
	import torch

	from transformers import GPTaLMHeadModel




@require_torch
@require_sentencepiece
@require_tokenizers
class 					UpperCamelCase_    (       unittest.TestCase      ):


							@slow
							@unittest.skip("""Model is not available."""						)
							def        _snake_case					(							self      :Optional[Any]						)				->				Optional[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								= """nvidia/megatron-gpt2-345m/"""
									if "MYDIR" in os.environ:
											SCREAMING_SNAKE_CASE__								= os.path.join(os.environ["""MYDIR"""]							,			__A						)
									SCREAMING_SNAKE_CASE__								= GPTaLMHeadModel.from_pretrained(__A						)
									model.to(__A						)
									model.half()

									SCREAMING_SNAKE_CASE__								= torch.tensor(
									    [[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]							,			device=__A							,			dtype=torch.long							,			)

									with torch.no_grad():
											SCREAMING_SNAKE_CASE__								= model(__A						).logits

									SCREAMING_SNAKE_CASE__								= torch.Size((1, 9, 5_0257)						)
									self.assertEqual(output.shape							,			__A						)

									SCREAMING_SNAKE_CASE__								= torch.tensor(
									    [
									        4.9_4_1_4,
									        -0.2_9_2_0,
									        -1.2_1_4_8,
									        -4.0_2_7_3,
									        -0.5_1_6_1,
									        -5.2_1_0_9,
									        -1.2_4_1_2,
									        -1.8_3_0_1,
									        -1.7_7_3_4,
									        -4.7_1_4_8,
									        -0.2_3_1_7,
									        -1.0_8_1_1,
									        -2.1_7_7_7,
									        0.4_1_4_1,
									        -3.7_9_6_9,
									        -4.0_5_8_6,
									        -2.5_3_3_2,
									        -3.3_8_0_9,
									        4.3_8_6_7,
									    ]							,			device=__A							,			dtype=torch.half							,			)

									for i in range(19						):
											SCREAMING_SNAKE_CASE__		,  SCREAMING_SNAKE_CASE__								= 8 * i // 17, 2792 * i  # along the diagonal
											SCREAMING_SNAKE_CASE__		,  SCREAMING_SNAKE_CASE__								= output[0, r, c], expected_diag[i]
											SCREAMING_SNAKE_CASE__								= f'''row={r} col={c} computed={computed} expected={expected}'''
											self.assertAlmostEqual(__A							,			__A							,			delta=1E-4							,			msg=__A						)






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