





"""simple docstring"""
import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch
  from torch import nn

  from transformers import (
      MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
      VideoMAEForPreTraining,
      VideoMAEForVideoClassification,
      VideoMAEModel,
  )
  from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from transformers import VideoMAEImageProcessor






class 					_SCREAMING_SNAKE_CASE:




       def __init__(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=13		,SCREAMING_SNAKE_CASE__=10		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=5		,SCREAMING_SNAKE_CASE__=4		,SCREAMING_SNAKE_CASE__=37		,SCREAMING_SNAKE_CASE__="gelu"		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=10		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=0.9		,SCREAMING_SNAKE_CASE__=None		,)			->      Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  parent
             __SCREAMING_SNAKE_CASE   :Tuple						=  batch_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  image_size
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  num_channels
             __SCREAMING_SNAKE_CASE   :Dict						=  patch_size
             __SCREAMING_SNAKE_CASE   :Tuple						=  tubelet_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_frames
             __SCREAMING_SNAKE_CASE   :Any						=  is_training
             __SCREAMING_SNAKE_CASE   :str						=  use_labels
             __SCREAMING_SNAKE_CASE   :Dict						=  hidden_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_hidden_layers
             __SCREAMING_SNAKE_CASE   :Any						=  num_attention_heads
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  intermediate_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  hidden_act
             __SCREAMING_SNAKE_CASE   :List[Any]						=  hidden_dropout_prob
             __SCREAMING_SNAKE_CASE   :List[str]						=  attention_probs_dropout_prob
             __SCREAMING_SNAKE_CASE   :str						=  type_sequence_label_size
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  initializer_range
             __SCREAMING_SNAKE_CASE   :Any						=  mask_ratio
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  scope

             # in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
             __SCREAMING_SNAKE_CASE   :List[Any]						=  (image_size // patch_size) ** 2
             __SCREAMING_SNAKE_CASE   :List[str]						=  (num_frames // tubelet_size) * self.num_patches_per_frame

             # use this variable to define bool_masked_pos
             __SCREAMING_SNAKE_CASE   :Any						=  int(mask_ratio * self.seq_length							)




       def     _UpperCamelCase     (						self							)			->      Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  floats_tensor(
                 [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]							)

             __SCREAMING_SNAKE_CASE   :Tuple						=  None
             if self.use_labels:
                   __SCREAMING_SNAKE_CASE   :int						=  ids_tensor([self.batch_size]		,self.type_sequence_label_size							)

             __SCREAMING_SNAKE_CASE   :Any						=  self.get_config()

             return config, pixel_values, labels




       def     _UpperCamelCase     (						self							)			->      Optional[int]:





             """simple docstring"""






             return VideoMAEConfig(
                 image_size=self.image_size		,patch_size=self.patch_size		,num_channels=self.num_channels		,num_frames=self.num_frames		,tubelet_size=self.tubelet_size		,hidden_size=self.hidden_size		,num_hidden_layers=self.num_hidden_layers		,num_attention_heads=self.num_attention_heads		,intermediate_size=self.intermediate_size		,hidden_act=self.hidden_act		,hidden_dropout_prob=self.hidden_dropout_prob		,attention_probs_dropout_prob=self.attention_probs_dropout_prob		,is_decoder=SCREAMING_SNAKE_CASE__		,initializer_range=self.initializer_range		,)




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  VideoMAEModel(config=SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  model(SCREAMING_SNAKE_CASE__							)
             self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.hidden_size)							)




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)			->      List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  VideoMAEForPreTraining(SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()
             # important: each video needs to have the same number of masked patches
             # hence we define a single mask, which we then repeat for each example in the batch
             __SCREAMING_SNAKE_CASE   :Any						=  torch.ones((self.num_masks,)							)
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  torch.cat([mask, torch.zeros(self.seq_length - mask.size(0							)							)]							)
             __SCREAMING_SNAKE_CASE   :List[str]						=  mask.expand(self.batch_size		,-1							).bool()

             __SCREAMING_SNAKE_CASE   :Dict						=  model(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)
             # model only returns predictions for masked patches
             __SCREAMING_SNAKE_CASE   :List[str]						=  mask.sum().item()
             __SCREAMING_SNAKE_CASE   :List[Any]						=  3 * self.tubelet_size * self.patch_size**2
             self.parent.assertEqual(result.logits.shape		,(self.batch_size, num_masked_patches, decoder_num_labels)							)




       def     _UpperCamelCase     (						self							)			->      Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[int]						=  self.prepare_config_and_inputs()
             __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Optional[Any]						=  config_and_inputs
             __SCREAMING_SNAKE_CASE   :List[str]						=  {'''pixel_values''': pixel_values}
             return config, inputs_dict






@require_torch
class 					_SCREAMING_SNAKE_CASE(   A    ,	A    ,	unittest.TestCase  ):
       SCREAMING_SNAKE_CASE_   :      int							=  (
           (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
       )
       SCREAMING_SNAKE_CASE_   :      Optional[Any]							=  (
           {'''feature-extraction''': VideoMAEModel, '''video-classification''': VideoMAEForVideoClassification}
           if is_torch_available()
           else {}
       )

       SCREAMING_SNAKE_CASE_   :      Optional[Any]							=  False
       SCREAMING_SNAKE_CASE_   :      Any							=  False
       SCREAMING_SNAKE_CASE_   :      Tuple							=  False
       SCREAMING_SNAKE_CASE_   :      str							=  False




       def     _UpperCamelCase     (						self							)			->      Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  VideoMAEModelTester(self							)
             __SCREAMING_SNAKE_CASE   :Tuple						=  ConfigTester(self		,config_class=SCREAMING_SNAKE_CASE__		,has_text_modality=SCREAMING_SNAKE_CASE__		,hidden_size=37							)




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=False							)			->      Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Dict						=  copy.deepcopy(SCREAMING_SNAKE_CASE__							)

             if model_class == VideoMAEForPreTraining:
                   # important: each video needs to have the same number of masked patches
                   # hence we define a single mask, which we then repeat for each example in the batch
                   __SCREAMING_SNAKE_CASE   :int						=  torch.ones((self.model_tester.num_masks,)							)
                   __SCREAMING_SNAKE_CASE   :str						=  torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0							)							)]							)
                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  mask.expand(self.model_tester.batch_size		,-1							).bool()
                   __SCREAMING_SNAKE_CASE   :Any						=  bool_masked_pos.to(SCREAMING_SNAKE_CASE__							)

             if return_labels:
                   if model_class in [
                       *get_values(SCREAMING_SNAKE_CASE__							),
                   ]:
                         __SCREAMING_SNAKE_CASE   :List[str]						=  torch.zeros(
                             self.model_tester.batch_size		,dtype=torch.long		,device=SCREAMING_SNAKE_CASE__							)

             return inputs_dict




       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             self.config_tester.run_common_tests()




       @unittest.skip(reason='''VideoMAE does not use inputs_embeds'''							)
       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             pass




       def     _UpperCamelCase     (						self							)			->      Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :List[Any]						=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE   :Any						=  model_class(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(model.get_input_embeddings()		,(nn.Module)							)
                   __SCREAMING_SNAKE_CASE   :Any						=  model.get_output_embeddings()
                   self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE__		,nn.Linear							)							)




       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Optional[int]						=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  model_class(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  inspect.signature(model.forward							)
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  [*signature.parameters.keys()]

                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  ['''pixel_values''']
                   self.assertListEqual(arg_names[:1]		,SCREAMING_SNAKE_CASE__							)




       def     _UpperCamelCase     (						self							)			->      Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__							)




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE   :List[Any]						=  VideoMAEModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)




       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             if not self.has_attentions:
                   pass

             else:
                   __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :str						=  self.model_tester.prepare_config_and_inputs_for_common()
                   __SCREAMING_SNAKE_CASE   :int						=  True

                   for model_class in self.all_model_classes:
                         __SCREAMING_SNAKE_CASE   :Tuple						=  self.model_tester.seq_length - self.model_tester.num_masks
                         __SCREAMING_SNAKE_CASE   :Tuple						=  (
                             num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
                         )

                         __SCREAMING_SNAKE_CASE   :Any						=  True
                         __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  False
                         __SCREAMING_SNAKE_CASE   :str						=  True
                         __SCREAMING_SNAKE_CASE   :int						=  model_class(SCREAMING_SNAKE_CASE__							)
                         model.to(SCREAMING_SNAKE_CASE__							)
                         model.eval()
                         with torch.no_grad():
                               __SCREAMING_SNAKE_CASE   :List[str]						=  model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)
                         __SCREAMING_SNAKE_CASE   :List[str]						=  outputs.attentions
                         self.assertEqual(len(SCREAMING_SNAKE_CASE__							)		,self.model_tester.num_hidden_layers							)

                         # check that output_attentions also work using config
                         del inputs_dict["output_attentions"]
                         __SCREAMING_SNAKE_CASE   :Tuple						=  True
                         __SCREAMING_SNAKE_CASE   :str						=  model_class(SCREAMING_SNAKE_CASE__							)
                         model.to(SCREAMING_SNAKE_CASE__							)
                         model.eval()
                         with torch.no_grad():
                               __SCREAMING_SNAKE_CASE   :Optional[int]						=  model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)
                         __SCREAMING_SNAKE_CASE   :int						=  outputs.attentions
                         self.assertEqual(len(SCREAMING_SNAKE_CASE__							)		,self.model_tester.num_hidden_layers							)

                         self.assertListEqual(
                             list(attentions[0].shape[-3:]							)		,[self.model_tester.num_attention_heads, seq_len, seq_len]		,)
                         __SCREAMING_SNAKE_CASE   :Optional[Any]						=  len(SCREAMING_SNAKE_CASE__							)

                         # Check attention is always last and order is fine
                         __SCREAMING_SNAKE_CASE   :Dict						=  True
                         __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  True
                         __SCREAMING_SNAKE_CASE   :int						=  model_class(SCREAMING_SNAKE_CASE__							)
                         model.to(SCREAMING_SNAKE_CASE__							)
                         model.eval()
                         with torch.no_grad():
                               __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)

                         self.assertEqual(out_len + 1		,len(SCREAMING_SNAKE_CASE__							)							)

                         __SCREAMING_SNAKE_CASE   :List[Any]						=  outputs.attentions

                         self.assertEqual(len(SCREAMING_SNAKE_CASE__							)		,self.model_tester.num_hidden_layers							)
                         self.assertListEqual(
                             list(self_attentions[0].shape[-3:]							)		,[self.model_tester.num_attention_heads, seq_len, seq_len]		,)




       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             def check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							):
                   __SCREAMING_SNAKE_CASE   :Dict						=  model_class(SCREAMING_SNAKE_CASE__							)
                   model.to(SCREAMING_SNAKE_CASE__							)
                   model.eval()

                   with torch.no_grad():
                         __SCREAMING_SNAKE_CASE   :int						=  model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)

                   __SCREAMING_SNAKE_CASE   :Dict						=  outputs.hidden_states
                   __SCREAMING_SNAKE_CASE   :str						=  self.model_tester.num_hidden_layers + 1
                   self.assertEqual(len(SCREAMING_SNAKE_CASE__							)		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Tuple						=  self.model_tester.seq_length - self.model_tester.num_masks
                   __SCREAMING_SNAKE_CASE   :List[Any]						=  num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

                   self.assertListEqual(
                       list(hidden_states[0].shape[-2:]							)		,[seq_length, self.model_tester.hidden_size]		,)

             __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :int						=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  True
                   check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   # check that output_hidden_states also work using config
                   del inputs_dict["output_hidden_states"]
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  True

                   check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             pass




def      __lowerCamelCase   (							)			->      Any:
      __SCREAMING_SNAKE_CASE   :Optional[int]						=  hf_hub_download(
          repo_id='''hf-internal-testing/spaghetti-video''' ,   filename='''eating_spaghetti.npy''' ,   repo_type='''dataset'''							)
      __SCREAMING_SNAKE_CASE   :int						=  np.load(a_							)
      return list(a_							)







@require_torch
@require_vision
class 					_SCREAMING_SNAKE_CASE(   unittest.TestCase  ):




       @cached_property
       def     _UpperCamelCase     (						self							)			->      List[str]:





             """simple docstring"""






             return (
                 VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]		,image_std=[0.5, 0.5, 0.5]							)
                 if is_vision_available()
                 else None
             )




       @slow
       def     _UpperCamelCase     (						self							)			->      Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[str]						=  VideoMAEForVideoClassification.from_pretrained('''MCG-NJU/videomae-base-finetuned-kinetics'''							).to(
                 SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :List[str]						=  self.default_image_processor
             __SCREAMING_SNAKE_CASE   :Any						=  prepare_video()
             __SCREAMING_SNAKE_CASE   :str						=  image_processor(SCREAMING_SNAKE_CASE__		,return_tensors='''pt'''							).to(SCREAMING_SNAKE_CASE__							)

             # forward pass
             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE   :str						=  model(**SCREAMING_SNAKE_CASE__							)

             # verify the logits
             __SCREAMING_SNAKE_CASE   :List[Any]						=  torch.Size((1, 4_00)							)
             self.assertEqual(outputs.logits.shape		,SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :Any						=  torch.tensor([0.3_6_6_9, -0.0_6_8_8, -0.2_4_2_1]							).to(SCREAMING_SNAKE_CASE__							)

             self.assertTrue(torch.allclose(outputs.logits[0, :3]		,SCREAMING_SNAKE_CASE__		,atol=1E-4							)							)




       @slow
       def     _UpperCamelCase     (						self							)			->      List[str]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''							).to(SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  self.default_image_processor
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  prepare_video()
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  image_processor(SCREAMING_SNAKE_CASE__		,return_tensors='''pt'''							).to(SCREAMING_SNAKE_CASE__							)

             # add boolean mask, indicating which patches to mask
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  hf_hub_download(repo_id='''hf-internal-testing/bool-masked-pos'''		,filename='''bool_masked_pos.pt'''							)
             __SCREAMING_SNAKE_CASE   :int						=  torch.load(SCREAMING_SNAKE_CASE__							)

             # forward pass
             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE   :List[str]						=  model(**SCREAMING_SNAKE_CASE__							)

             # verify the logits
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  torch.Size([1, 14_08, 15_36]							)
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  torch.tensor(
                 [[0.7_9_9_4, 0.9_6_1_2, 0.8_5_0_8], [0.7_4_0_1, 0.8_9_5_8, 0.8_3_0_2], [0.5_8_6_2, 0.7_4_6_8, 0.7_3_2_5]]		,device=SCREAMING_SNAKE_CASE__							)
             self.assertEqual(outputs.logits.shape		,SCREAMING_SNAKE_CASE__							)
             self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]		,SCREAMING_SNAKE_CASE__		,atol=1E-4							)							)

             # verify the loss (`config.norm_pix_loss` = `True`)
             __SCREAMING_SNAKE_CASE   :Any						=  torch.tensor([0.5_1_4_2]		,device=SCREAMING_SNAKE_CASE__							)
             self.assertTrue(torch.allclose(outputs.loss		,SCREAMING_SNAKE_CASE__		,atol=1E-4							)							)

             # verify the loss (`config.norm_pix_loss` = `False`)
             __SCREAMING_SNAKE_CASE   :Tuple						=  VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''		,norm_pix_loss=SCREAMING_SNAKE_CASE__							).to(
                 SCREAMING_SNAKE_CASE__							)

             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE   :Tuple						=  model(**SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  torch.tensor(torch.tensor([0.6_4_6_9]							)		,device=SCREAMING_SNAKE_CASE__							)
             self.assertTrue(torch.allclose(outputs.loss		,SCREAMING_SNAKE_CASE__		,atol=1E-4							)							)






"""simple docstring"""
from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available, is_vision_available
from ...utils import OptionalDependencyNotAvailable


lowerCamelCase_								=		{"configuration_dpt": ["DPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "DPTConfig"]}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase_								=		["DPTFeatureExtractor"]
  lowerCamelCase_								=		["DPTImageProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase_								=		[
      "DPT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "DPTForDepthEstimation",
      "DPTForSemanticSegmentation",
      "DPTModel",
      "DPTPreTrainedModel",
  ]


if TYPE_CHECKING:
  from .configuration_dpt import DPT_PRETRAINED_CONFIG_ARCHIVE_MAP, DPTConfig

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_dpt import DPTFeatureExtractor
    from .image_processing_dpt import DPTImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_dpt import (
        DPT_PRETRAINED_MODEL_ARCHIVE_LIST,
        DPTForDepthEstimation,
        DPTForSemanticSegmentation,
        DPTModel,
        DPTPreTrainedModel,
    )


else:
  import sys

  lowerCamelCase_								=		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)