"""simple docstring"""






import tempfile
import unittest

import numpy as np

import transformers
from transformers import GPTaConfig, GPTaTokenizer, is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
       import jax
       import jax.numpy as jnp

       from transformers.modeling_flax_pytorch_utils import (
           convert_pytorch_state_dict_to_flax,
           load_flax_weights_in_pytorch_model,
       )
       from transformers.models.gpta.modeling_flax_gpta import FlaxGPTaLMHeadModel, FlaxGPTaModel

if is_torch_available():
       import torch


class 					UpperCAmelCase		:



    """simple docstring"""

    def __init__(     self					,    _UpperCAmelCase					,    _UpperCAmelCase=14					,    _UpperCAmelCase=7					,    _UpperCAmelCase=True					,    _UpperCAmelCase=True					,    _UpperCAmelCase=False					,    _UpperCAmelCase=True					,    _UpperCAmelCase=99					,    _UpperCAmelCase=32					,    _UpperCAmelCase=5					,    _UpperCAmelCase=4					,    _UpperCAmelCase=37					,    _UpperCAmelCase="gelu"					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=512					,    _UpperCAmelCase=0.02					,    ):
       lowercase__:     Tuple      =   parent
       lowercase__:     Any      =   batch_size
       lowercase__:     Any      =   seq_length
       lowercase__:     List[Any]      =   is_training
       lowercase__:     str      =   use_input_mask
       lowercase__:     Optional[Any]      =   use_token_type_ids
       lowercase__:     Any      =   use_labels
       lowercase__:     List[Any]      =   vocab_size
       lowercase__:     Tuple      =   hidden_size
       lowercase__:     Union[str, Any]      =   num_hidden_layers
       lowercase__:     str      =   num_attention_heads
       lowercase__:     Optional[Any]      =   intermediate_size
       lowercase__:     List[Any]      =   hidden_act
       lowercase__:     Union[str, Any]      =   hidden_dropout_prob
       lowercase__:     Dict      =   attention_probs_dropout_prob
       lowercase__:     str      =   max_position_embeddings
       lowercase__:     Optional[Any]      =   initializer_range
       lowercase__:     Any      =   None
       lowercase__:     int      =   vocab_size - 1
       lowercase__:     int      =   vocab_size - 1
       lowercase__:     Union[str, Any]      =   vocab_size - 1






    def _snake_case    (     self							):
       lowercase__:     Optional[int]      =   ids_tensor([self.batch_size, self.seq_length]					,    self.vocab_size							)

       lowercase__:     Dict      =   None
       if self.use_input_mask:
          lowercase__:     int      =   random_attention_mask([self.batch_size, self.seq_length]							)

       lowercase__:     int      =   GPTaConfig(
           vocab_size=self.vocab_size					,    n_embd=self.hidden_size					,    n_layer=self.num_hidden_layers					,    n_head=self.num_attention_heads					,    n_positions=self.max_position_embeddings					,    use_cache=_UpperCAmelCase					,    bos_token_id=self.bos_token_id					,    eos_token_id=self.eos_token_id					,    pad_token_id=self.pad_token_id					,    )

       return (config, input_ids, input_mask)






    def _snake_case    (     self							):
       lowercase__:     Optional[Any]      =   self.prepare_config_and_inputs()
       lowercase__,				lowercase__,				lowercase__:     Tuple      =   config_and_inputs
       lowercase__:     Dict      =   {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
       return config, inputs_dict






    def _snake_case    (     self							):
       lowercase__,				lowercase__,				lowercase__:     Dict      =   self.prepare_config_and_inputs()

       lowercase__:     List[str]      =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
       lowercase__:     List[Any]      =   ids_tensor([self.batch_size, self.seq_length]					,    vocab_size=2							)

       return (
           config,
           input_ids,
           attention_mask,
           encoder_hidden_states,
           encoder_attention_mask,
       )






    def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							):
       lowercase__:     List[Any]      =   20
       lowercase__:     Optional[int]      =   model_class_name(_UpperCAmelCase							)

       lowercase__:     Optional[Any]      =   model.init_cache(input_ids.shape[0]					,    _UpperCAmelCase							)
       lowercase__:     Tuple      =   jnp.ones((input_ids.shape[0], max_decoder_length)					,    dtype='''i4'''							)

       lowercase__:     Any      =   jnp.broadcast_to(
           jnp.arange(input_ids.shape[-1] - 1							)[None, :]					,    (input_ids.shape[0], input_ids.shape[-1] - 1)							)
       lowercase__:     List[str]      =   model(
           input_ids[:, :-1]					,    attention_mask=_UpperCAmelCase					,    past_key_values=_UpperCAmelCase					,    position_ids=_UpperCAmelCase					,    )

       lowercase__:     int      =   jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]					,    dtype='''i4'''							)
       lowercase__:     Optional[Any]      =   model(
           input_ids[:, -1:]					,    attention_mask=_UpperCAmelCase					,    past_key_values=outputs_cache.past_key_values					,    position_ids=_UpperCAmelCase					,    )

       lowercase__:     List[Any]      =   model(_UpperCAmelCase							)

       lowercase__:     Tuple      =   np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])							)							)
       self.parent.assertTrue(diff < 1e-3					,    msg=F"""Max diff is {diff}"""							)






    def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							):
       lowercase__:     Dict      =   20
       lowercase__:     Dict      =   model_class_name(_UpperCAmelCase							)

       lowercase__:     str      =   jnp.concatenate(
           [attention_mask, jnp.zeros((attention_mask.shape[0], max_decoder_length - attention_mask.shape[1])							)]					,    axis=-1					,    )

       lowercase__:     int      =   model.init_cache(input_ids.shape[0]					,    _UpperCAmelCase							)
       lowercase__:     Any      =   jnp.broadcast_to(
           jnp.arange(input_ids.shape[-1] - 1							)[None, :]					,    (input_ids.shape[0], input_ids.shape[-1] - 1)							)

       lowercase__:     List[Any]      =   model(
           input_ids[:, :-1]					,    attention_mask=_UpperCAmelCase					,    past_key_values=_UpperCAmelCase					,    position_ids=_UpperCAmelCase					,    )
       lowercase__:     Any      =   jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]					,    dtype='''i4'''							)
       lowercase__:     Optional[Any]      =   model(
           input_ids[:, -1:]					,    past_key_values=outputs_cache.past_key_values					,    attention_mask=_UpperCAmelCase					,    position_ids=_UpperCAmelCase					,    )

       lowercase__:     Tuple      =   model(_UpperCAmelCase					,    attention_mask=_UpperCAmelCase							)

       lowercase__:     str      =   np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])							)							)
       self.parent.assertTrue(diff < 1e-3					,    msg=F"""Max diff is {diff}"""							)



