






import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
 from transformers.models.esm.modeling_esm import (
     ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
     EsmEmbeddings,
     create_position_ids_from_input_ids,
 )





class       __a  :







 def __init__(		self :       List[Any]							,       SCREAMING_SNAKE_CASE :       Union[str, Any]							,       SCREAMING_SNAKE_CASE :       int=13							,       SCREAMING_SNAKE_CASE :       int=7							,       SCREAMING_SNAKE_CASE :       List[Any]=False							,       SCREAMING_SNAKE_CASE :       Any=True							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=False							,       SCREAMING_SNAKE_CASE :       int=True							,       SCREAMING_SNAKE_CASE :       Optional[int]=33							,       SCREAMING_SNAKE_CASE :       Tuple=32							,       SCREAMING_SNAKE_CASE :       Dict=5							,       SCREAMING_SNAKE_CASE :       int=4							,       SCREAMING_SNAKE_CASE :       List[str]=37							,       SCREAMING_SNAKE_CASE :       Dict="gelu"							,       SCREAMING_SNAKE_CASE :       List[Any]=0.1							,       SCREAMING_SNAKE_CASE :       Optional[int]=0.1							,       SCREAMING_SNAKE_CASE :       List[Any]=5_12							,       SCREAMING_SNAKE_CASE :       str=16							,       SCREAMING_SNAKE_CASE :       int=2							,       SCREAMING_SNAKE_CASE :       List[str]=0.0_2							,       SCREAMING_SNAKE_CASE :       List[Any]=3							,       SCREAMING_SNAKE_CASE :       str=4							,       SCREAMING_SNAKE_CASE :       Dict=None							,       ):


  '''simple docstring'''






  UpperCamelCase__      :       Optional[int]	    =  parent
  UpperCamelCase__      :       List[Any]	    =  batch_size
  UpperCamelCase__      :       Any	    =  seq_length
  UpperCamelCase__      :       List[str]	    =  is_training
  UpperCamelCase__      :       Optional[int]	    =  use_input_mask
  UpperCamelCase__      :       str	    =  use_token_type_ids
  UpperCamelCase__      :       Dict	    =  use_labels
  UpperCamelCase__      :       Union[str, Any]	    =  vocab_size
  UpperCamelCase__      :       Optional[Any]	    =  hidden_size
  UpperCamelCase__      :       Optional[int]	    =  num_hidden_layers
  UpperCamelCase__      :       Optional[int]	    =  num_attention_heads
  UpperCamelCase__      :       Optional[Any]	    =  intermediate_size
  UpperCamelCase__      :       Union[str, Any]	    =  hidden_act
  UpperCamelCase__      :       int	    =  hidden_dropout_prob
  UpperCamelCase__      :       Tuple	    =  attention_probs_dropout_prob
  UpperCamelCase__      :       Any	    =  max_position_embeddings
  UpperCamelCase__      :       Dict	    =  type_vocab_size
  UpperCamelCase__      :       Union[str, Any]	    =  type_sequence_label_size
  UpperCamelCase__      :       Optional[Any]	    =  initializer_range
  UpperCamelCase__      :       Dict	    =  num_labels
  UpperCamelCase__      :       Dict	    =  num_choices
  UpperCamelCase__      :       Dict	    =  scope







 def  __lowercase (		self :       Any						):


  '''simple docstring'''






  UpperCamelCase__      :       Union[str, Any]	    =  ids_tensor([self.batch_size, self.seq_length]							,       self.vocab_size						)

  UpperCamelCase__      :       List[Any]	    =  None
  if self.use_input_mask:
   UpperCamelCase__      :       Tuple	    =  random_attention_mask([self.batch_size, self.seq_length]						)

  UpperCamelCase__      :       Optional[Any]	    =  None
  UpperCamelCase__      :       List[Any]	    =  None
  UpperCamelCase__      :       str	    =  None
  if self.use_labels:
   UpperCamelCase__      :       List[Any]	    =  ids_tensor([self.batch_size]							,       self.type_sequence_label_size						)
   UpperCamelCase__      :       int	    =  ids_tensor([self.batch_size, self.seq_length]							,       self.num_labels						)
   UpperCamelCase__      :       Optional[Any]	    =  ids_tensor([self.batch_size]							,       self.num_choices						)

  UpperCamelCase__      :       Dict	    =  self.get_config()

  return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels







 def  __lowercase (		self :       str						):


  '''simple docstring'''






  return EsmConfig(
      vocab_size=self.vocab_size							,       hidden_size=self.hidden_size							,       pad_token_id=1							,       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							,       max_position_embeddings=self.max_position_embeddings							,       type_vocab_size=self.type_vocab_size							,       initializer_range=self.initializer_range							,       )







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


  '''simple docstring'''






  UpperCamelCase__      :       List[Any]	    =  EsmModel(config=SCREAMING_SNAKE_CASE						)
  model.to(SCREAMING_SNAKE_CASE						)
  model.eval()
  UpperCamelCase__      :       Tuple	    =  model(SCREAMING_SNAKE_CASE							,       attention_mask=SCREAMING_SNAKE_CASE						)
  UpperCamelCase__      :       Optional[int]	    =  model(SCREAMING_SNAKE_CASE						)
  UpperCamelCase__      :       Dict	    =  model(SCREAMING_SNAKE_CASE						)

  self.parent.assertEqual(result.last_hidden_state.shape							,       (self.batch_size, self.seq_length, self.hidden_size)						)
  self.parent.assertEqual(result.pooler_output.shape							,       (self.batch_size, self.hidden_size)						)







 def  __lowercase (		self :       List[Any]							,       SCREAMING_SNAKE_CASE :       Union[str, Any]							,       SCREAMING_SNAKE_CASE :       List[Any]							,       SCREAMING_SNAKE_CASE :       Dict							,       SCREAMING_SNAKE_CASE :       Optional[int]							,       SCREAMING_SNAKE_CASE :       str							,       SCREAMING_SNAKE_CASE :       str						):


  '''simple docstring'''






  UpperCamelCase__      :       Optional[Any]	    =  EsmForMaskedLM(config=SCREAMING_SNAKE_CASE						)
  model.to(SCREAMING_SNAKE_CASE						)
  model.eval()
  UpperCamelCase__      :       List[str]	    =  model(SCREAMING_SNAKE_CASE							,       attention_mask=SCREAMING_SNAKE_CASE							,       labels=SCREAMING_SNAKE_CASE						)
  self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.seq_length, self.vocab_size)						)







 def  __lowercase (		self :       Optional[int]							,       SCREAMING_SNAKE_CASE :       Dict							,       SCREAMING_SNAKE_CASE :       Tuple							,       SCREAMING_SNAKE_CASE :       Union[str, Any]							,       SCREAMING_SNAKE_CASE :       Tuple							,       SCREAMING_SNAKE_CASE :       Dict							,       SCREAMING_SNAKE_CASE :       Dict						):


  '''simple docstring'''






  UpperCamelCase__      :       Union[str, Any]	    =  self.num_labels
  UpperCamelCase__      :       List[str]	    =  EsmForTokenClassification(config=SCREAMING_SNAKE_CASE						)
  model.to(SCREAMING_SNAKE_CASE						)
  model.eval()
  UpperCamelCase__      :       Optional[Any]	    =  model(SCREAMING_SNAKE_CASE							,       attention_mask=SCREAMING_SNAKE_CASE							,       labels=SCREAMING_SNAKE_CASE						)
  self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.seq_length, self.num_labels)						)







 def  __lowercase (		self :       Tuple						):


  '''simple docstring'''






  UpperCamelCase__      :       str	    =  self.prepare_config_and_inputs()
  (
      UpperCamelCase__					
  )      :       str	    =  config_and_inputs
  UpperCamelCase__      :       Optional[Any]	    =  {"input_ids": input_ids, "attention_mask": input_mask}
  return config, inputs_dict







