






import argparse
import json

import gdown
import numpy as np
import torch
from huggingface_hub import hf_hub_download

from transformers import (
    VideoMAEConfig,
    VideoMAEForPreTraining,
    VideoMAEForVideoClassification,
    VideoMAEImageProcessor,
)






def     _snake_case    (__lowercase):
   UpperCamelCase_									=     VideoMAEConfig()

   set_architecture_configs(__lowercase    ,      __lowercase)

   if "finetuned" not in model_name:
      UpperCamelCase_									=     False

   if "finetuned" in model_name:
      UpperCamelCase_									=     'huggingface/label-files'
      if "kinetics" in model_name:
         UpperCamelCase_									=     400
         UpperCamelCase_									=     'kinetics400-id2label.json'
      elif "ssv2" in model_name:
         UpperCamelCase_									=     174
         UpperCamelCase_									=     'something-something-v2-id2label.json'
      else:
         raise ValueError('Model name should either contain \'kinetics\' or \'ssv2\' in case it\'s fine-tuned.')
      UpperCamelCase_									=     json.load(open(hf_hub_download(__lowercase    ,      __lowercase    ,      repo_type='dataset')    ,      'r'))
      UpperCamelCase_									=     {int(__lowercase): v for k, v in idalabel.items()}
      UpperCamelCase_									=     idalabel
      UpperCamelCase_									=     {v: k for k, v in idalabel.items()}

   return config






def     _snake_case    (__lowercase    ,      __lowercase):
   if "small" in model_name:
      UpperCamelCase_									=     384
      UpperCamelCase_									=     1536
      UpperCamelCase_									=     12
      UpperCamelCase_									=     16
      UpperCamelCase_									=     12
      UpperCamelCase_									=     3
      UpperCamelCase_									=     192
      UpperCamelCase_									=     768
   elif "large" in model_name:
      UpperCamelCase_									=     1024
      UpperCamelCase_									=     4096
      UpperCamelCase_									=     24
      UpperCamelCase_									=     16
      UpperCamelCase_									=     12
      UpperCamelCase_									=     8
      UpperCamelCase_									=     512
      UpperCamelCase_									=     2048
   elif "huge" in model_name:
      UpperCamelCase_									=     1280
      UpperCamelCase_									=     5120
      UpperCamelCase_									=     32
      UpperCamelCase_									=     16
      UpperCamelCase_									=     12
      UpperCamelCase_									=     8
      UpperCamelCase_									=     640
      UpperCamelCase_									=     2560
   elif "base" not in model_name:
      raise ValueError('Model name should include either "small", "base", "large", or "huge"')