@require_flax
class 					UpperCAmelCase		(_UpperCAmelCase					,_UpperCAmelCase					,unittest.TestCase						):



    """simple docstring"""

    _UpperCAmelCase			:List[str]							=				(FlaxGPTaModel, FlaxGPTaLMHeadModel) if is_flax_available() else ()
    _UpperCAmelCase			:Tuple							=				(FlaxGPTaLMHeadModel,) if is_flax_available() else ()






    def _snake_case    (     self							):
       lowercase__:     str      =   FlaxGPTaModelTester(self							)






    def _snake_case    (     self							):
       for model_class_name in self.all_model_classes:
          lowercase__,				lowercase__,				lowercase__:     List[str]      =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.check_use_cache_forward(_UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							)






    def _snake_case    (     self							):
       for model_class_name in self.all_model_classes:
          lowercase__,				lowercase__,				lowercase__:     Any      =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.check_use_cache_forward_with_attn_mask(
              _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							)






    @slow
    def _snake_case    (     self							):
       lowercase__:     str      =   GPTaTokenizer.from_pretrained('''gpt2'''					,    pad_token='''</s>'''					,    padding_side='''left'''							)
       lowercase__:     Union[str, Any]      =   tokenizer(['''Hello this is a long string''', '''Hey''']					,    return_tensors='''np'''					,    padding=_UpperCAmelCase					,    truncation=_UpperCAmelCase							)

       lowercase__:     Any      =   FlaxGPTaLMHeadModel.from_pretrained('''gpt2'''							)
       lowercase__:     List[str]      =   False
       lowercase__:     str      =   model.config.eos_token_id

       lowercase__:     int      =   jax.jit(model.generate							)

       lowercase__:     str      =   jit_generate(inputs['''input_ids''']					,    attention_mask=inputs['''attention_mask''']							).sequences

       lowercase__:     List[Any]      =   tokenizer.batch_decode(_UpperCAmelCase					,    skip_special_tokens=_UpperCAmelCase							)

       lowercase__:     Optional[int]      =   [
           '''Hello this is a long string of words. I\'m going to start with the first one.\n''',
           '''Hey, I\'m not sure if I\'m going to be able to do''',
       ]

       self.assertListEqual(_UpperCAmelCase					,    _UpperCAmelCase							)






    @is_pt_flax_cross_test
    def _snake_case    (     self							):
       lowercase__,				lowercase__:     Optional[int]      =   self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
          with self.subTest(model_class.__name__							):
             # prepare inputs
             lowercase__:     Tuple      =   self._prepare_for_class(_UpperCAmelCase					,    _UpperCAmelCase							)
             lowercase__:     Optional[int]      =   {k: torch.tensor(v.tolist()							) for k, v in prepared_inputs_dict.items()}

             # load corresponding PyTorch class
             lowercase__:     Optional[Any]      =   model_class.__name__[4:]  # Skip the "Flax" at the beginning
             lowercase__:     Dict      =   getattr(_UpperCAmelCase					,    _UpperCAmelCase							)

             lowercase__,				lowercase__:     Union[str, Any]      =   pt_inputs['''input_ids'''].shape
             lowercase__:     Union[str, Any]      =   np.random.randint(0					,    seq_length - 1					,    size=(batch_size,)							)
             for batch_idx, start_index in enumerate(_UpperCAmelCase							):
                lowercase__:     Union[str, Any]      =   0
                lowercase__:     Optional[int]      =   1
                lowercase__:     List[Any]      =   0
                lowercase__:     int      =   1
             lowercase__:     Dict      =   pt_model_class(_UpperCAmelCase							).eval()
             lowercase__:     Dict      =   model_class(_UpperCAmelCase					,    dtype=jnp.floataa							)

             lowercase__:     Optional[Any]      =   convert_pytorch_state_dict_to_flax(pt_model.state_dict()					,    _UpperCAmelCase							)
             lowercase__:     List[Any]      =   fx_state

             with torch.no_grad():
                lowercase__:     Optional[int]      =   pt_model(**_UpperCAmelCase							).to_tuple()

             lowercase__:     str      =   fx_model(**_UpperCAmelCase							).to_tuple()
             self.assertEqual(len(_UpperCAmelCase							)					,    len(_UpperCAmelCase							)					,    '''Output lengths differ between Flax and PyTorch'''							)
             for fx_output, pt_output in zip(_UpperCAmelCase					,    _UpperCAmelCase							):
                self.assert_almost_equals(fx_output[:, -1]					,    pt_output[:, -1].numpy()					,    4e-2							)

             with tempfile.TemporaryDirectory() as tmpdirname:
                pt_model.save_pretrained(_UpperCAmelCase							)
                lowercase__:     int      =   model_class.from_pretrained(_UpperCAmelCase					,    from_pt=_UpperCAmelCase							)

             lowercase__:     Optional[int]      =   fx_model_loaded(**_UpperCAmelCase							).to_tuple()
             self.assertEqual(
                 len(_UpperCAmelCase							)					,    len(_UpperCAmelCase							)					,    '''Output lengths differ between Flax and PyTorch'''							)
             for fx_output_loaded, pt_output in zip(_UpperCAmelCase					,    _UpperCAmelCase							):
                self.assert_almost_equals(fx_output_loaded[:, -1]					,    pt_output[:, -1].numpy()					,    4e-2							)






    @is_pt_flax_cross_test
    def _snake_case    (     self							):
       lowercase__,				lowercase__:     Tuple      =   self.model_tester.prepare_config_and_inputs_for_common()
       for model_class in self.all_model_classes:
          with self.subTest(model_class.__name__							):
             # prepare inputs
             lowercase__:     List[Any]      =   self._prepare_for_class(_UpperCAmelCase					,    _UpperCAmelCase							)
             lowercase__:     Optional[int]      =   {k: torch.tensor(v.tolist()							) for k, v in prepared_inputs_dict.items()}

             # load corresponding PyTorch class
             lowercase__:     Any      =   model_class.__name__[4:]  # Skip the "Flax" at the beginning
             lowercase__:     int      =   getattr(_UpperCAmelCase					,    _UpperCAmelCase							)

             lowercase__:     Optional[int]      =   pt_model_class(_UpperCAmelCase							).eval()
             lowercase__:     str      =   model_class(_UpperCAmelCase					,    dtype=jnp.floataa							)

             lowercase__:     Tuple      =   load_flax_weights_in_pytorch_model(_UpperCAmelCase					,    fx_model.params							)
             lowercase__,				lowercase__:     Optional[Any]      =   pt_inputs['''input_ids'''].shape
             lowercase__:     Tuple      =   np.random.randint(0					,    seq_length - 1					,    size=(batch_size,)							)
             for batch_idx, start_index in enumerate(_UpperCAmelCase							):
                lowercase__:     List[Any]      =   0
                lowercase__:     List[Any]      =   1
                lowercase__:     Dict      =   0
                lowercase__:     List[str]      =   1

             # make sure weights are tied in PyTorch
             pt_model.tie_weights()

             with torch.no_grad():
                lowercase__:     int      =   pt_model(**_UpperCAmelCase							).to_tuple()

             lowercase__:     str      =   fx_model(**_UpperCAmelCase							).to_tuple()
             self.assertEqual(len(_UpperCAmelCase							)					,    len(_UpperCAmelCase							)					,    '''Output lengths differ between Flax and PyTorch'''							)
             for fx_output, pt_output in zip(_UpperCAmelCase					,    _UpperCAmelCase							):
                self.assert_almost_equals(fx_output[:, -1]					,    pt_output[:, -1].numpy()					,    4e-2							)

             with tempfile.TemporaryDirectory() as tmpdirname:
                fx_model.save_pretrained(_UpperCAmelCase							)
                lowercase__:     Optional[int]      =   pt_model_class.from_pretrained(_UpperCAmelCase					,    from_flax=_UpperCAmelCase							)

             with torch.no_grad():
                lowercase__:     List[str]      =   pt_model_loaded(**_UpperCAmelCase							).to_tuple()

             self.assertEqual(
                 len(_UpperCAmelCase							)					,    len(_UpperCAmelCase							)					,    '''Output lengths differ between Flax and PyTorch'''							)
             for fx_output, pt_output in zip(_UpperCAmelCase					,    _UpperCAmelCase							):
                self.assert_almost_equals(fx_output[:, -1]					,    pt_output[:, -1].numpy()					,    4e-2							)






    @slow
    def _snake_case    (     self							):
       for model_class_name in self.all_model_classes:
          lowercase__:     Tuple      =   model_class_name.from_pretrained('''gpt2'''					,    from_pt=_UpperCAmelCase							)
          lowercase__:     Optional[Any]      =   model(np.ones((1, 1)							)							)
          self.assertIsNotNone(_UpperCAmelCase							)