@require_torch
class       __a  (   A__	,       A__	,       unittest.TestCase	):
 _lowerCAmelCase	:	List[str]				=			False

 _lowerCAmelCase	:	Any				=			(
     (
         EsmForMaskedLM,
         EsmModel,
         EsmForSequenceClassification,
         EsmForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 _lowerCAmelCase	:	str				=			()
 _lowerCAmelCase	:	Optional[int]				=			(
     {
         '''feature-extraction''': EsmModel,
         '''fill-mask''': EsmForMaskedLM,
         '''text-classification''': EsmForSequenceClassification,
         '''token-classification''': EsmForTokenClassification,
         '''zero-shot''': EsmForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 _lowerCAmelCase	:	Dict				=			True







 def  __lowercase (		self :       List[str]						):


  '''simple docstring'''






  UpperCamelCase__      :       Dict	    =  EsmModelTester(self						)
  UpperCamelCase__      :       List[Any]	    =  ConfigTester(self							,       config_class=SCREAMING_SNAKE_CASE							,       hidden_size=37						)







 def  __lowercase (		self :       Any						):


  '''simple docstring'''






  self.config_tester.run_common_tests()







 def  __lowercase (		self :       Optional[int]						):


  '''simple docstring'''






  UpperCamelCase__      :       Optional[Any]	    =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       List[str]						):


  '''simple docstring'''






  UpperCamelCase__      :       str	    =  self.model_tester.prepare_config_and_inputs()
  for type in ["absolute", "relative_key", "relative_key_query"]:
   UpperCamelCase__      :       int	    =  type
   self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       Optional[int]						):


  '''simple docstring'''






  UpperCamelCase__      :       Optional[int]	    =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       int						):


  '''simple docstring'''






  UpperCamelCase__      :       Optional[int]	    =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE						)







 @slow
 def  __lowercase (		self :       int						):


  '''simple docstring'''






  for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   UpperCamelCase__      :       Optional[int]	    =  EsmModel.from_pretrained(SCREAMING_SNAKE_CASE						)
   self.assertIsNotNone(SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       Optional[int]						):


  '''simple docstring'''






  UpperCamelCase__      :       Optional[Any]	    =  self.model_tester.prepare_config_and_inputs()[0]
  UpperCamelCase__      :       Any	    =  EsmEmbeddings(config=SCREAMING_SNAKE_CASE						)

  UpperCamelCase__      :       int	    =  torch.as_tensor([[12, 31, 13, model.padding_idx]]						)
  UpperCamelCase__      :       Tuple	    =  torch.as_tensor(
      [
          [
              0 + model.padding_idx + 1,
              1 + model.padding_idx + 1,
              2 + model.padding_idx + 1,
              model.padding_idx,
          ]
      ]						)
  UpperCamelCase__      :       Optional[Any]	    =  create_position_ids_from_input_ids(SCREAMING_SNAKE_CASE							,       model.padding_idx						)
  self.assertEqual(position_ids.shape							,       expected_positions.shape						)
  self.assertTrue(torch.all(torch.eq(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)						)						)







 def  __lowercase (		self :       int						):


  '''simple docstring'''






  UpperCamelCase__      :       List[Any]	    =  self.model_tester.prepare_config_and_inputs()[0]
  UpperCamelCase__      :       Union[str, Any]	    =  EsmEmbeddings(config=SCREAMING_SNAKE_CASE						)

  UpperCamelCase__      :       Union[str, Any]	    =  torch.empty(2							,       4							,       30						)
  UpperCamelCase__      :       Union[str, Any]	    =  [
      0 + embeddings.padding_idx + 1,
      1 + embeddings.padding_idx + 1,
      2 + embeddings.padding_idx + 1,
      3 + embeddings.padding_idx + 1,
  ]
  UpperCamelCase__      :       Optional[int]	    =  torch.as_tensor([expected_single_positions, expected_single_positions]						)
  UpperCamelCase__      :       List[str]	    =  embeddings.create_position_ids_from_inputs_embeds(SCREAMING_SNAKE_CASE						)
  self.assertEqual(position_ids.shape							,       expected_positions.shape						)
  self.assertTrue(torch.all(torch.eq(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)						)						)







 @unittest.skip("Esm does not support embedding resizing"						)
 def  __lowercase (		self :       Dict						):


  '''simple docstring'''






  pass







 @unittest.skip("Esm does not support embedding resizing"						)
 def  __lowercase (		self :       Optional[Any]						):


  '''simple docstring'''






  pass







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


  '''simple docstring'''






  pass







