


"""simple docstring"""


import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
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,
	    VideoMAEForPreTraining,
	    VideoMAEForVideoClassification,
	    VideoMAEModel,
	)
	from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
	from transformers import VideoMAEImageProcessor
class   _UpperCamelCase  :
							'''simple docstring'''







							def __init__(     self    ,   __a    ,   __a=13    ,   __a=10    ,   __a=3    ,   __a=2    ,   __a=2    ,   __a=2    ,   __a=True    ,   __a=True    ,   __a=32    ,   __a=5    ,   __a=4    ,   __a=37    ,   __a="gelu"    ,   __a=0.1    ,   __a=0.1    ,   __a=10    ,   __a=0.0_2    ,   __a=0.9    ,   __a=None    ,   ):
										__lowerCAmelCase				    =			parent
										__lowerCAmelCase				    =			batch_size
										__lowerCAmelCase				    =			image_size
										__lowerCAmelCase				    =			num_channels
										__lowerCAmelCase				    =			patch_size
										__lowerCAmelCase				    =			tubelet_size
										__lowerCAmelCase				    =			num_frames
										__lowerCAmelCase				    =			is_training
										__lowerCAmelCase				    =			use_labels
										__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				    =			type_sequence_label_size
										__lowerCAmelCase				    =			initializer_range
										__lowerCAmelCase				    =			mask_ratio
										__lowerCAmelCase				    =			scope

										# in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
										__lowerCAmelCase				    =			(image_size // patch_size) ** 2
										__lowerCAmelCase				    =			(num_frames // tubelet_size) * self.num_patches_per_frame

										# use this variable to define bool_masked_pos
										__lowerCAmelCase				    =			int(mask_ratio * self.seq_length	)

							def 			snake_case				(     self	):
										__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.type_sequence_label_size	)

										__lowerCAmelCase				    =			self.get_config()

										return config, pixel_values, labels

							def 			snake_case				(     self	):
										return VideoMAEConfig(
										    image_size=self.image_size    ,   patch_size=self.patch_size    ,   num_channels=self.num_channels    ,   num_frames=self.num_frames    ,   tubelet_size=self.tubelet_size    ,   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    ,   is_decoder=__a    ,   initializer_range=self.initializer_range    ,   )

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			VideoMAEModel(config=__a	)
										model.to(__a	)
										model.eval()
										__lowerCAmelCase				    =			model(__a	)
										self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.hidden_size)	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a	):
										__lowerCAmelCase				    =			VideoMAEForPreTraining(__a	)
										model.to(__a	)
										model.eval()
										# important: each video needs to have the same number of masked patches
										# hence we define a single mask, which we then repeat for each example in the batch
										__lowerCAmelCase				    =			torch.ones((self.num_masks,)	)
										__lowerCAmelCase				    =			torch.cat([mask, torch.zeros(self.seq_length - mask.size(0	)	)]	)
										__lowerCAmelCase				    =			mask.expand(self.batch_size    ,   -1	).bool()

										__lowerCAmelCase				    =			model(__a    ,   __a	)
										# model only returns predictions for masked patches
										__lowerCAmelCase				    =			mask.sum().item()
										__lowerCAmelCase				    =			3 * self.tubelet_size * self.patch_size**2
										self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, num_masked_patches, decoder_num_labels)	)



							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.prepare_config_and_inputs()
										__lowerCAmelCase    ,	__lowerCAmelCase    ,	__lowerCAmelCase				    =			config_and_inputs
										__lowerCAmelCase				    =			{"pixel_values": pixel_values}
										return config, inputs_dict