def     _snake_case    (__lowercase):
   if "encoder." in name:
      UpperCamelCase_									=     name.replace('encoder.'    ,      '')
   if "cls_token" in name:
      UpperCamelCase_									=     name.replace('cls_token'    ,      'videomae.embeddings.cls_token')
   if "decoder_pos_embed" in name:
      UpperCamelCase_									=     name.replace('decoder_pos_embed'    ,      'decoder.decoder_pos_embed')
   if "pos_embed" in name and "decoder" not in name:
      UpperCamelCase_									=     name.replace('pos_embed'    ,      'videomae.embeddings.position_embeddings')
   if "patch_embed.proj" in name:
      UpperCamelCase_									=     name.replace('patch_embed.proj'    ,      'videomae.embeddings.patch_embeddings.projection')
   if "patch_embed.norm" in name:
      UpperCamelCase_									=     name.replace('patch_embed.norm'    ,      'videomae.embeddings.norm')
   if "decoder.blocks" in name:
      UpperCamelCase_									=     name.replace('decoder.blocks'    ,      'decoder.decoder_layers')
   if "blocks" in name:
      UpperCamelCase_									=     name.replace('blocks'    ,      'videomae.encoder.layer')
   if "attn.proj" in name:
      UpperCamelCase_									=     name.replace('attn.proj'    ,      'attention.output.dense')
   if "attn" in name and "bias" not in name:
      UpperCamelCase_									=     name.replace('attn'    ,      'attention.self')
   if "attn" in name:
      UpperCamelCase_									=     name.replace('attn'    ,      'attention.attention')
   if "norm1" in name:
      UpperCamelCase_									=     name.replace('norm1'    ,      'layernorm_before')
   if "norm2" in name:
      UpperCamelCase_									=     name.replace('norm2'    ,      'layernorm_after')
   if "mlp.fc1" in name:
      UpperCamelCase_									=     name.replace('mlp.fc1'    ,      'intermediate.dense')
   if "mlp.fc2" in name:
      UpperCamelCase_									=     name.replace('mlp.fc2'    ,      'output.dense')
   if "decoder_embed" in name:
      UpperCamelCase_									=     name.replace('decoder_embed'    ,      'decoder.decoder_embed')
   if "decoder_norm" in name:
      UpperCamelCase_									=     name.replace('decoder_norm'    ,      'decoder.decoder_norm')
   if "decoder_pred" in name:
      UpperCamelCase_									=     name.replace('decoder_pred'    ,      'decoder.decoder_pred')
   if "norm.weight" in name and "decoder" not in name and "fc" not in name:
      UpperCamelCase_									=     name.replace('norm.weight'    ,      'videomae.layernorm.weight')
   if "norm.bias" in name and "decoder" not in name and "fc" not in name:
      UpperCamelCase_									=     name.replace('norm.bias'    ,      'videomae.layernorm.bias')
   if "head" in name and "decoder" not in name:
      UpperCamelCase_									=     name.replace('head'    ,      'classifier')

   return name






def     _snake_case    (__lowercase    ,      __lowercase):
   for key in orig_state_dict.copy().keys():
      UpperCamelCase_									=     orig_state_dict.pop(__lowercase)

      if key.startswith('encoder.'):
         UpperCamelCase_									=     key.replace('encoder.'    ,      '')

      if "qkv" in key:
         UpperCamelCase_									=     key.split('.')
         if key.startswith('decoder.blocks'):
            UpperCamelCase_									=     config.decoder_hidden_size
            UpperCamelCase_									=     int(key_split[2])
            UpperCamelCase_									=     'decoder.decoder_layers.'
            if "weight" in key:
               UpperCamelCase_									=     val[:dim, :]
               UpperCamelCase_									=     val[dim : dim * 2, :]
               UpperCamelCase_									=     val[-dim:, :]
         else:
            UpperCamelCase_									=     config.hidden_size
            UpperCamelCase_									=     int(key_split[1])
            UpperCamelCase_									=     'videomae.encoder.layer.'
            if "weight" in key:
               UpperCamelCase_									=     val[:dim, :]
               UpperCamelCase_									=     val[dim : dim * 2, :]
               UpperCamelCase_									=     val[-dim:, :]
      else:
         UpperCamelCase_									=     val

   return orig_state_dict