"""simple docstring"""






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import TvltImageProcessor



def SCREAMING_SNAKE_CASE__    (     __UpperCAmelCase ,					__UpperCAmelCase=1_0 ,					__UpperCAmelCase=1_0 ,					__UpperCAmelCase=False ,					__UpperCAmelCase=False				)						->						List[str]:
   lowercase__:     List[Any]      =   []
   for i in range(image_processor_tester.num_frames				):
      video.append(np.random.randint(2_5_5 ,					size=(image_processor_tester.num_channels, width, height) ,					dtype=np.uinta				)				)

   if not numpify and not torchify:
      # PIL expects the channel dimension as last dimension
      lowercase__:     Union[str, Any]      =   [Image.fromarray(np.moveaxis(__UpperCAmelCase ,					0 ,					-1				)				) for frame in video]

   if torchify:
      lowercase__:     List[str]      =   [torch.from_numpy(__UpperCAmelCase				) for frame in video]

   return video



def SCREAMING_SNAKE_CASE__    (     __UpperCAmelCase ,					__UpperCAmelCase=False ,					__UpperCAmelCase=False ,					__UpperCAmelCase=False				)						->						Tuple:
   assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

   lowercase__:     int      =   []
   for i in range(image_processor_tester.batch_size				):
      if equal_resolution:
         lowercase__:     Any      =   image_processor_tester.max_resolution
      else:
         lowercase__,				lowercase__:     Union[str, Any]      =   np.random.choice(
             np.arange(image_processor_tester.min_resolution ,					image_processor_tester.max_resolution				) ,					2				)
         lowercase__:     str      =   prepare_video(
             image_processor_tester=__UpperCAmelCase ,					width=__UpperCAmelCase ,					height=__UpperCAmelCase ,					numpify=__UpperCAmelCase ,					torchify=__UpperCAmelCase ,					)
      video_inputs.append(__UpperCAmelCase				)

   return video_inputs


