






"""simple docstring"""



import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, slow, torch_device

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin




class        __lowercase(       _UpperCamelCase						,							_UpperCamelCase						,							unittest.TestCase  ):
						lowerCAmelCase_		:							Optional[Any]=       UNetaDModel
						lowerCAmelCase_		:							List[str]=       """sample"""






						@property
						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											lowerCamelCase__				=4
											lowerCamelCase__				=14
											lowerCamelCase__				=16

											lowerCamelCase__				=floats_tensor((batch_size, num_features, seq_len)).to(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=torch.tensor([10] * batch_size).to(_SCREAMING_SNAKE_CASE)

											return {"sample": noise, "timestep": time_step}






						@property
						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											return (4, 14, 16)






						@property
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											return (4, 14, 16)






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




											"""simple docstring"""





											pass






						def 		lowerCAmelCase   (					self)			->  Any:




											"""simple docstring"""





											pass






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											super().test_determinism()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  int:




											"""simple docstring"""





											super().test_outputs_equivalence()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  List[Any]:




											"""simple docstring"""





											super().test_from_save_pretrained()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											super().test_from_save_pretrained_variant()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  List[Any]:




											"""simple docstring"""





											super().test_model_from_pretrained()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  List[str]:




											"""simple docstring"""





											super().test_output()






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




											"""simple docstring"""





											lowerCamelCase__				={
											    'block_out_channels': (32, 64, 1_28, 2_56),
											    'in_channels': 14,
											    'out_channels': 14,
											    'time_embedding_type': 'positional',
											    'use_timestep_embedding': True,
											    'flip_sin_to_cos': False,
											    'freq_shift': 1.0,
											    'out_block_type': 'OutConv1DBlock',
											    'mid_block_type': 'MidResTemporalBlock1D',
											    'down_block_types': ('DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D'),
											    'up_block_types': ('UpResnetBlock1D', 'UpResnetBlock1D', 'UpResnetBlock1D'),
											    'act_fn': 'mish',
											}
											lowerCamelCase__				=self.dummy_input
											return init_dict, inputs_dict






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  List[Any]:




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=UNetaDModel.from_pretrained(
											    'bglick13/hopper-medium-v2-value-function-hor32'    ,						output_loading_info=_SCREAMING_SNAKE_CASE    ,						subfolder='unet')
											self.assertIsNotNone(_SCREAMING_SNAKE_CASE)
											self.assertEqual(len(loading_info['missing_keys'])    ,						0)

											model.to(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=model(**self.dummy_input)

											assert image is not None, "Make sure output is not None"






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=UNetaDModel.from_pretrained('bglick13/hopper-medium-v2-value-function-hor32'    ,						subfolder='unet')
											torch.manual_seed(0)
											if torch.cuda.is_available():
																torch.cuda.manual_seed_all(0)

											lowerCamelCase__				=model.config.in_channels
											lowerCamelCase__				=16
											lowerCamelCase__				=torch.randn((1, seq_len, num_features)).permute(
											    0    ,						2    ,						1)  # match original, we can update values and remove
											lowerCamelCase__				=torch.full((num_features,)    ,						0)

											with torch.no_grad():
																lowerCamelCase__				=model(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE).sample.permute(0    ,						2    ,						1)

											lowerCamelCase__				=output[0, -3:, -3:].flatten()
											# fmt: off
											lowerCamelCase__				=torch.tensor([-2.137172, 1.1426016, 0.3688687, -0.766922, 0.7303146, 0.11038864, -0.4760633, 0.13270172, 0.02591348])
											# fmt: on
											self.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						rtol=1E-3))






						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											pass






						@slow
						def 		lowerCAmelCase   (					self)			->  Union[str, Any]:




											"""simple docstring"""





											lowerCamelCase__				='harmonai/maestro-150k'
											lowerCamelCase__				=UNetaDModel.from_pretrained(_SCREAMING_SNAKE_CASE    ,						subfolder='unet')
											model.to(_SCREAMING_SNAKE_CASE)

											lowerCamelCase__				=6_55_36
											lowerCamelCase__				=torch.sin(torch.arange(_SCREAMING_SNAKE_CASE)[None, None, :].repeat(1    ,						2    ,						1)).to(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=torch.tensor([1]).to(_SCREAMING_SNAKE_CASE)

											with torch.no_grad():
																lowerCamelCase__				=model(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE).sample

											lowerCamelCase__				=output.abs().sum()
											lowerCamelCase__				=output.abs().max()

											assert (output_sum - 224.0896).abs() < 0.5
											assert (output_max - 0.0607).abs() < 4E-4




class        __lowercase(       _UpperCamelCase						,							_UpperCamelCase						,							unittest.TestCase  ):
						lowerCAmelCase_		:							List[str]=       UNetaDModel
						lowerCAmelCase_		:							Union[str, Any]=       """sample"""






						@property
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=4
											lowerCamelCase__				=14
											lowerCamelCase__				=16

											lowerCamelCase__				=floats_tensor((batch_size, num_features, seq_len)).to(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=torch.tensor([10] * batch_size).to(_SCREAMING_SNAKE_CASE)

											return {"sample": noise, "timestep": time_step}






						@property
						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											return (4, 14, 16)






						@property
						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											return (4, 14, 1)






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											super().test_determinism()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  int:




											"""simple docstring"""





											super().test_outputs_equivalence()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Union[str, Any]:




											"""simple docstring"""





											super().test_from_save_pretrained()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											super().test_from_save_pretrained_variant()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Union[str, Any]:




											"""simple docstring"""





											super().test_model_from_pretrained()






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Optional[int]:




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=self.prepare_init_args_and_inputs_for_common()
											lowerCamelCase__				=self.model_class(**_SCREAMING_SNAKE_CASE)
											model.to(_SCREAMING_SNAKE_CASE)
											model.eval()

											with torch.no_grad():
																lowerCamelCase__				=model(**_SCREAMING_SNAKE_CASE)

																if isinstance(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE):
																					lowerCamelCase__				=output.sample

											self.assertIsNotNone(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=torch.Size((inputs_dict['sample'].shape[0], 1))
											self.assertEqual(output.shape    ,						_SCREAMING_SNAKE_CASE    ,						'Input and output shapes do not match')






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




											"""simple docstring"""





											pass






						def 		lowerCAmelCase   (					self)			->  int:




											"""simple docstring"""





											pass






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




											"""simple docstring"""





											lowerCamelCase__				={
											    'in_channels': 14,
											    'out_channels': 14,
											    'down_block_types': ['DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D', 'DownResnetBlock1D'],
											    'up_block_types': [],
											    'out_block_type': 'ValueFunction',
											    'mid_block_type': 'ValueFunctionMidBlock1D',
											    'block_out_channels': [32, 64, 1_28, 2_56],
											    'layers_per_block': 1,
											    'downsample_each_block': True,
											    'use_timestep_embedding': True,
											    'freq_shift': 1.0,
											    'flip_sin_to_cos': False,
											    'time_embedding_type': 'positional',
											    'act_fn': 'mish',
											}
											lowerCamelCase__				=self.dummy_input
											return init_dict, inputs_dict






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=UNetaDModel.from_pretrained(
											    'bglick13/hopper-medium-v2-value-function-hor32'    ,						output_loading_info=_SCREAMING_SNAKE_CASE    ,						subfolder='value_function')
											self.assertIsNotNone(_SCREAMING_SNAKE_CASE)
											self.assertEqual(len(vf_loading_info['missing_keys'])    ,						0)

											value_function.to(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=value_function(**self.dummy_input)

											assert image is not None, "Make sure output is not None"






						@unittest.skipIf(torch_device == 'mps'    ,						'mish op not supported in MPS')
						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=UNetaDModel.from_pretrained(
											    'bglick13/hopper-medium-v2-value-function-hor32'    ,						output_loading_info=_SCREAMING_SNAKE_CASE    ,						subfolder='value_function')
											torch.manual_seed(0)
											if torch.cuda.is_available():
																torch.cuda.manual_seed_all(0)

											lowerCamelCase__				=value_function.config.in_channels
											lowerCamelCase__				=14
											lowerCamelCase__				=torch.randn((1, seq_len, num_features)).permute(
											    0    ,						2    ,						1)  # match original, we can update values and remove
											lowerCamelCase__				=torch.full((num_features,)    ,						0)

											with torch.no_grad():
																lowerCamelCase__				=value_function(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE).sample

											# fmt: off
											lowerCamelCase__				=torch.tensor([165.25] * seq_len)
											# fmt: on
											self.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						rtol=1E-3))






						def 		lowerCAmelCase   (					self)			->  List[str]:




											"""simple docstring"""





											pass







"""simple docstring"""



import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VivitConfig
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


if is_torch_available():
						import torch
						from torch import nn

						from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VivitForVideoClassification, VivitModel
						from transformers.models.vivit.modeling_vivit import VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from transformers import VivitImageProcessor




class        __lowercase:






						def __init__(					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE=2    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=10    ,						_SCREAMING_SNAKE_CASE=10    ,						_SCREAMING_SNAKE_CASE=8    ,						_SCREAMING_SNAKE_CASE=[2, 4, 4]    ,						_SCREAMING_SNAKE_CASE=3    ,						_SCREAMING_SNAKE_CASE=7_68    ,						_SCREAMING_SNAKE_CASE=5    ,						_SCREAMING_SNAKE_CASE=4    ,						_SCREAMING_SNAKE_CASE=37    ,						_SCREAMING_SNAKE_CASE="gelu_fast"    ,						_SCREAMING_SNAKE_CASE=0.0    ,						_SCREAMING_SNAKE_CASE=0.0    ,						_SCREAMING_SNAKE_CASE=0.02    ,						_SCREAMING_SNAKE_CASE=1E-06    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=None    ,						)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				=parent
											lowerCamelCase__				=batch_size
											lowerCamelCase__				=is_training
											lowerCamelCase__				=use_labels
											lowerCamelCase__				=num_labels
											lowerCamelCase__				=image_size
											lowerCamelCase__				=num_frames
											lowerCamelCase__				=tubelet_size
											lowerCamelCase__				=num_channels
											lowerCamelCase__				=hidden_size
											lowerCamelCase__				=num_hidden_layers
											lowerCamelCase__				=num_attention_heads
											lowerCamelCase__				=intermediate_size
											lowerCamelCase__				=hidden_act
											lowerCamelCase__				=hidden_dropout_prob
											lowerCamelCase__				=attention_probs_dropout_prob
											lowerCamelCase__				=initializer_range
											lowerCamelCase__				=layer_norm_eps
											lowerCamelCase__				=qkv_bias
											lowerCamelCase__				=scope

											lowerCamelCase__				=(
											    (self.image_size // self.tubelet_size[2])
											    * (self.image_size // self.tubelet_size[1])
											    * (self.num_frames // self.tubelet_size[0])
											) + 1  # CLS token






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




											"""simple docstring"""





											lowerCamelCase__				=floats_tensor(
											    [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size])

											lowerCamelCase__				=None
											if self.use_labels:
																lowerCamelCase__				=ids_tensor([self.batch_size]    ,						self.num_labels)

											lowerCamelCase__				=self.get_config()

											return config, pixel_values, labels






						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				=VivitConfig(
											    num_frames=self.num_frames    ,						image_size=self.image_size    ,						tubelet_size=self.tubelet_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    ,						layer_norm_eps=self.layer_norm_eps    ,						qkv_bias=self.qkv_bias    ,						)
											lowerCamelCase__				=self.num_labels
											return config






						def 		lowerCAmelCase   (					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)			->  int:




											"""simple docstring"""





											lowerCamelCase__				=VivitModel(config=_SCREAMING_SNAKE_CASE)
											model.to(_SCREAMING_SNAKE_CASE)
											model.eval()
											lowerCamelCase__				=model(_SCREAMING_SNAKE_CASE)
											self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, self.seq_length, self.hidden_size))






						def 		lowerCAmelCase   (					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=VivitForVideoClassification(_SCREAMING_SNAKE_CASE)
											model.to(_SCREAMING_SNAKE_CASE)
											model.eval()

											lowerCamelCase__				=model(_SCREAMING_SNAKE_CASE)

											# verify the logits shape
											lowerCamelCase__				=torch.Size((self.batch_size, self.num_labels))
											self.parent.assertEqual(result.logits.shape    ,						_SCREAMING_SNAKE_CASE)






						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				=self.prepare_config_and_inputs()
											lowerCamelCase__				,     lowerCamelCase__				,     lowerCamelCase__				=config_and_inputs
											lowerCamelCase__				={'pixel_values': pixel_values}
											return config, inputs_dict




@require_torch
class        __lowercase(       _UpperCamelCase						,							unittest.TestCase  ):
						lowerCAmelCase_		:							str=       (VivitModel, VivitForVideoClassification) if is_torch_available() else ()

						lowerCAmelCase_		:							str=       False
						lowerCAmelCase_		:							Tuple=       False
						lowerCAmelCase_		:							Union[str, Any]=       False
						lowerCAmelCase_		:							Dict=       False






						def 		lowerCAmelCase   (					self)			->  List[str]:




											"""simple docstring"""





											lowerCamelCase__				=VivitModelTester(self)
											lowerCamelCase__				=ConfigTester(self    ,						config_class=_SCREAMING_SNAKE_CASE    ,						has_text_modality=_SCREAMING_SNAKE_CASE    ,						hidden_size=37)






						def 		lowerCAmelCase   (					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE=False)			->  Optional[int]:




											"""simple docstring"""





											lowerCamelCase__				=copy.deepcopy(_SCREAMING_SNAKE_CASE)

											if return_labels:
																if model_class in get_values(_SCREAMING_SNAKE_CASE):
																					lowerCamelCase__				=torch.zeros(
																					    self.model_tester.batch_size    ,						dtype=torch.long    ,						device=_SCREAMING_SNAKE_CASE)

											return inputs_dict






						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											self.config_tester.run_common_tests()






						@unittest.skip(reason='Vivit does not use inputs_embeds')
						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											pass






						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=self.model_tester.prepare_config_and_inputs_for_common()

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






						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=self.model_tester.prepare_config_and_inputs_for_common()

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

																lowerCamelCase__				=['pixel_values', 'head_mask']
																self.assertListEqual(arg_names[:2]    ,						_SCREAMING_SNAKE_CASE)






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




											"""simple docstring"""





											lowerCamelCase__				=self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE)






						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_video_classification(*_SCREAMING_SNAKE_CASE)






						@slow
						def 		lowerCAmelCase   (					self)			->  Tuple:




											"""simple docstring"""





											for model_name in VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																lowerCamelCase__				=VivitModel.from_pretrained(_SCREAMING_SNAKE_CASE)
																self.assertIsNotNone(_SCREAMING_SNAKE_CASE)






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




											"""simple docstring"""





											lowerCamelCase__				,     lowerCamelCase__				=self.model_tester.prepare_config_and_inputs_for_common()
											lowerCamelCase__				=True

											for model_class in self.all_model_classes:
																lowerCamelCase__				=self.model_tester.seq_length

																lowerCamelCase__				=True
																lowerCamelCase__				=False
																lowerCamelCase__				=True
																lowerCamelCase__				=model_class(_SCREAMING_SNAKE_CASE)
																model.to(_SCREAMING_SNAKE_CASE)
																model.eval()
																with torch.no_grad():
																					lowerCamelCase__				=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE))
																lowerCamelCase__				=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"]
																lowerCamelCase__				=True
																lowerCamelCase__				=model_class(_SCREAMING_SNAKE_CASE)
																model.to(_SCREAMING_SNAKE_CASE)
																model.eval()
																with torch.no_grad():
																					lowerCamelCase__				=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE))
																lowerCamelCase__				=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]    ,						)
																lowerCamelCase__				=len(_SCREAMING_SNAKE_CASE)

																# Check attention is always last and order is fine
																lowerCamelCase__				=True
																lowerCamelCase__				=True
																lowerCamelCase__				=model_class(_SCREAMING_SNAKE_CASE)
																model.to(_SCREAMING_SNAKE_CASE)
																model.eval()
																with torch.no_grad():
																					lowerCamelCase__				=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE))

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

																lowerCamelCase__				=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 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											def check_hidden_states_output(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE):
																lowerCamelCase__				=model_class(_SCREAMING_SNAKE_CASE)
																model.to(_SCREAMING_SNAKE_CASE)
																model.eval()

																with torch.no_grad():
																					lowerCamelCase__				=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE))

																lowerCamelCase__				=outputs.hidden_states
																lowerCamelCase__				=self.model_tester.num_hidden_layers + 1
																self.assertEqual(len(_SCREAMING_SNAKE_CASE)    ,						_SCREAMING_SNAKE_CASE)

																lowerCamelCase__				=self.model_tester.seq_length

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

											lowerCamelCase__				,     lowerCamelCase__				=self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																lowerCamelCase__				=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"]
																lowerCamelCase__				=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 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											pass




