


'''simple docstring'''



import argparse
import collections
import os
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_table.py
__UpperCAmelCase      :Optional[Any]			    =       "src/transformers"
__UpperCAmelCase      :List[str]			    =       "docs/source/en"
__UpperCAmelCase      :int			    =       "."




def      _a     (						_lowercase :     Union[str, Any]      , _lowercase :     str      , _lowercase :     Any  ):





					'''simple docstring'''






					with open(_lowercase      , '''r'''      , encoding='''utf-8'''      , newline='''\n'''  ) as f:
										__UpperCAmelCase     :			Union[str, Any]  							=      f.readlines()
					# Find the start prompt.
					__UpperCAmelCase     :			Tuple  							=      0
					while not lines[start_index].startswith(_lowercase  ):
										start_index += 1
					start_index += 1

					__UpperCAmelCase     :			str  							=      start_index
					while not lines[end_index].startswith(_lowercase  ):
										end_index += 1
					end_index -= 1

					while len(lines[start_index]  ) <= 1:
										start_index += 1
					while len(lines[end_index]  ) <= 1:
										end_index -= 1
					end_index += 1
					return "".join(lines[start_index:end_index]  ), start_index, end_index, lines


# Add here suffixes that are used to identify models, separated by |
__UpperCAmelCase      :Union[str, Any]			    =       "Model|Encoder|Decoder|ForConditionalGeneration"
# Regexes that match TF/Flax/PT model names.
__UpperCAmelCase      :Tuple			    =       re.compile(r"TF(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)")
__UpperCAmelCase      :Optional[Any]			    =       re.compile(r"Flax(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)")
# Will match any TF or Flax model too so need to be in an else branch afterthe two previous regexes.
__UpperCAmelCase      :Optional[Any]			    =       re.compile(r"(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)")


# This is to make sure the transformers module imported is the one in the repo.
__UpperCAmelCase      :Union[str, Any]			    =       direct_transformers_import(TRANSFORMERS_PATH)




def      _a     (						_lowercase :     List[Any]  ):





					'''simple docstring'''






					__UpperCAmelCase     :			Optional[int]  							=      re.finditer('''.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)'''      , _lowercase  )
					return [m.group(0  ) for m in matches]




def      _a     (						_lowercase :     List[Any]      , _lowercase :     Union[str, Any]  ):





					'''simple docstring'''






					__UpperCAmelCase     :			Union[str, Any]  							=      2 if text == '''✅''' or text == '''❌''' else len(_lowercase  )
					__UpperCAmelCase     :			Dict  							=      (width - text_length) // 2
					__UpperCAmelCase     :			int  							=      width - text_length - left_indent
					return " " * left_indent + text + " " * right_indent