class 					UpperCAmelCase		(unittest.TestCase						):



    """simple docstring"""

    def __init__(     self					,    _UpperCAmelCase					,    _UpperCAmelCase=7					,    _UpperCAmelCase=3					,    _UpperCAmelCase=4					,    _UpperCAmelCase=18					,    _UpperCAmelCase=30					,    _UpperCAmelCase=400					,    _UpperCAmelCase=True					,    _UpperCAmelCase=None					,    _UpperCAmelCase=True					,    _UpperCAmelCase=[0.5, 0.5, 0.5]					,    _UpperCAmelCase=[0.5, 0.5, 0.5]					,    _UpperCAmelCase=True					,    _UpperCAmelCase=None					,    ):
       lowercase__:     Any      =   size if size is not None else {'''shortest_edge''': 18}
       lowercase__:     List[Any]      =   crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

       lowercase__:     List[Any]      =   parent
       lowercase__:     List[str]      =   batch_size
       lowercase__:     Union[str, Any]      =   num_channels
       lowercase__:     List[Any]      =   num_frames
       lowercase__:     Tuple      =   image_size
       lowercase__:     List[Any]      =   min_resolution
       lowercase__:     Union[str, Any]      =   max_resolution
       lowercase__:     Dict      =   do_resize
       lowercase__:     List[Any]      =   size
       lowercase__:     str      =   do_normalize
       lowercase__:     int      =   image_mean
       lowercase__:     Any      =   image_std
       lowercase__:     List[Any]      =   do_center_crop
       lowercase__:     Optional[int]      =   crop_size






    def _snake_case    (     self							):
       return {
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_normalize": self.do_normalize,
           "do_resize": self.do_resize,
           "size": self.size,
           "do_center_crop": self.do_center_crop,
           "crop_size": self.crop_size,
       }