@require_torch
class       __a  (   A__	):







 @slow
 def  __lowercase (		self :       Tuple						):


  '''simple docstring'''






  with torch.no_grad():
   UpperCamelCase__      :       str	    =  EsmForMaskedLM.from_pretrained("facebook/esm2_t6_8M_UR50D"						)
   model.eval()
   UpperCamelCase__      :       List[Any]	    =  torch.tensor([[0, 1, 2, 3, 4, 5]]						)
   UpperCamelCase__      :       Any	    =  model(SCREAMING_SNAKE_CASE						)[0]

   UpperCamelCase__      :       int	    =  33

   UpperCamelCase__      :       Tuple	    =  torch.Size((1, 6, vocab_size)						)
   self.assertEqual(output.shape							,       SCREAMING_SNAKE_CASE						)

   UpperCamelCase__      :       str	    =  torch.tensor(
       [[[8.9_2_1_5, -10.58_98, -6.4_6_7_1], [-6.3_9_6_7, -13.91_14, -1.1_2_1_2], [-7.7_8_1_2, -13.95_16, -3.7_4_0_6]]]						)
   self.assertTrue(torch.allclose(output[:, :3, :3]							,       SCREAMING_SNAKE_CASE							,       atol=1e-4						)						)







 @slow
 def  __lowercase (		self :       Optional[Any]						):


  '''simple docstring'''






  with torch.no_grad():
   UpperCamelCase__      :       List[str]	    =  EsmModel.from_pretrained("facebook/esm2_t6_8M_UR50D"						)
   model.eval()

   UpperCamelCase__      :       int	    =  torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]						)
   UpperCamelCase__      :       Optional[int]	    =  model(SCREAMING_SNAKE_CASE						)[0]
   # compare the actual values for a slice.
   UpperCamelCase__      :       Dict	    =  torch.tensor(
       [[[0.1_4_4_4, 0.5_4_1_3, 0.3_2_4_8], [0.3_0_3_4, 0.0_0_5_3, 0.3_1_0_8], [0.3_2_2_8, -0.2_4_9_9, 0.3_4_1_5]]]						)
   self.assertTrue(torch.allclose(output[:, :3, :3]							,       SCREAMING_SNAKE_CASE							,       atol=1e-4						)						)