def      _a     (						):





					'''simple docstring'''






					__UpperCAmelCase     :			Tuple  							=      transformers_module.models.auto.configuration_auto.CONFIG_MAPPING_NAMES
					__UpperCAmelCase     :			Optional[Any]  							=      {
					    name: config_maping_names[code]
					    for code, name in transformers_module.MODEL_NAMES_MAPPING.items()
					    if code in config_maping_names
					}
					__UpperCAmelCase     :			Any  							=      {name: config.replace('''Config'''      , ''''''  ) for name, config in model_name_to_config.items()}

					# Dictionaries flagging if each model prefix has a slow/fast tokenizer, backend in PT/TF/Flax.
					__UpperCAmelCase     :			Any  							=      collections.defaultdict(_lowercase  )
					__UpperCAmelCase     :			Tuple  							=      collections.defaultdict(_lowercase  )
					__UpperCAmelCase     :			List[Any]  							=      collections.defaultdict(_lowercase  )
					__UpperCAmelCase     :			List[Any]  							=      collections.defaultdict(_lowercase  )
					__UpperCAmelCase     :			Tuple  							=      collections.defaultdict(_lowercase  )

					# Let's lookup through all transformers object (once).
					for attr_name in dir(_lowercase  ):
										__UpperCAmelCase     :			Tuple  							=      None
										if attr_name.endswith('''Tokenizer'''  ):
															__UpperCAmelCase     :			Optional[int]  							=      slow_tokenizers
															__UpperCAmelCase     :			Optional[int]  							=      attr_name[:-9]
										elif attr_name.endswith('''TokenizerFast'''  ):
															__UpperCAmelCase     :			List[Any]  							=      fast_tokenizers
															__UpperCAmelCase     :			int  							=      attr_name[:-13]
										elif _re_tf_models.match(_lowercase  ) is not None:
															__UpperCAmelCase     :			Optional[int]  							=      tf_models
															__UpperCAmelCase     :			Optional[int]  							=      _re_tf_models.match(_lowercase  ).groups()[0]
										elif _re_flax_models.match(_lowercase  ) is not None:
															__UpperCAmelCase     :			List[str]  							=      flax_models
															__UpperCAmelCase     :			List[str]  							=      _re_flax_models.match(_lowercase  ).groups()[0]
										elif _re_pt_models.match(_lowercase  ) is not None:
															__UpperCAmelCase     :			Optional[Any]  							=      pt_models
															__UpperCAmelCase     :			Optional[int]  							=      _re_pt_models.match(_lowercase  ).groups()[0]

										if lookup_dict is not None:
															while len(_lowercase  ) > 0:
																				if attr_name in model_name_to_prefix.values():
																									__UpperCAmelCase     :			Optional[Any]  							=      True
																									break
																				# Try again after removing the last word in the name
																				__UpperCAmelCase     :			Any  							=      ''''''.join(camel_case_split(_lowercase  )[:-1]  )

    # Let's build that table!
					__UpperCAmelCase     :			List[str]  							=      list(model_name_to_config.keys()  )
					model_names.sort(key=str.lower  )
					__UpperCAmelCase     :			Any  							=      ['''Model''', '''Tokenizer slow''', '''Tokenizer fast''', '''PyTorch support''', '''TensorFlow support''', '''Flax Support''']
					# We'll need widths to properly display everything in the center (+2 is to leave one extra space on each side).
					__UpperCAmelCase     :			List[Any]  							=      [len(_lowercase  ) + 2 for c in columns]
					__UpperCAmelCase     :			Tuple  							=      max([len(_lowercase  ) for name in model_names]  ) + 2

					# Build the table per se
					__UpperCAmelCase     :			List[Any]  							=      '''|''' + '''|'''.join([_center_text(_lowercase      , _lowercase  ) for c, w in zip(_lowercase      , _lowercase  )]  ) + '''|\n'''
					# Use ":-----:" format to center-aligned table cell texts
					table += "|" + "|".join([''':''' + '''-''' * (w - 2) + ''':''' for w in widths]  ) + "|\n"

					__UpperCAmelCase     :			Union[str, Any]  							=      {True: '''✅''', False: '''❌'''}
					for name in model_names:
										__UpperCAmelCase     :			int  							=      model_name_to_prefix[name]
										__UpperCAmelCase     :			Tuple  							=      [
										    name,
										    check[slow_tokenizers[prefix]],
										    check[fast_tokenizers[prefix]],
										    check[pt_models[prefix]],
										    check[tf_models[prefix]],
										    check[flax_models[prefix]],
										]
										table += "|" + "|".join([_center_text(_lowercase      , _lowercase  ) for l, w in zip(_lowercase      , _lowercase  )]  ) + "|\n"
					return table




def      _a     (						_lowercase :     int=False  ):





					'''simple docstring'''






					__UpperCAmelCase     :			Any  							=      _find_text_in_file(
					    filename=os.path.join(_lowercase      , '''index.md'''  )      , start_prompt='''<!--This table is updated automatically from the auto modules'''      , end_prompt='''<!-- End table-->'''      , )
					__UpperCAmelCase     :			Any  							=      get_model_table_from_auto_modules()

					if current_table != new_table:
										if overwrite:
															with open(os.path.join(_lowercase      , '''index.md'''  )      , '''w'''      , encoding='''utf-8'''      , newline='''\n'''  ) as f:
																				f.writelines(lines[:start_index] + [new_table] + lines[end_index:]  )
										else:
															raise ValueError(
															    '''The model table in the `index.md` has not been updated. Run `make fix-copies` to fix this.'''  )


if __name__ == "__main__":
						__UpperCAmelCase      :Tuple			    =       argparse.ArgumentParser()
						parser.add_argument("--fix_and_overwrite", action="store_true", help="Whether to fix inconsistencies.")
						__UpperCAmelCase      :Optional[Any]			    =       parser.parse_args()

						check_model_table(args.fix_and_overwrite)



'''simple docstring'''



import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import TimesformerConfig
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,
          TimesformerForVideoClassification,
          TimesformerModel,
      )
      from transformers.models.timesformer.modeling_timesformer import TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from transformers import VideoMAEImageProcessor