@require_torch
@require_vision
class 					UpperCAmelCase		(_UpperCAmelCase					,unittest.TestCase						):



    """simple docstring"""

    _UpperCAmelCase			:str							=				TvltImageProcessor if is_vision_available() else None






    def _snake_case    (     self							):
       lowercase__:     List[Any]      =   TvltImageProcessorTester(self							)






    @property
    def _snake_case    (     self							):
       return self.image_processor_tester.prepare_image_processor_dict()






    def _snake_case    (     self							):
       lowercase__:     List[str]      =   self.image_processing_class(**self.image_processor_dict							)
       self.assertTrue(hasattr(_UpperCAmelCase					,    '''image_mean'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase					,    '''image_std'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase					,    '''do_normalize'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase					,    '''do_resize'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase					,    '''do_center_crop'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase					,    '''size'''							)							)






    def _snake_case    (     self							):
       # Initialize image_processor
       lowercase__:     List[str]      =   self.image_processing_class(**self.image_processor_dict							)
       # create random PIL videos
       lowercase__:     str      =   prepare_video_inputs(self.image_processor_tester					,    equal_resolution=_UpperCAmelCase							)
       for video in video_inputs:
          self.assertIsInstance(_UpperCAmelCase					,    _UpperCAmelCase							)
          self.assertIsInstance(video[0]					,    Image.Image							)

       # Test not batched input
       lowercase__:     Union[str, Any]      =   image_processor(video_inputs[0]					,    return_tensors='''pt'''							).pixel_values
       self.assertEqual(
           encoded_videos.shape					,    (
               1,
               self.image_processor_tester.num_frames,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )					,    )

       # Test batched
       lowercase__:     Tuple      =   image_processor(_UpperCAmelCase					,    return_tensors='''pt'''							).pixel_values
       self.assertEqual(
           encoded_videos.shape					,    (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_frames,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )					,    )






    def _snake_case    (     self							):
       # Initialize image_processor
       lowercase__:     str      =   self.image_processing_class(**self.image_processor_dict							)
       # create random numpy tensors
       lowercase__:     List[str]      =   prepare_video_inputs(self.image_processor_tester					,    equal_resolution=_UpperCAmelCase					,    numpify=_UpperCAmelCase							)
       for video in video_inputs:
          self.assertIsInstance(_UpperCAmelCase					,    _UpperCAmelCase							)
          self.assertIsInstance(video[0]					,    np.ndarray							)

       # Test not batched input
       lowercase__:     Optional[Any]      =   image_processor(video_inputs[0]					,    return_tensors='''pt'''							).pixel_values
       self.assertEqual(
           encoded_videos.shape					,    (
               1,
               self.image_processor_tester.num_frames,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )					,    )

       # Test batched
       lowercase__:     Tuple      =   image_processor(_UpperCAmelCase					,    return_tensors='''pt'''							).pixel_values
       self.assertEqual(
           encoded_videos.shape					,    (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_frames,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )					,    )






    def _snake_case    (     self							):
       # Initialize image_processor
       lowercase__:     List[Any]      =   self.image_processing_class(**self.image_processor_dict							)
       # create random PyTorch tensors
       lowercase__:     Optional[int]      =   prepare_video_inputs(self.image_processor_tester					,    equal_resolution=_UpperCAmelCase					,    torchify=_UpperCAmelCase							)
       for video in video_inputs:
          self.assertIsInstance(_UpperCAmelCase					,    _UpperCAmelCase							)
          self.assertIsInstance(video[0]					,    torch.Tensor							)

       # Test not batched input
       lowercase__:     Optional[Any]      =   image_processor(video_inputs[0]					,    return_tensors='''pt'''							).pixel_values
       self.assertEqual(
           encoded_videos.shape					,    (
               1,
               self.image_processor_tester.num_frames,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )					,    )

       # Test batched
       lowercase__:     List[Any]      =   image_processor(_UpperCAmelCase					,    return_tensors='''pt'''							).pixel_values
       self.assertEqual(
           encoded_videos.shape					,    (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_frames,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           )					,    )