def     _snake_case    ():
   UpperCamelCase_									=     hf_hub_download(
       repo_id='hf-internal-testing/spaghetti-video'    ,      filename='eating_spaghetti.npy'    ,      repo_type='dataset')
   UpperCamelCase_									=     np.load(__lowercase)
   return list(__lowercase)






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase):
   UpperCamelCase_									=     get_videomae_config(__lowercase)

   if "finetuned" in model_name:
      UpperCamelCase_									=     VideoMAEForVideoClassification(__lowercase)
   else:
      UpperCamelCase_									=     VideoMAEForPreTraining(__lowercase)

   # download original checkpoint, hosted on Google Drive
   UpperCamelCase_									=     'pytorch_model.bin'
   gdown.cached_download(__lowercase    ,      __lowercase    ,      quiet=__lowercase)
   UpperCamelCase_									=     torch.load(__lowercase    ,      map_location='cpu')
   if "model" in files:
      UpperCamelCase_									=     files['model']
   else:
      UpperCamelCase_									=     files['module']
   UpperCamelCase_									=     convert_state_dict(__lowercase    ,      __lowercase)

   model.load_state_dict(__lowercase)
   model.eval()

   # verify model on basic input
   UpperCamelCase_									=     VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]    ,      image_std=[0.5, 0.5, 0.5])
   UpperCamelCase_									=     prepare_video()
   UpperCamelCase_									=     image_processor(__lowercase    ,      return_tensors='pt')

   if "finetuned" not in model_name:
      UpperCamelCase_									=     hf_hub_download(repo_id='hf-internal-testing/bool-masked-pos'    ,      filename='bool_masked_pos.pt')
      UpperCamelCase_									=     torch.load(__lowercase)

   UpperCamelCase_									=     model(**__lowercase)
   UpperCamelCase_									=     outputs.logits

   UpperCamelCase_									=     [
       'videomae-small-finetuned-kinetics',
       'videomae-small-finetuned-ssv2',
       # Kinetics-400 checkpoints (short = pretrained only for 800 epochs instead of 1600)
       'videomae-base-short',
       'videomae-base-short-finetuned-kinetics',
       'videomae-base',
       'videomae-base-finetuned-kinetics',
       'videomae-large',
       'videomae-large-finetuned-kinetics',
       'videomae-huge-finetuned-kinetics',
       # Something-Something-v2 checkpoints (short = pretrained only for 800 epochs instead of 2400)
       'videomae-base-short-ssv2',
       'videomae-base-short-finetuned-ssv2',
       'videomae-base-ssv2',
       'videomae-base-finetuned-ssv2',
   ]

   # NOTE: logits were tested with image_mean and image_std equal to [0.5, 0.5, 0.5] and [0.5, 0.5, 0.5]
   if model_name == "videomae-small-finetuned-kinetics":
      UpperCamelCase_									=     torch.Size([1, 400])
      UpperCamelCase_									=     torch.tensor([-0.9_291, -0.4_061, -0.9_307])
   elif model_name == "videomae-small-finetuned-ssv2":
      UpperCamelCase_									=     torch.Size([1, 174])
      UpperCamelCase_									=     torch.tensor([0.2_671, -0.4_689, -0.8_235])
   elif model_name == "videomae-base":
      UpperCamelCase_									=     torch.Size([1, 1408, 1536])
      UpperCamelCase_									=     torch.tensor([[0.7_739, 0.7_968, 0.7_089], [0.6_701, 0.7_487, 0.6_209], [0.4_287, 0.5_158, 0.4_773]])
   elif model_name == "videomae-base-short":
      UpperCamelCase_									=     torch.Size([1, 1408, 1536])
      UpperCamelCase_									=     torch.tensor([[0.7_994, 0.9_612, 0.8_508], [0.7_401, 0.8_958, 0.8_302], [0.5_862, 0.7_468, 0.7_325]])
      # we verified the loss both for normalized and unnormalized targets for this one
      UpperCamelCase_									=     torch.tensor([0.5_142]) if config.norm_pix_loss else torch.tensor([0.6_469])
   elif model_name == "videomae-large":
      UpperCamelCase_									=     torch.Size([1, 1408, 1536])
      UpperCamelCase_									=     torch.tensor([[0.7_149, 0.7_997, 0.6_966], [0.6_768, 0.7_869, 0.6_948], [0.5_139, 0.6_221, 0.5_605]])
   elif model_name == "videomae-large-finetuned-kinetics":
      UpperCamelCase_									=     torch.Size([1, 400])
      UpperCamelCase_									=     torch.tensor([0.0_771, 0.0_011, -0.3_625])
   elif model_name == "videomae-huge-finetuned-kinetics":
      UpperCamelCase_									=     torch.Size([1, 400])
      UpperCamelCase_									=     torch.tensor([0.2_433, 0.1_632, -0.4_894])
   elif model_name == "videomae-base-short-finetuned-kinetics":
      UpperCamelCase_									=     torch.Size([1, 400])
      UpperCamelCase_									=     torch.tensor([0.6_588, 0.0_990, -0.2_493])
   elif model_name == "videomae-base-finetuned-kinetics":
      UpperCamelCase_									=     torch.Size([1, 400])
      UpperCamelCase_									=     torch.tensor([0.3_669, -0.0_688, -0.2_421])
   elif model_name == "videomae-base-short-ssv2":
      UpperCamelCase_									=     torch.Size([1, 1408, 1536])
      UpperCamelCase_									=     torch.tensor([[0.4_712, 0.5_296, 0.5_786], [0.2_278, 0.2_729, 0.4_026], [0.0_352, 0.0_730, 0.2_506]])
   elif model_name == "videomae-base-short-finetuned-ssv2":
      UpperCamelCase_									=     torch.Size([1, 174])
      UpperCamelCase_									=     torch.tensor([-0.0_537, -0.1_539, -0.3_266])
   elif model_name == "videomae-base-ssv2":
      UpperCamelCase_									=     torch.Size([1, 1408, 1536])
      UpperCamelCase_									=     torch.tensor([[0.8_131, 0.8_727, 0.8_546], [0.7_366, 0.9_377, 0.8_870], [0.5_935, 0.8_874, 0.8_564]])
   elif model_name == "videomae-base-finetuned-ssv2":
      UpperCamelCase_									=     torch.Size([1, 174])
      UpperCamelCase_									=     torch.tensor([0.1_961, -0.8_337, -0.6_389])
   else:
      raise ValueError(f"""Model name not supported. Should be one of {model_names}""")

   # verify logits
   assert logits.shape == expected_shape
   if "finetuned" in model_name:
      assert torch.allclose(logits[0, :3]    ,      __lowercase    ,      atol=1e-4)
   else:
      print('Logits:'    ,      logits[0, :3, :3])
      assert torch.allclose(logits[0, :3, :3]    ,      __lowercase    ,      atol=1e-4)
   print('Logits ok!')

   # verify loss, if applicable
   if model_name == "videomae-base-short":
      UpperCamelCase_									=     outputs.loss
      assert torch.allclose(__lowercase    ,      __lowercase    ,      atol=1e-4)
      print('Loss ok!')

   if pytorch_dump_folder_path is not None:
      print(f"""Saving model and image processor to {pytorch_dump_folder_path}""")
      image_processor.save_pretrained(__lowercase)
      model.save_pretrained(__lowercase)

   if push_to_hub:
      print('Pushing to the hub...')
      model.push_to_hub(__lowercase    ,      organization='nielsr')