import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
 from PIL import Image

 from transformers import CLIPImageProcessor, CLIPProcessor





@require_vision
class       __a  (   unittest.TestCase	):







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


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  tempfile.mkdtemp()

      # fmt: off
      UpperCamelCase__      :       List[Any]	    =  ["l", "o", "w", "e", "r", "s", "t", "i", "d", "n", "lo", "l</w>", "w</w>", "r</w>", "t</w>", "low</w>", "er</w>", "lowest</w>", "newer</w>", "wider", "<unk>", "<|startoftext|>", "<|endoftext|>"]
      # fmt: on
      UpperCamelCase__      :       List[Any]	    =  dict(zip(SCREAMING_SNAKE_CASE							,       range(len(SCREAMING_SNAKE_CASE						)						)						)						)
      UpperCamelCase__      :       Tuple	    =  ["#version: 0.2", "l o", "lo w</w>", "e r</w>", ""]
      UpperCamelCase__      :       Tuple	    =  {"unk_token": "<unk>"}

      UpperCamelCase__      :       Tuple	    =  os.path.join(self.tmpdirname							,       VOCAB_FILES_NAMES["vocab_file"]						)
      UpperCamelCase__      :       Optional[int]	    =  os.path.join(self.tmpdirname							,       VOCAB_FILES_NAMES["merges_file"]						)
      with open(self.vocab_file							,       "w"							,       encoding="utf-8"						) as fp:
           fp.write(json.dumps(SCREAMING_SNAKE_CASE						) + "\n"						)
      with open(self.merges_file							,       "w"							,       encoding="utf-8"						) as fp:
           fp.write("\n".join(SCREAMING_SNAKE_CASE						)						)

      UpperCamelCase__      :       List[str]	    =  {
          "do_resize": True,
          "size": 20,
          "do_center_crop": True,
          "crop_size": 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],
      }
      UpperCamelCase__      :       int	    =  os.path.join(self.tmpdirname							,       SCREAMING_SNAKE_CASE						)
      with open(self.image_processor_file							,       "w"							,       encoding="utf-8"						) as fp:
           json.dump(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       List[str]							,       **SCREAMING_SNAKE_CASE :       List[str]						):


      '''simple docstring'''






      return CLIPTokenizer.from_pretrained(self.tmpdirname							,       **SCREAMING_SNAKE_CASE						)







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


      '''simple docstring'''






      return CLIPTokenizerFast.from_pretrained(self.tmpdirname							,       **SCREAMING_SNAKE_CASE						)







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


      '''simple docstring'''






      return CLIPImageProcessor.from_pretrained(self.tmpdirname							,       **SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      shutil.rmtree(self.tmpdirname						)







 def  __lowercase (		self :       Any						):


      '''simple docstring'''






      UpperCamelCase__      :       int	    =  [np.random.randint(2_55							,       size=(3, 30, 4_00)							,       dtype=np.uinta						)]

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

      return image_inputs







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      UpperCamelCase__      :       Union[str, Any]	    =  self.get_tokenizer()
      UpperCamelCase__      :       List[str]	    =  self.get_rust_tokenizer()
      UpperCamelCase__      :       str	    =  self.get_image_processor()

      UpperCamelCase__      :       List[str]	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)
      processor_slow.save_pretrained(self.tmpdirname						)
      UpperCamelCase__      :       List[Any]	    =  CLIPProcessor.from_pretrained(self.tmpdirname							,       use_fast=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       Tuple	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)
      processor_fast.save_pretrained(self.tmpdirname						)
      UpperCamelCase__      :       Any	    =  CLIPProcessor.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							,       SCREAMING_SNAKE_CASE						)
      self.assertIsInstance(processor_fast.tokenizer							,       SCREAMING_SNAKE_CASE						)

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







 def  __lowercase (		self :       List[str]						):


      '''simple docstring'''






      UpperCamelCase__      :       str	    =  CLIPProcessor(tokenizer=self.get_tokenizer()							,       image_processor=self.get_image_processor()						)
      processor.save_pretrained(self.tmpdirname						)

      UpperCamelCase__      :       Union[str, Any]	    =  self.get_tokenizer(bos_token="(BOS)"							,       eos_token="(EOS)"						)
      UpperCamelCase__      :       int	    =  self.get_image_processor(do_normalize=SCREAMING_SNAKE_CASE							,       padding_value=1.0						)

      UpperCamelCase__      :       Tuple	    =  CLIPProcessor.from_pretrained(
          self.tmpdirname							,       bos_token="(BOS)"							,       eos_token="(EOS)"							,       do_normalize=SCREAMING_SNAKE_CASE							,       padding_value=1.0						)

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

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







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       List[str]	    =  self.get_image_processor()
      UpperCamelCase__      :       Union[str, Any]	    =  self.get_tokenizer()

      UpperCamelCase__      :       Any	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       Dict	    =  self.prepare_image_inputs()

      UpperCamelCase__      :       List[Any]	    =  image_processor(SCREAMING_SNAKE_CASE							,       return_tensors="np"						)
      UpperCamelCase__      :       Optional[Any]	    =  processor(images=SCREAMING_SNAKE_CASE							,       return_tensors="np"						)

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







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


      '''simple docstring'''






      UpperCamelCase__      :       str	    =  self.get_image_processor()
      UpperCamelCase__      :       int	    =  self.get_tokenizer()

      UpperCamelCase__      :       Any	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       List[Any]	    =  "lower newer"

      UpperCamelCase__      :       int	    =  processor(text=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       Tuple	    =  tokenizer(SCREAMING_SNAKE_CASE						)

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







 def  __lowercase (		self :       int						):


      '''simple docstring'''






      UpperCamelCase__      :       List[str]	    =  self.get_image_processor()
      UpperCamelCase__      :       Dict	    =  self.get_tokenizer()

      UpperCamelCase__      :       Optional[Any]	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       Dict	    =  "lower newer"
      UpperCamelCase__      :       List[Any]	    =  self.prepare_image_inputs()

      UpperCamelCase__      :       Tuple	    =  processor(text=SCREAMING_SNAKE_CASE							,       images=SCREAMING_SNAKE_CASE						)

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

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







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      UpperCamelCase__      :       Optional[Any]	    =  self.get_image_processor()
      UpperCamelCase__      :       Optional[int]	    =  self.get_tokenizer()

      UpperCamelCase__      :       Optional[Any]	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       List[str]	    =  [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

      UpperCamelCase__      :       Optional[Any]	    =  processor.batch_decode(SCREAMING_SNAKE_CASE						)
      UpperCamelCase__      :       List[Any]	    =  tokenizer.batch_decode(SCREAMING_SNAKE_CASE						)

      self.assertListEqual(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       List[str]						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  self.get_image_processor()
      UpperCamelCase__      :       Tuple	    =  self.get_tokenizer()

      UpperCamelCase__      :       Dict	    =  CLIPProcessor(tokenizer=SCREAMING_SNAKE_CASE							,       image_processor=SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       Dict	    =  "lower newer"
      UpperCamelCase__      :       List[str]	    =  self.prepare_image_inputs()

      UpperCamelCase__      :       str	    =  processor(text=SCREAMING_SNAKE_CASE							,       images=SCREAMING_SNAKE_CASE						)

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