def 						lowerCamelCase_				(  ):
					lowerCamelCase__				=hf_hub_download(
					    repo_id='hf-internal-testing/spaghetti-video'			,	filename='eating_spaghetti_32_frames.npy'			,	repo_type='dataset'			)
					lowerCamelCase__				=np.load(__A			)
					return list(__A			)




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






						@cached_property
						def 		lowerCAmelCase   (					self)			->  Union[str, Any]:




											"""simple docstring"""





											return VivitImageProcessor() if is_vision_available() else None






						@slow
						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=VivitForVideoClassification.from_pretrained('google/vivit-b-16x2-kinetics400').to(_SCREAMING_SNAKE_CASE)

											lowerCamelCase__				=self.default_image_processor
											lowerCamelCase__				=prepare_video()
											lowerCamelCase__				=image_processor(_SCREAMING_SNAKE_CASE    ,						return_tensors='pt').to(_SCREAMING_SNAKE_CASE)

											# forward pass
											with torch.no_grad():
																lowerCamelCase__				=model(**_SCREAMING_SNAKE_CASE)

											# verify the logits
											lowerCamelCase__				=torch.Size((1, 4_00))
											self.assertEqual(outputs.logits.shape    ,						_SCREAMING_SNAKE_CASE)

											# taken from original model
											lowerCamelCase__				=torch.tensor([-1.0543, 2.0764, -0.2104, 0.4439, -0.9658]).to(_SCREAMING_SNAKE_CASE)

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