if __name__ == "__main__":
 snake_case__      :	Tuple       	=      argparse.ArgumentParser()
 # Required parameters
 parser.add_argument(
     """--checkpoint_url""",
     default="""https://drive.google.com/u/1/uc?id=1tEhLyskjb755TJ65ptsrafUG2llSwQE1&amp;export=download&amp;confirm=t&amp;uuid=aa3276eb-fb7e-482a-adec-dc7171df14c4""",
     type=str,
     help=(
         """URL of the original PyTorch checkpoint (on Google Drive) you'd like to convert. Should be a direct"""
         """ download link."""
     ),
 )
 parser.add_argument(
     """--pytorch_dump_folder_path""",
     default="""/Users/nielsrogge/Documents/VideoMAE/Test""",
     type=str,
     help="""Path to the output PyTorch model directory.""",
 )
 parser.add_argument("""--model_name""", default="""videomae-base""", type=str, help="""Name of the model.""")
 parser.add_argument(
     """--push_to_hub""", action="""store_true""", help="""Whether or not to push the converted model to the 🤗 hub."""
 )

 snake_case__      :	Tuple       	=      parser.parse_args()
 convert_videomae_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path, args.model_name, args.push_to_hub)










import inspect
import unittest

from transformers import ViTMSNConfig
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 ViTMSNForImageClassification, ViTMSNModel
 from transformers.models.vit_msn.modeling_vit_msn import VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import ViTImageProcessor