class      a    :


     """simple docstring"""






     def __init__(    self					:		List[str]							,			snake_case					:		Any							,			snake_case					:		Tuple=13							,			snake_case					:		Any=10							,			snake_case					:		Any=3							,			snake_case					:		Dict=2							,			snake_case					:		Optional[Any]=2							,			snake_case					:		Union[str, Any]=True							,			snake_case					:		Dict=True							,			snake_case					:		List[Any]=32							,			snake_case					:		Dict=5							,			snake_case					:		List[str]=4							,			snake_case					:		Dict=37							,			snake_case					:		Any="gelu"							,			snake_case					:		Optional[int]=0.1							,			snake_case					:		Union[str, Any]=0.1							,			snake_case					:		Optional[int]=10							,			snake_case					:		Dict=0.02							,			snake_case					:		Tuple="divided_space_time"							,			snake_case					:		List[Any]=None							,			)						->							Optional[int]:
          __UpperCAmelCase     :			Dict  							=      parent
          __UpperCAmelCase     :			Tuple  							=      batch_size
          __UpperCAmelCase     :			Optional[Any]  							=      image_size
          __UpperCAmelCase     :			Optional[int]  							=      num_channels
          __UpperCAmelCase     :			Optional[Any]  							=      patch_size
          __UpperCAmelCase     :			List[str]  							=      num_frames
          __UpperCAmelCase     :			Union[str, Any]  							=      is_training
          __UpperCAmelCase     :			str  							=      use_labels
          __UpperCAmelCase     :			Union[str, Any]  							=      hidden_size
          __UpperCAmelCase     :			Any  							=      num_hidden_layers
          __UpperCAmelCase     :			List[Any]  							=      num_attention_heads
          __UpperCAmelCase     :			Dict  							=      intermediate_size
          __UpperCAmelCase     :			List[str]  							=      hidden_act
          __UpperCAmelCase     :			List[Any]  							=      hidden_dropout_prob
          __UpperCAmelCase     :			int  							=      attention_probs_dropout_prob
          __UpperCAmelCase     :			Any  							=      attention_type
          __UpperCAmelCase     :			Optional[Any]  							=      initializer_range
          __UpperCAmelCase     :			str  							=      scope
          __UpperCAmelCase     :			List[str]  							=      num_labels

          # in TimeSformer, the number of spatial tokens equals num_frames * num_patches per frame + 1 CLS token
          __UpperCAmelCase     :			str  							=      (image_size // patch_size) ** 2
          __UpperCAmelCase     :			int  							=      (num_frames) * self.num_patches_per_frame + 1

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Tuple:
          __UpperCAmelCase     :			List[str]  							=      floats_tensor(
              [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]      )

          __UpperCAmelCase     :			Dict  							=      None
          if self.use_labels:
               __UpperCAmelCase     :			List[str]  							=      ids_tensor([self.batch_size]							,			self.num_labels      )

          __UpperCAmelCase     :			Optional[int]  							=      self.get_config()

          return config, pixel_values, labels

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Optional[Any]:
          __UpperCAmelCase     :			str  							=      TimesformerConfig(
              image_size=self.image_size							,			patch_size=self.patch_size							,			num_channels=self.num_channels							,			num_frames=self.num_frames							,			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							,			attention_type=self.attention_type							,			)
          __UpperCAmelCase     :			Optional[int]  							=      self.num_labels
          return config

     def 			lowerCamelCase__			(    self					:		Dict							,			snake_case					:		Any							,			snake_case					:		Optional[int]							,			snake_case					:		List[Any]      )						->							Optional[Any]:
          __UpperCAmelCase     :			List[Any]  							=      TimesformerModel(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Tuple  							=      model(snake_case      )
          self.parent.assertEqual(result.last_hidden_state.shape							,			(self.batch_size, self.seq_length, self.hidden_size)      )

     def 			lowerCamelCase__			(    self					:		int							,			snake_case					:		Tuple							,			snake_case					:		List[Any]							,			snake_case					:		Optional[Any]      )						->							str:
          __UpperCAmelCase     :			Union[str, Any]  							=      TimesformerForVideoClassification(snake_case      )
          model.to(snake_case      )
          model.eval()

          __UpperCAmelCase     :			str  							=      model(snake_case      )

          # verify the logits shape
          __UpperCAmelCase     :			List[str]  							=      torch.Size((self.batch_size, self.num_labels)      )
          self.parent.assertEqual(result.logits.shape							,			snake_case      )






     def 			lowerCamelCase__			(    self					:		Any      )						->							List[str]:
          __UpperCAmelCase     :			Optional[int]  							=      self.prepare_config_and_inputs()
          __UpperCAmelCase							,       __UpperCAmelCase							,       __UpperCAmelCase     :			int  							=      config_and_inputs
          __UpperCAmelCase     :			Optional[Any]  							=      {'''pixel_values''': pixel_values}
          return config, inputs_dict



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


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			List[str]							       =       (TimesformerModel, TimesformerForVideoClassification) if is_torch_available() else ()
     SCREAMING_SNAKE_CASE	:			Optional[Any]							       =       (
         {"feature-extraction": TimesformerModel, "video-classification": TimesformerForVideoClassification}
         if is_torch_available()
         else {}
     )

     SCREAMING_SNAKE_CASE	:			int							       =       False
     SCREAMING_SNAKE_CASE	:			str							       =       False
     SCREAMING_SNAKE_CASE	:			Union[str, Any]							       =       False
     SCREAMING_SNAKE_CASE	:			List[Any]							       =       False

     def 			lowerCamelCase__			(    self					:		int      )						->							str:
          __UpperCAmelCase     :			Tuple  							=      TimesformerModelTester(self      )
          __UpperCAmelCase     :			str  							=      ConfigTester(
              self							,			config_class=snake_case							,			has_text_modality=snake_case							,			hidden_size=37      )

     def 			lowerCamelCase__			(    self					:		Dict							,			snake_case					:		Optional[int]							,			snake_case					:		Optional[int]							,			snake_case					:		Optional[int]=False      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Union[str, Any]  							=      copy.deepcopy(snake_case      )

          if return_labels:
               if model_class in get_values(snake_case      ):
                    __UpperCAmelCase     :			List[Any]  							=      torch.zeros(
                        self.model_tester.batch_size							,			dtype=torch.long							,			device=snake_case      )

          return inputs_dict

     def 			lowerCamelCase__			(    self					:		Optional[Any]      )						->							Union[str, Any]:
          self.config_tester.run_common_tests()

     @unittest.skip(reason='''TimeSformer does not use inputs_embeds'''      )
     def 			lowerCamelCase__			(    self					:		Any      )						->							Dict:
          pass

     def 			lowerCamelCase__			(    self					:		Optional[Any]      )						->							int:
          __UpperCAmelCase							,       __UpperCAmelCase     :			List[Any]  							=      self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __UpperCAmelCase     :			Optional[Any]  							=      model_class(snake_case      )
               self.assertIsInstance(model.get_input_embeddings()							,			(nn.Module)      )
               __UpperCAmelCase     :			Dict  							=      model.get_output_embeddings()
               self.assertTrue(x is None or isinstance(snake_case							,			nn.Linear      )      )

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							List[Any]:
          __UpperCAmelCase							,       __UpperCAmelCase     :			Union[str, Any]  							=      self.model_tester.prepare_config_and_inputs_for_common()

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

               __UpperCAmelCase     :			List[str]  							=      ['''pixel_values''']
               self.assertListEqual(arg_names[:1]							,			snake_case      )

     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							Dict:
          __UpperCAmelCase     :			List[Any]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Dict:
          __UpperCAmelCase     :			List[str]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_video_classification(*snake_case      )

     @slow
     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							str:
          for model_name in TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase     :			Optional[int]  							=      TimesformerModel.from_pretrained(snake_case      )
               self.assertIsNotNone(snake_case      )

     def 			lowerCamelCase__			(    self					:		Dict      )						->							List[Any]:
          if not self.has_attentions:
               pass

          else:
               __UpperCAmelCase							,       __UpperCAmelCase     :			List[str]  							=      self.model_tester.prepare_config_and_inputs_for_common()
               __UpperCAmelCase     :			Optional[int]  							=      True

               for model_class in self.all_model_classes:
                    __UpperCAmelCase     :			Tuple  							=      self.model_tester.seq_length
                    __UpperCAmelCase     :			int  							=      self.model_tester.num_frames

                    __UpperCAmelCase     :			Optional[int]  							=      True
                    __UpperCAmelCase     :			Any  							=      False
                    __UpperCAmelCase     :			Optional[int]  							=      True
                    __UpperCAmelCase     :			Tuple  							=      model_class(snake_case      )
                    model.to(snake_case      )
                    model.eval()
                    with torch.no_grad():
                         __UpperCAmelCase     :			int  							=      model(**self._prepare_for_class(snake_case							,			snake_case      )      )
                    __UpperCAmelCase     :			str  							=      outputs.attentions
                    self.assertEqual(len(snake_case      )							,			self.model_tester.num_hidden_layers      )

                    # check that output_attentions also work using config
                    del inputs_dict["output_attentions"]
                    __UpperCAmelCase     :			Dict  							=      True
                    __UpperCAmelCase     :			str  							=      model_class(snake_case      )
                    model.to(snake_case      )
                    model.eval()
                    with torch.no_grad():
                         __UpperCAmelCase     :			List[Any]  							=      model(**self._prepare_for_class(snake_case							,			snake_case      )      )
                    __UpperCAmelCase     :			List[Any]  							=      outputs.attentions
                    self.assertEqual(len(snake_case      )							,			self.model_tester.num_hidden_layers      )

                    # attentions has shape (batch_size x num_frames) x num_heads x (num_patches per frame + 1) x (num_patches per frame + 1)
                    self.assertListEqual(
                        list(attentions[0].shape[-3:]      )							,			[self.model_tester.num_attention_heads, seq_len // num_frames + 1, seq_len // num_frames + 1]							,			)
                    __UpperCAmelCase     :			Tuple  							=      len(snake_case      )

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

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

                    __UpperCAmelCase     :			Any  							=      outputs.attentions

                    self.assertEqual(len(snake_case      )							,			self.model_tester.num_hidden_layers      )

                    # attentions has shape (batch_size x num_frames) x num_heads x (num_patches per frame + 1) x (num_patches per frame + 1)
                    self.assertListEqual(
                        list(self_attentions[0].shape[-3:]      )							,			[self.model_tester.num_attention_heads, seq_len // num_frames + 1, seq_len // num_frames + 1]							,			)






     def 			lowerCamelCase__			(    self					:		Dict      )						->							Union[str, Any]:
          def check_hidden_states_output(snake_case					:		Optional[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		Tuple      ):
               __UpperCAmelCase     :			str  							=      model_class(snake_case      )
               model.to(snake_case      )
               model.eval()

               with torch.no_grad():
                    __UpperCAmelCase     :			Any  							=      model(**self._prepare_for_class(snake_case							,			snake_case      )      )

               __UpperCAmelCase     :			int  							=      outputs.hidden_states
               __UpperCAmelCase     :			Union[str, Any]  							=      self.model_tester.num_hidden_layers + 1
               self.assertEqual(len(snake_case      )							,			snake_case      )

               __UpperCAmelCase     :			int  							=      self.model_tester.seq_length

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

          __UpperCAmelCase							,       __UpperCAmelCase     :			str  							=      self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __UpperCAmelCase     :			str  							=      True
               check_hidden_states_output(snake_case							,			snake_case							,			snake_case      )

               # check that output_hidden_states also work using config
               del inputs_dict["output_hidden_states"]
               __UpperCAmelCase     :			str  							=      True

               check_hidden_states_output(snake_case							,			snake_case							,			snake_case      )




def      _a     (						):





     '''simple docstring'''






     __UpperCAmelCase     :			Union[str, Any]  							=      hf_hub_download(
         repo_id='''hf-internal-testing/spaghetti-video'''      , filename='''eating_spaghetti.npy'''      , repo_type='''dataset'''  )
     __UpperCAmelCase     :			int  							=      np.load(_lowercase  )
     return list(_lowercase  )



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


     """simple docstring"""






     @cached_property
     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							str:
          # logits were tested with a different mean and std, so we use the same here
          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 			lowerCamelCase__			(    self					:		str      )						->							List[Any]:
          __UpperCAmelCase     :			Union[str, Any]  							=      TimesformerForVideoClassification.from_pretrained('''facebook/timesformer-base-finetuned-k400'''      ).to(
              snake_case      )

          __UpperCAmelCase     :			str  							=      self.default_image_processor
          __UpperCAmelCase     :			Dict  							=      prepare_video()
          __UpperCAmelCase     :			Union[str, Any]  							=      image_processor(video[:8]							,			return_tensors='''pt'''      ).to(snake_case      )

          # forward pass
          with torch.no_grad():
               __UpperCAmelCase     :			List[Any]  							=      model(**snake_case      )

          # verify the logits
          __UpperCAmelCase     :			Optional[Any]  							=      torch.Size((1, 400)      )
          self.assertEqual(outputs.logits.shape							,			snake_case      )

          __UpperCAmelCase     :			List[Any]  							=      torch.tensor([-0.3_016, -0.7_713, -0.4_205]      ).to(snake_case      )

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