@require_torch
class   _UpperCamelCase  (   lowerCAmelCase__       ,lowerCAmelCase__       ,unittest.TestCase		):
							'''simple docstring'''







							__UpperCAmelCase						:    Dict				      =(
							    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
							)
							__UpperCAmelCase						:    str				      =(
							    {"""feature-extraction""": VideoMAEModel, """video-classification""": VideoMAEForVideoClassification}
							    if is_torch_available()
							    else {}
							)

							__UpperCAmelCase						:    List[str]				      =False
							__UpperCAmelCase						:    Tuple				      =False
							__UpperCAmelCase						:    Union[str, Any]				      =False
							__UpperCAmelCase						:    Dict				      =False

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			VideoMAEModelTester(self	)
										__lowerCAmelCase				    =			ConfigTester(self    ,   config_class=__a    ,   has_text_modality=__a    ,   hidden_size=37	)

							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a=False	):
										__lowerCAmelCase				    =			copy.deepcopy(__a	)

										if model_class == VideoMAEForPreTraining:
													# important: each video needs to have the same number of masked patches
													# hence we define a single mask, which we then repeat for each example in the batch
													__lowerCAmelCase				    =			torch.ones((self.model_tester.num_masks,)	)
													__lowerCAmelCase				    =			torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0	)	)]	)
													__lowerCAmelCase				    =			mask.expand(self.model_tester.batch_size    ,   -1	).bool()
													__lowerCAmelCase				    =			bool_masked_pos.to(__a	)

										if return_labels:
													if model_class in [
													    *get_values(__a	),
													]:
																__lowerCAmelCase				    =			torch.zeros(
																    self.model_tester.batch_size    ,   dtype=torch.long    ,   device=__a	)

										return inputs_dict

							def 			snake_case				(     self	):
										self.config_tester.run_common_tests()

							@unittest.skip(reason="VideoMAE does not use inputs_embeds"	)
							def 			snake_case				(     self	):
										pass

							def 			snake_case				(     self	):
										__lowerCAmelCase    ,	__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs_for_common()

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

							def 			snake_case				(     self	):
										__lowerCAmelCase    ,	__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs_for_common()

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

													__lowerCAmelCase				    =			["pixel_values"]
													self.assertListEqual(arg_names[:1]    ,   __a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*__a	)

							@slow
							def 			snake_case				(     self	):
										for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													__lowerCAmelCase				    =			VideoMAEModel.from_pretrained(__a	)
													self.assertIsNotNone(__a	)

							def 			snake_case				(     self	):
										if not self.has_attentions:
													pass

										else:
													__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 - self.model_tester.num_masks
																__lowerCAmelCase				    =			(
																    num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
																)

																__lowerCAmelCase				    =			True
																__lowerCAmelCase				    =			False
																__lowerCAmelCase				    =			True
																__lowerCAmelCase				    =			model_class(__a	)
																model.to(__a	)
																model.eval()
																with torch.no_grad():
																			__lowerCAmelCase				    =			model(**self._prepare_for_class(__a    ,   __a	)	)
																__lowerCAmelCase				    =			outputs.attentions
																self.assertEqual(len(__a	)    ,   self.model_tester.num_hidden_layers	)

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

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

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

																__lowerCAmelCase				    =			outputs.attentions

																self.assertEqual(len(__a	)    ,   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 			snake_case				(     self	):
										def check_hidden_states_output(__a    ,   __a    ,   __a	):
													__lowerCAmelCase				    =			model_class(__a	)
													model.to(__a	)
													model.eval()

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

													__lowerCAmelCase				    =			outputs.hidden_states
													__lowerCAmelCase				    =			self.model_tester.num_hidden_layers + 1
													self.assertEqual(len(__a	)    ,   __a	)

													__lowerCAmelCase				    =			self.model_tester.seq_length - self.model_tester.num_masks
													__lowerCAmelCase				    =			num_visible_patches if model_class == VideoMAEForPreTraining else 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(__a    ,   __a    ,   __a	)

													# check that output_hidden_states also work using config
													del inputs_dict["output_hidden_states"]
													__lowerCAmelCase				    =			True

													check_hidden_states_output(__a    ,   __a    ,   __a	)



							@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."	)
							def 			snake_case				(     self	):
										pass


def _lowerCamelCase	(		):

			'''simple docstring'''




			__lowerCAmelCase				    =			hf_hub_download(
			    repo_id="hf-internal-testing/spaghetti-video"    , filename="eating_spaghetti.npy"    , repo_type="dataset"      )
			__lowerCAmelCase				    =			np.load(_UpperCamelCase      )
			return list(_UpperCamelCase      )


@require_torch
@require_vision
class   _UpperCamelCase  (   unittest.TestCase		):
							'''simple docstring'''







							@cached_property
							def 			snake_case				(     self	):
										# 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 			snake_case				(     self	):
										__lowerCAmelCase				    =			VideoMAEForVideoClassification.from_pretrained("MCG-NJU/videomae-base-finetuned-kinetics"	).to(
										    __a	)

										__lowerCAmelCase				    =			self.default_image_processor
										__lowerCAmelCase				    =			prepare_video()
										__lowerCAmelCase				    =			image_processor(__a    ,   return_tensors="pt"	).to(__a	)

										# forward pass
										with torch.no_grad():
													__lowerCAmelCase				    =			model(**__a	)

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

										__lowerCAmelCase				    =			torch.tensor([0.3_6_6_9, -0.0_6_8_8, -0.2_4_2_1]	).to(__a	)

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



							@slow
							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			VideoMAEForPreTraining.from_pretrained("MCG-NJU/videomae-base-short"	).to(__a	)

										__lowerCAmelCase				    =			self.default_image_processor
										__lowerCAmelCase				    =			prepare_video()
										__lowerCAmelCase				    =			image_processor(__a    ,   return_tensors="pt"	).to(__a	)

										# add boolean mask, indicating which patches to mask
										__lowerCAmelCase				    =			hf_hub_download(repo_id="hf-internal-testing/bool-masked-pos"    ,   filename="bool_masked_pos.pt"	)
										__lowerCAmelCase				    =			torch.load(__a	)

										# forward pass
										with torch.no_grad():
													__lowerCAmelCase				    =			model(**__a	)

										# verify the logits
										__lowerCAmelCase				    =			torch.Size([1, 14_08, 15_36]	)
										__lowerCAmelCase				    =			torch.tensor(
										    [[0.7_9_9_4, 0.9_6_1_2, 0.8_5_0_8], [0.7_4_0_1, 0.8_9_5_8, 0.8_3_0_2], [0.5_8_6_2, 0.7_4_6_8, 0.7_3_2_5]]    ,   device=__a	)
										self.assertEqual(outputs.logits.shape    ,   __a	)
										self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]    ,   __a    ,   atol=1e-4	)	)

										# verify the loss (`config.norm_pix_loss` = `True`)
										__lowerCAmelCase				    =			torch.tensor([0.5_1_4_2]    ,   device=__a	)
										self.assertTrue(torch.allclose(outputs.loss    ,   __a    ,   atol=1e-4	)	)

										# verify the loss (`config.norm_pix_loss` = `False`)
										__lowerCAmelCase				    =			VideoMAEForPreTraining.from_pretrained("MCG-NJU/videomae-base-short"    ,   norm_pix_loss=__a	).to(
										    __a	)

										with torch.no_grad():
													__lowerCAmelCase				    =			model(**__a	)

										__lowerCAmelCase				    =			torch.tensor(torch.tensor([0.6_4_6_9]	)    ,   device=__a	)
										self.assertTrue(torch.allclose(outputs.loss    ,   __a    ,   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   _UpperCamelCase  (   unittest.TestCase		):
							'''simple docstring'''







							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			tempfile.mkdtemp()

										__lowerCAmelCase				    =			[
										    "[UNK]",
										    "[CLS]",
										    "[SEP]",
										    "[PAD]",
										    "[MASK]",
										    "的",
										    "价",
										    "格",
										    "是",
										    "15",
										    "便",
										    "alex",
										    "##andra",
										    "，",
										    "。",
										    "-",
										    "t",
										    "shirt",
										]
										__lowerCAmelCase				    =			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]	)	)

										__lowerCAmelCase				    =			{
										    "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.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3],
										    "image_std": [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1],
										    "do_convert_rgb": True,
										}
										__lowerCAmelCase				    =			os.path.join(self.tmpdirname    ,   __a	)
										with open(self.image_processor_file    ,   "w"    ,   encoding="utf-8"	) as fp:
													json.dump(__a    ,   __a	)

							def 			snake_case				(     self    ,   **__a	):
										return BertTokenizer.from_pretrained(self.tmpdirname    ,   **__a	)

							def 			snake_case				(     self    ,   **__a	):
										return BertTokenizerFast.from_pretrained(self.tmpdirname    ,   **__a	)

							def 			snake_case				(     self    ,   **__a	):
										return ChineseCLIPImageProcessor.from_pretrained(self.tmpdirname    ,   **__a	)

							def 			snake_case				(     self	):
										shutil.rmtree(self.tmpdirname	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			[np.random.randint(2_55    ,   size=(3, 30, 4_00)    ,   dtype=np.uinta	)]

										__lowerCAmelCase				    =			[Image.fromarray(np.moveaxis(__a    ,   0    ,   -1	)	) for x in image_inputs]

										return image_inputs

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.get_tokenizer()
										__lowerCAmelCase				    =			self.get_rust_tokenizer()
										__lowerCAmelCase				    =			self.get_image_processor()

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)
										processor_slow.save_pretrained(self.tmpdirname	)
										__lowerCAmelCase				    =			ChineseCLIPProcessor.from_pretrained(self.tmpdirname    ,   use_fast=__a	)

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)
										processor_fast.save_pretrained(self.tmpdirname	)
										__lowerCAmelCase				    =			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    ,   __a	)
										self.assertIsInstance(processor_fast.tokenizer    ,   __a	)

										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    ,   __a	)
										self.assertIsInstance(processor_fast.image_processor    ,   __a	)

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=self.get_tokenizer()    ,   image_processor=self.get_image_processor()	)
										processor.save_pretrained(self.tmpdirname	)

										__lowerCAmelCase				    =			self.get_tokenizer(cls_token="(CLS)"    ,   sep_token="(SEP)"	)
										__lowerCAmelCase				    =			self.get_image_processor(do_normalize=__a	)

										__lowerCAmelCase				    =			ChineseCLIPProcessor.from_pretrained(
										    self.tmpdirname    ,   cls_token="(CLS)"    ,   sep_token="(SEP)"    ,   do_normalize=__a	)

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

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

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.get_image_processor()
										__lowerCAmelCase				    =			self.get_tokenizer()

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)

										__lowerCAmelCase				    =			self.prepare_image_inputs()

										__lowerCAmelCase				    =			image_processor(__a    ,   return_tensors="np"	)
										__lowerCAmelCase				    =			processor(images=__a    ,   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 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.get_image_processor()
										__lowerCAmelCase				    =			self.get_tokenizer()

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)

										__lowerCAmelCase				    =			"Alexandra，T-shirt的价格是15便士。"

										__lowerCAmelCase				    =			processor(text=__a	)

										__lowerCAmelCase				    =			tokenizer(__a	)

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

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.get_image_processor()
										__lowerCAmelCase				    =			self.get_tokenizer()

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)

										__lowerCAmelCase				    =			"Alexandra，T-shirt的价格是15便士。"
										__lowerCAmelCase				    =			self.prepare_image_inputs()

										__lowerCAmelCase				    =			processor(text=__a    ,   images=__a	)

										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(__a	):
													processor()

							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.get_image_processor()
										__lowerCAmelCase				    =			self.get_tokenizer()

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)

										__lowerCAmelCase				    =			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

										__lowerCAmelCase				    =			processor.batch_decode(__a	)
										__lowerCAmelCase				    =			tokenizer.batch_decode(__a	)

										self.assertListEqual(__a    ,   __a	)



							def 			snake_case				(     self	):
										__lowerCAmelCase				    =			self.get_image_processor()
										__lowerCAmelCase				    =			self.get_tokenizer()

										__lowerCAmelCase				    =			ChineseCLIPProcessor(tokenizer=__a    ,   image_processor=__a	)

										__lowerCAmelCase				    =			"Alexandra，T-shirt的价格是15便士。"
										__lowerCAmelCase				    =			self.prepare_image_inputs()

										__lowerCAmelCase				    =			processor(text=__a    ,   images=__a	)

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