class 						_a       :






  """simple docstring"""





  def __init__(     self		,		_UpperCAmelCase		,		_UpperCAmelCase=13		,		_UpperCAmelCase=30		,		_UpperCAmelCase=2		,		_UpperCAmelCase=3		,		_UpperCAmelCase=True		,		_UpperCAmelCase=True		,		_UpperCAmelCase=32		,		_UpperCAmelCase=5		,		_UpperCAmelCase=4		,		_UpperCAmelCase=37		,		_UpperCAmelCase="gelu"		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=10		,		_UpperCAmelCase=0.0_2		,		_UpperCAmelCase=None		,		)			-> Optional[Any]:
     UpperCamelCase_									=     parent
     UpperCamelCase_									=     batch_size
     UpperCamelCase_									=     image_size
     UpperCamelCase_									=     patch_size
     UpperCamelCase_									=     num_channels
     UpperCamelCase_									=     is_training
     UpperCamelCase_									=     use_labels
     UpperCamelCase_									=     hidden_size
     UpperCamelCase_									=     num_hidden_layers
     UpperCamelCase_									=     num_attention_heads
     UpperCamelCase_									=     intermediate_size
     UpperCamelCase_									=     hidden_act
     UpperCamelCase_									=     hidden_dropout_prob
     UpperCamelCase_									=     attention_probs_dropout_prob
     UpperCamelCase_									=     type_sequence_label_size
     UpperCamelCase_									=     initializer_range
     UpperCamelCase_									=     scope

     # in ViT MSN, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
     UpperCamelCase_									=     (image_size // patch_size) ** 2
     UpperCamelCase_									=     num_patches + 1




  def    _UpperCAmelCase     (     self )			-> Tuple:
     UpperCamelCase_									=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

     UpperCamelCase_									=     None
     if self.use_labels:
        UpperCamelCase_									=     ids_tensor([self.batch_size]		,		self.type_sequence_label_size )

     UpperCamelCase_									=     self.get_config()

     return config, pixel_values, labels




  def    _UpperCAmelCase     (     self )			-> int:
     return ViTMSNConfig(
         image_size=self.image_size		,		patch_size=self.patch_size		,		num_channels=self.num_channels		,		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		,		initializer_range=self.initializer_range		,		)




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> Any:
     UpperCamelCase_									=     ViTMSNModel(config=_UpperCAmelCase )
     model.to(_UpperCAmelCase )
     model.eval()
     UpperCamelCase_									=     model(_UpperCAmelCase )
     self.parent.assertEqual(result.last_hidden_state.shape		,		(self.batch_size, self.seq_length, self.hidden_size) )




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase )			-> str:
     UpperCamelCase_									=     self.type_sequence_label_size
     UpperCamelCase_									=     ViTMSNForImageClassification(_UpperCAmelCase )
     model.to(_UpperCAmelCase )
     model.eval()
     UpperCamelCase_									=     model(_UpperCAmelCase		,		labels=_UpperCAmelCase )
     print('Pixel and labels shape: {pixel_values.shape}, {labels.shape}' )
     print('Labels: {labels}' )
     self.parent.assertEqual(result.logits.shape		,		(self.batch_size, self.type_sequence_label_size) )

     # test greyscale images
     UpperCamelCase_									=     1
     UpperCamelCase_									=     ViTMSNForImageClassification(_UpperCAmelCase )
     model.to(_UpperCAmelCase )
     model.eval()

     UpperCamelCase_									=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
     UpperCamelCase_									=     model(_UpperCAmelCase )
     self.parent.assertEqual(result.logits.shape		,		(self.batch_size, self.type_sequence_label_size) )




  def    _UpperCAmelCase     (     self )			-> Dict:
     UpperCamelCase_									=     self.prepare_config_and_inputs()
     UpperCamelCase_		,      UpperCamelCase_		,      UpperCamelCase_									=     config_and_inputs
     UpperCamelCase_									=     {'pixel_values': pixel_values}
     return config, inputs_dict




