



'''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 	lowerCamelCase_							:







      def __init__(  self   :      Dict				,    lowerCAmelCase__   :      Tuple				,    lowerCAmelCase__   :      Union[str, Any]=13				,    lowerCAmelCase__   :      Any=10				,    lowerCAmelCase__   :      Tuple=3				,    lowerCAmelCase__   :      str=2				,    lowerCAmelCase__   :      Any=2				,    lowerCAmelCase__   :      Any=True				,    lowerCAmelCase__   :      List[str]=True				,    lowerCAmelCase__   :      Any=32				,    lowerCAmelCase__   :      Dict=5				,    lowerCAmelCase__   :      Any=4				,    lowerCAmelCase__   :      Any=37				,    lowerCAmelCase__   :      Optional[Any]="gelu"				,    lowerCAmelCase__   :      Optional[int]=0.1				,    lowerCAmelCase__   :      Tuple=0.1				,    lowerCAmelCase__   :      Union[str, Any]=10				,    lowerCAmelCase__   :      Union[str, Any]=0.02				,    lowerCAmelCase__   :      Any="divided_space_time"				,    lowerCAmelCase__   :      Union[str, Any]=None				,    ):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      List[str]     					=			parent
             SCREAMING_SNAKE_CASE					:      int     					=			batch_size
             SCREAMING_SNAKE_CASE					:      Optional[int]     					=			image_size
             SCREAMING_SNAKE_CASE					:      int     					=			num_channels
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			patch_size
             SCREAMING_SNAKE_CASE					:      Dict     					=			num_frames
             SCREAMING_SNAKE_CASE					:      Tuple     					=			is_training
             SCREAMING_SNAKE_CASE					:      str     					=			use_labels
             SCREAMING_SNAKE_CASE					:      str     					=			hidden_size
             SCREAMING_SNAKE_CASE					:      Dict     					=			num_hidden_layers
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			num_attention_heads
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			intermediate_size
             SCREAMING_SNAKE_CASE					:      List[str]     					=			hidden_act
             SCREAMING_SNAKE_CASE					:      int     					=			hidden_dropout_prob
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			attention_probs_dropout_prob
             SCREAMING_SNAKE_CASE					:      Optional[int]     					=			attention_type
             SCREAMING_SNAKE_CASE					:      Any     					=			initializer_range
             SCREAMING_SNAKE_CASE					:      str     					=			scope
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			num_labels

             # in TimeSformer, the number of spatial tokens equals num_frames * num_patches per frame + 1 CLS token
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			(image_size // patch_size) ** 2
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			(num_frames) * self.num_patches_per_frame + 1







      def 					__lowercase    (  self   :      str				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			floats_tensor(
                 [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]				)

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

             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.get_config()

             return config, pixel_values, labels







      def 					__lowercase    (  self   :      List[Any]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Tuple     					=			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				,    )
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.num_labels
             return config







      def 					__lowercase    (  self   :      List[Any]				,    lowerCAmelCase__   :      Any				,    lowerCAmelCase__   :      Optional[int]				,    lowerCAmelCase__   :      Optional[int]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			TimesformerModel(config=__lowerCAmelCase				)
             model.to(__lowerCAmelCase				)
             model.eval()
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			model(__lowerCAmelCase				)
             self.parent.assertEqual(result.last_hidden_state.shape				,    (self.batch_size, self.seq_length, self.hidden_size)				)







      def 					__lowercase    (  self   :      str				,    lowerCAmelCase__   :      Optional[Any]				,    lowerCAmelCase__   :      Any				,    lowerCAmelCase__   :      Optional[int]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      int     					=			TimesformerForVideoClassification(__lowerCAmelCase				)
             model.to(__lowerCAmelCase				)
             model.eval()

             SCREAMING_SNAKE_CASE					:      Tuple     					=			model(__lowerCAmelCase				)

             # verify the logits shape
             SCREAMING_SNAKE_CASE					:      Optional[int]     					=			torch.Size((self.batch_size, self.num_labels)				)
             self.parent.assertEqual(result.logits.shape				,    __lowerCAmelCase				)







      def 					__lowercase    (  self   :      str				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      int     					=			self.prepare_config_and_inputs()
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			config_and_inputs
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			{'''pixel_values''': pixel_values}
             return config, inputs_dict


@require_torch
class 	lowerCamelCase_							(					UpperCAmelCase__    ,				UpperCAmelCase__    ,				unittest.TestCase			):
      _lowerCAmelCase     :   Optional[int]	     =				(TimesformerModel, TimesformerForVideoClassification) if is_torch_available() else ()
      _lowerCAmelCase     :   Optional[int]	     =				(
          {'feature-extraction': TimesformerModel, 'video-classification': TimesformerForVideoClassification}
          if is_torch_available()
          else {}
      )

      _lowerCAmelCase     :   str	     =				False
      _lowerCAmelCase     :   Any	     =				False
      _lowerCAmelCase     :   Union[str, Any]	     =				False
      _lowerCAmelCase     :   List[Any]	     =				False







      def 					__lowercase    (  self   :      Optional[int]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      str     					=			TimesformerModelTester(self				)
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			ConfigTester(
                 self				,    config_class=__lowerCAmelCase				,    has_text_modality=__lowerCAmelCase				,    hidden_size=37				)







      def 					__lowercase    (  self   :      Tuple				,    lowerCAmelCase__   :      Any				,    lowerCAmelCase__   :      List[Any]				,    lowerCAmelCase__   :      Union[str, Any]=False				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Dict     					=			copy.deepcopy(__lowerCAmelCase				)

             if return_labels:
                    if model_class in get_values(__lowerCAmelCase				):
                           SCREAMING_SNAKE_CASE					:      Any     					=			torch.zeros(
                               self.model_tester.batch_size				,    dtype=torch.long				,    device=__lowerCAmelCase				)

             return inputs_dict







      def 					__lowercase    (  self   :      List[Any]				):

             """simple docstring"""
             self.config_tester.run_common_tests()







      @unittest.skip(reason='''TimeSformer does not use inputs_embeds'''				)
      def 					__lowercase    (  self   :      int				):

             """simple docstring"""
             pass







      def 					__lowercase    (  self   :      Dict				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Tuple     					=			self.model_tester.prepare_config_and_inputs_for_common()

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







      def 					__lowercase    (  self   :      Tuple				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      str     					=			self.model_tester.prepare_config_and_inputs_for_common()

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

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







      def 					__lowercase    (  self   :      Any				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Dict     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__lowerCAmelCase				)







      def 					__lowercase    (  self   :      Union[str, Any]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_video_classification(*__lowerCAmelCase				)







      @slow
      def 					__lowercase    (  self   :      Dict				):

             """simple docstring"""






             for model_name in TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    SCREAMING_SNAKE_CASE					:      List[str]     					=			TimesformerModel.from_pretrained(__lowerCAmelCase				)
                    self.assertIsNotNone(__lowerCAmelCase				)







      def 					__lowercase    (  self   :      Optional[int]				):

             """simple docstring"""






             if not self.has_attentions:
                    pass

             else:
                    SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      str     					=			self.model_tester.prepare_config_and_inputs_for_common()
                    SCREAMING_SNAKE_CASE					:      List[Any]     					=			True

                    for model_class in self.all_model_classes:
                           SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.model_tester.seq_length
                           SCREAMING_SNAKE_CASE					:      Dict     					=			self.model_tester.num_frames

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

                           # check that output_attentions also work using config
                           del inputs_dict["output_attentions"]
                           SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			True
                           SCREAMING_SNAKE_CASE					:      int     					=			model_class(__lowerCAmelCase				)
                           model.to(__lowerCAmelCase				)
                           model.eval()
                           with torch.no_grad():
                                  SCREAMING_SNAKE_CASE					:      Any     					=			model(**self._prepare_for_class(__lowerCAmelCase				,    __lowerCAmelCase				)				)
                           SCREAMING_SNAKE_CASE					:      Optional[int]     					=			outputs.attentions
                           self.assertEqual(len(__lowerCAmelCase				)				,    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]				,    )
                           SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			len(__lowerCAmelCase				)

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

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

                           SCREAMING_SNAKE_CASE					:      Optional[int]     					=			outputs.attentions

                           self.assertEqual(len(__lowerCAmelCase				)				,    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 					__lowercase    (  self   :      Optional[int]				):

             """simple docstring"""






             def check_hidden_states_output(lowerCAmelCase__   :      Union[str, Any]				,    lowerCAmelCase__   :      Optional[int]				,    lowerCAmelCase__   :      str				):
                    SCREAMING_SNAKE_CASE					:      Tuple     					=			model_class(__lowerCAmelCase				)
                    model.to(__lowerCAmelCase				)
                    model.eval()

                    with torch.no_grad():
                           SCREAMING_SNAKE_CASE					:      Any     					=			model(**self._prepare_for_class(__lowerCAmelCase				,    __lowerCAmelCase				)				)

                    SCREAMING_SNAKE_CASE					:      Any     					=			outputs.hidden_states
                    SCREAMING_SNAKE_CASE					:      int     					=			self.model_tester.num_hidden_layers + 1
                    self.assertEqual(len(__lowerCAmelCase				)				,    __lowerCAmelCase				)

                    SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.model_tester.seq_length

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

             SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      List[str]     					=			self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    SCREAMING_SNAKE_CASE					:      List[Any]     					=			True
                    check_hidden_states_output(__lowerCAmelCase				,    __lowerCAmelCase				,    __lowerCAmelCase				)

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

                    check_hidden_states_output(__lowerCAmelCase				,    __lowerCAmelCase				,    __lowerCAmelCase				)


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






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







      @cached_property
      def 					__lowercase    (  self   :      List[str]				):

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







      @slow
      def 					__lowercase    (  self   :      int				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      int     					=			TimesformerForVideoClassification.from_pretrained('''facebook/timesformer-base-finetuned-k400'''				).to(
                 __lowerCAmelCase				)

             SCREAMING_SNAKE_CASE					:      Dict     					=			self.default_image_processor
             SCREAMING_SNAKE_CASE					:      Tuple     					=			prepare_video()
             SCREAMING_SNAKE_CASE					:      Tuple     					=			image_processor(video[:8]				,    return_tensors='''pt'''				).to(__lowerCAmelCase				)

             # forward pass
             with torch.no_grad():
                    SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			model(**__lowerCAmelCase				)

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

             SCREAMING_SNAKE_CASE					:      int     					=			torch.tensor([-0.3016, -0.7713, -0.4205]				).to(__lowerCAmelCase				)

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









'''simple docstring'''



import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import FEATURE_EXTRACTOR_NAME, is_vision_available


if is_vision_available():
							from PIL import Image

							from transformers import ChineseCLIPImageProcessor, ChineseCLIPProcessor
@require_vision
class 	lowerCamelCase_							(					unittest.TestCase			):







						def 					__lowercase    (  self   :      Optional[int]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			tempfile.mkdtemp()

													SCREAMING_SNAKE_CASE					:      int     					=			[
													    '''[UNK]''',
													    '''[CLS]''',
													    '''[SEP]''',
													    '''[PAD]''',
													    '''[MASK]''',
													    '''的''',
													    '''价''',
													    '''格''',
													    '''是''',
													    '''15''',
													    '''便''',
													    '''alex''',
													    '''##andra''',
													    '''，''',
													    '''。''',
													    '''-''',
													    '''t''',
													    '''shirt''',
													]
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			os.path.join(self.tmpdirname				,    VOCAB_FILES_NAMES['''vocab_file''']				)
													with open(self.vocab_file				,    '''w'''				,    encoding='''utf-8'''				) as vocab_writer:
																				vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]				)				)

													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			{
													    '''do_resize''': True,
													    '''size''': {'''height''': 2_24, '''width''': 2_24},
													    '''do_center_crop''': True,
													    '''crop_size''': {'''height''': 18, '''width''': 18},
													    '''do_normalize''': True,
													    '''image_mean''': [0.4814_5466, 0.457_8275, 0.4082_1073],
													    '''image_std''': [0.2686_2954, 0.2613_0258, 0.2757_7711],
													    '''do_convert_rgb''': True,
													}
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			os.path.join(self.tmpdirname				,    lowerCAmelCase__				)
													with open(self.image_processor_file				,    '''w'''				,    encoding='''utf-8'''				) as fp:
																				json.dump(lowerCAmelCase__				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      str				,    **lowerCAmelCase__   :      int				):

													"""simple docstring"""
													return BertTokenizer.from_pretrained(self.tmpdirname				,    **lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Any				,    **lowerCAmelCase__   :      Dict				):

													"""simple docstring"""
													return BertTokenizerFast.from_pretrained(self.tmpdirname				,    **lowerCAmelCase__				)







						def 					__lowercase    (  self   :      List[Any]				,    **lowerCAmelCase__   :      Dict				):

													"""simple docstring"""
													return ChineseCLIPImageProcessor.from_pretrained(self.tmpdirname				,    **lowerCAmelCase__				)







						def 					__lowercase    (  self   :      List[Any]				):

													"""simple docstring"""
													shutil.rmtree(self.tmpdirname				)







						def 					__lowercase    (  self   :      int				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Dict     					=			[np.random.randint(2_55				,    size=(3, 30, 4_00)				,    dtype=np.uinta				)]

													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			[Image.fromarray(np.moveaxis(lowerCAmelCase__				,    0				,    -1				)				) for x in image_inputs]

													return image_inputs







						def 					__lowercase    (  self   :      int				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Dict     					=			self.get_tokenizer()
													SCREAMING_SNAKE_CASE					:      str     					=			self.get_rust_tokenizer()
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.get_image_processor()

													SCREAMING_SNAKE_CASE					:      Dict     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)
													processor_slow.save_pretrained(self.tmpdirname				)
													SCREAMING_SNAKE_CASE					:      List[str]     					=			ChineseCLIPProcessor.from_pretrained(self.tmpdirname				,    use_fast=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      int     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)
													processor_fast.save_pretrained(self.tmpdirname				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			ChineseCLIPProcessor.from_pretrained(self.tmpdirname				)

													self.assertEqual(processor_slow.tokenizer.get_vocab()				,    tokenizer_slow.get_vocab()				)
													self.assertEqual(processor_fast.tokenizer.get_vocab()				,    tokenizer_fast.get_vocab()				)
													self.assertEqual(tokenizer_slow.get_vocab()				,    tokenizer_fast.get_vocab()				)
													self.assertIsInstance(processor_slow.tokenizer				,    lowerCAmelCase__				)
													self.assertIsInstance(processor_fast.tokenizer				,    lowerCAmelCase__				)

													self.assertEqual(processor_slow.image_processor.to_json_string()				,    image_processor.to_json_string()				)
													self.assertEqual(processor_fast.image_processor.to_json_string()				,    image_processor.to_json_string()				)
													self.assertIsInstance(processor_slow.image_processor				,    lowerCAmelCase__				)
													self.assertIsInstance(processor_fast.image_processor				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Tuple				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			ChineseCLIPProcessor(tokenizer=self.get_tokenizer()				,    image_processor=self.get_image_processor()				)
													processor.save_pretrained(self.tmpdirname				)

													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.get_tokenizer(cls_token='''(CLS)'''				,    sep_token='''(SEP)'''				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.get_image_processor(do_normalize=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			ChineseCLIPProcessor.from_pretrained(
													    self.tmpdirname				,    cls_token='''(CLS)'''				,    sep_token='''(SEP)'''				,    do_normalize=lowerCAmelCase__				)

													self.assertEqual(processor.tokenizer.get_vocab()				,    tokenizer_add_kwargs.get_vocab()				)
													self.assertIsInstance(processor.tokenizer				,    lowerCAmelCase__				)

													self.assertEqual(processor.image_processor.to_json_string()				,    image_processor_add_kwargs.to_json_string()				)
													self.assertIsInstance(processor.image_processor				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Optional[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Any     					=			self.get_image_processor()
													SCREAMING_SNAKE_CASE					:      str     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Tuple     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      Tuple     					=			self.prepare_image_inputs()

													SCREAMING_SNAKE_CASE					:      List[Any]     					=			image_processor(lowerCAmelCase__				,    return_tensors='''np'''				)
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			processor(images=lowerCAmelCase__				,    return_tensors='''np'''				)

													for key in input_feat_extract.keys():
																				self.assertAlmostEqual(input_feat_extract[key].sum()				,    input_processor[key].sum()				,    delta=1e-2				)







						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			self.get_image_processor()
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Tuple     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      int     					=			'''Alexandra，T-shirt的价格是15便士。'''

													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			processor(text=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      List[str]     					=			tokenizer(lowerCAmelCase__				)

													for key in encoded_tok.keys():
																				self.assertListEqual(encoded_tok[key]				,    encoded_processor[key]				)







						def 					__lowercase    (  self   :      Optional[int]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_image_processor()
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Tuple     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      str     					=			'''Alexandra，T-shirt的价格是15便士。'''
													SCREAMING_SNAKE_CASE					:      Tuple     					=			self.prepare_image_inputs()

													SCREAMING_SNAKE_CASE					:      List[str]     					=			processor(text=lowerCAmelCase__				,    images=lowerCAmelCase__				)

													self.assertListEqual(list(inputs.keys()				)				,    ['''input_ids''', '''token_type_ids''', '''attention_mask''', '''pixel_values''']				)

													# test if it raises when no input is passed
													with pytest.raises(lowerCAmelCase__				):
																				processor()







						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Tuple     					=			self.get_image_processor()
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Tuple     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      List[Any]     					=			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

													SCREAMING_SNAKE_CASE					:      Any     					=			processor.batch_decode(lowerCAmelCase__				)
													SCREAMING_SNAKE_CASE					:      Tuple     					=			tokenizer.batch_decode(lowerCAmelCase__				)

													self.assertListEqual(lowerCAmelCase__				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      str     					=			self.get_image_processor()
													SCREAMING_SNAKE_CASE					:      List[str]     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Dict     					=			ChineseCLIPProcessor(tokenizer=lowerCAmelCase__				,    image_processor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      int     					=			'''Alexandra，T-shirt的价格是15便士。'''
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.prepare_image_inputs()

													SCREAMING_SNAKE_CASE					:      Any     					=			processor(text=lowerCAmelCase__				,    images=lowerCAmelCase__				)

													self.assertListEqual(list(inputs.keys()				)				,    processor.model_input_names				)