@require_torch
class 						_a       (  UpperCAmelCase__						,       UpperCAmelCase__						,       unittest.TestCase    ):






  """simple docstring"""





  A_						=   (ViTMSNModel, ViTMSNForImageClassification) if is_torch_available() else ()
  A_						=   (
      {"""feature-extraction""": ViTMSNModel, """image-classification""": ViTMSNForImageClassification}
      if is_torch_available()
      else {}
  )

  A_						=   False
  A_						=   False
  A_						=   False
  A_						=   False




  def    _UpperCAmelCase     (     self )			-> Dict:
     UpperCamelCase_									=     ViTMSNModelTester(self )
     UpperCamelCase_									=     ConfigTester(self		,		config_class=_UpperCAmelCase		,		has_text_modality=_UpperCAmelCase		,		hidden_size=37 )




  def    _UpperCAmelCase     (     self )			-> List[Any]:
     self.config_tester.run_common_tests()




  @unittest.skip(reason='ViTMSN does not use inputs_embeds' )
  def    _UpperCAmelCase     (     self )			-> Optional[Any]:
     pass




  def    _UpperCAmelCase     (     self )			-> List[str]:
     UpperCamelCase_		,      UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs_for_common()

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




  def    _UpperCAmelCase     (     self )			-> List[str]:
     UpperCamelCase_		,      UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
        UpperCamelCase_									=     model_class(_UpperCAmelCase )
        UpperCamelCase_									=     inspect.signature(model.forward )
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        UpperCamelCase_									=     [*signature.parameters.keys()]

        UpperCamelCase_									=     ['pixel_values']
        self.assertListEqual(arg_names[:1]		,		_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> Any:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_UpperCAmelCase )




  def    _UpperCAmelCase     (     self )			-> List[Any]:
     UpperCamelCase_									=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase )




  @slow
  def    _UpperCAmelCase     (     self )			-> Dict:
     for model_name in VIT_MSN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        UpperCamelCase_									=     ViTMSNModel.from_pretrained(_UpperCAmelCase )
        self.assertIsNotNone(_UpperCAmelCase )






def     _snake_case    ():
   UpperCamelCase_									=     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
   return image


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






  """simple docstring"""





  @cached_property
  def    _UpperCAmelCase     (     self )			-> Union[str, Any]:
     return ViTImageProcessor.from_pretrained('facebook/vit-msn-small' ) if is_vision_available() else None




  @slow
  def    _UpperCAmelCase     (     self )			-> List[str]:
     torch.manual_seed(2 )
     UpperCamelCase_									=     ViTMSNForImageClassification.from_pretrained('facebook/vit-msn-small' ).to(_UpperCAmelCase )

     UpperCamelCase_									=     self.default_image_processor
     UpperCamelCase_									=     prepare_img()
     UpperCamelCase_									=     image_processor(images=_UpperCAmelCase		,		return_tensors='pt' ).to(_UpperCAmelCase )

     # forward pass
     with torch.no_grad():
        UpperCamelCase_									=     model(**_UpperCAmelCase )

     # verify the logits
     UpperCamelCase_									=     torch.Size((1, 1000) )
     self.assertEqual(outputs.logits.shape		,		_UpperCAmelCase )

     UpperCamelCase_									=     torch.tensor([-0.0_8_0_3, -0.4_4_5_4, -0.2_3_7_5] ).to(_UpperCAmelCase )

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





