




from collections import defaultdict
from pathlib import Path

import pandas as pd
from rouge_cli import calculate_rouge_path

from utils import calculate_rouge


lowercase_             =     [
    'Prosecutor: "No videos were used in the crash investigation" German papers say they saw a cell phone video of the'
    ' final seconds on board Flight 9525. The Germanwings co-pilot says he had a "previous episode of severe'
    ' depression\" German airline confirms it knew of Andreas Lubitz\'s depression years before he took control.',
    'The Palestinian Authority officially becomes the 123rd member of the International Criminal Court. The formal'
    ' accession was marked with a ceremony at The Hague, in the Netherlands. The Palestinians signed the ICC\'s'
    ' founding Rome Statute in January. Israel and the United States opposed the Palestinians\' efforts to join the'
    ' body.',
    'Amnesty International releases its annual report on the death penalty. The report catalogs the use of'
    ' state-sanctioned killing as a punitive measure across the globe. At least 607 people were executed around the'
    ' world in 2014, compared to 778 in 2013. The U.S. remains one of the worst offenders for imposing capital'
    ' punishment.',
]

lowercase_             =     [
    'Marseille prosecutor says "so far no videos were used in the crash investigation" despite media reports .'
    ' Journalists at Bild and Paris Match are "very confident" the video clip is real, an editor says . Andreas Lubitz'
    ' had informed his Lufthansa training school of an episode of severe depression, airline says .',
    'Membership gives the ICC jurisdiction over alleged crimes committed in Palestinian territories since last June .'
    ' Israel and the United States opposed the move, which could open the door to war crimes investigations against'
    ' Israelis .',
    'Amnesty\'s annual death penalty report catalogs encouraging signs, but setbacks in numbers of those sentenced to'
    ' death . Organization claims that governments around the world are using the threat of terrorism to advance'
    ' executions . The number of executions worldwide has gone down by almost 22% compared with 2013, but death'
    ' sentences up by 28% .',
]
def   a   (    )					->   Tuple:





      """simple docstring"""



      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     bootstrap_aggregation=lowercase__   ,     rouge_keys=['rouge2', 'rougeL']  )
      assert isinstance(lowercase__   ,     lowercase__  )
      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     bootstrap_aggregation=lowercase__   ,     rouge_keys=['rouge2']  )
      assert (
          pd.DataFrame(no_aggregation['rouge2']  ).fmeasure.mean()
          == pd.DataFrame(no_aggregation_just_ra['rouge2']  ).fmeasure.mean()
      )
def   a   (    )					->   List[Any]:





      """simple docstring"""



      _lowercase			 ='rougeLsum'
      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     newline_sep=lowercase__   ,     rouge_keys=[k]  )[k]
      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     newline_sep=lowercase__   ,     rouge_keys=[k]  )[k]
      assert score > score_no_sep
def   a   (    )					->   List[str]:





      """simple docstring"""



      _lowercase			 =['rouge1', 'rouge2', 'rougeL']
      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     newline_sep=lowercase__   ,     rouge_keys=lowercase__  )
      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     newline_sep=lowercase__   ,     rouge_keys=lowercase__  )
      assert score_sep == score_no_sep
def   a   (    )					->   Optional[int]:





      """simple docstring"""



      _lowercase			 =[
          'Her older sister, Margot Frank, died in 1945, a month earlier than previously thought.',
          'Marseille prosecutor says \"so far no videos were used in the crash investigation\" despite media reports .',
      ]
      _lowercase			 =[
          'Margot Frank, died in 1945, a month earlier than previously thought.',
          'Prosecutor: \"No videos were used in the crash investigation\" German papers say they saw a cell phone video of'
          ' the final seconds on board Flight 9525.',
      ]
      assert calculate_rouge(lowercase__   ,     lowercase__   ,     newline_sep=lowercase__  ) == calculate_rouge(lowercase__   ,     lowercase__   ,     newline_sep=lowercase__  )
def   a   (    )					->   List[Any]:





      """simple docstring"""



      _lowercase			 =[
          '\" \"a person who has such a video needs to immediately give it to the investigators,\" prosecutor says .<n> \"it is a very disturbing scene,\" editor-in-chief of bild online tells \"erin burnett: outfront\" '
      ]
      _lowercase			 =[
          ' Marseille prosecutor says \"so far no videos were used in the crash investigation\" despite media reports . Journalists at Bild and Paris Match are \"very confident\" the video clip is real, an editor says . Andreas Lubitz had informed his Lufthansa training school of an episode of severe depression, airline says .'
      ]

      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     rouge_keys=['rougeLsum']   ,     newline_sep=lowercase__  )['rougeLsum']
      _lowercase			 =calculate_rouge(lowercase__   ,     lowercase__   ,     rouge_keys=['rougeLsum']  )['rougeLsum']
      assert new_score > prev_score







def   a   (    )					->   Optional[Any]:





      """simple docstring"""



      _lowercase			 =Path('examples/seq2seq/test_data/wmt_en_ro'  )
      _lowercase			 =calculate_rouge_path(data_dir.joinpath('test.source'  )   ,     data_dir.joinpath('test.target'  )  )
      assert isinstance(lowercase__   ,     lowercase__  )
      _lowercase			 =calculate_rouge_path(
          data_dir.joinpath('test.source'  )   ,     data_dir.joinpath('test.target'  )   ,     bootstrap_aggregation=lowercase__  )
      assert isinstance(lowercase__   ,     lowercase__  )





from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import is_tf_available, is_vision_available

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
  from transformers import (
      TFBertModel,
      TFCLIPVisionModel,
      TFDeiTModel,
      TFRobertaModel,
      TFVisionTextDualEncoderModel,
      TFViTModel,
      VisionTextDualEncoderConfig,
  )

if is_vision_available():
  from PIL import Image

  from transformers import VisionTextDualEncoderProcessor
def   a   (    A__			:     List[Any]  )					->   Union[str, Any]:





      """simple docstring"""



      if isinstance(A__   ,     collections.abc.Iterable  ):
            return x
      return (x, x)





@require_tf
class 				__lowerCAmelCase  :




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase      )						->				List[Any]:
        '''simple docstring'''






        pass




  def 						A__  (       self      )						->				str:
        '''simple docstring'''






        pass




  def 						A__  (       self      )						->				Optional[Any]:
        '''simple docstring'''






        pass




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase=None							,     **lowerCAmelCase      )						->				Optional[Any]:
        '''simple docstring'''






        _lowercase			 =VisionTextDualEncoderConfig.from_vision_text_configs(lowerCAmelCase							,     lowerCAmelCase      )

        _lowercase			 =TFVisionTextDualEncoderModel(lowerCAmelCase      )

        _lowercase			 =model(input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase      )

        self.assertEqual(output['text_embeds'].shape							,     (input_ids.shape[0], config.projection_dim)      )
        self.assertEqual(output['image_embeds'].shape							,     (pixel_values.shape[0], config.projection_dim)      )




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase=None							,     **lowerCAmelCase      )						->				int:
        '''simple docstring'''






        _lowercase , _lowercase			 =self.get_vision_text_model(lowerCAmelCase							,     lowerCAmelCase      )
        _lowercase			 =TFVisionTextDualEncoderModel(vision_model=lowerCAmelCase							,     text_model=lowerCAmelCase      )

        _lowercase			 =model(input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase      )

        self.assertEqual(output['text_embeds'].shape							,     (input_ids.shape[0], model.config.projection_dim)      )
        self.assertEqual(output['image_embeds'].shape							,     (pixel_values.shape[0], model.config.projection_dim)      )




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase=None							,     **lowerCAmelCase      )						->				Union[str, Any]:
        '''simple docstring'''






        _lowercase , _lowercase			 =self.get_vision_text_model(lowerCAmelCase							,     lowerCAmelCase      )
        _lowercase			 ={'vision_model': vision_model, 'text_model': text_model}
        _lowercase			 =TFVisionTextDualEncoderModel.from_vision_text_pretrained(**lowerCAmelCase      )

        _lowercase			 =model(input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase      )

        self.assertEqual(output['text_embeds'].shape							,     (input_ids.shape[0], model.config.projection_dim)      )
        self.assertEqual(output['image_embeds'].shape							,     (pixel_values.shape[0], model.config.projection_dim)      )




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase=None							,     **lowerCAmelCase      )						->				int:
        '''simple docstring'''






        _lowercase , _lowercase			 =self.get_vision_text_model(lowerCAmelCase							,     lowerCAmelCase      )
        _lowercase			 =TFVisionTextDualEncoderModel(vision_model=lowerCAmelCase							,     text_model=lowerCAmelCase      )

        _lowercase			 =model(input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase      )
        _lowercase			 =output[0].numpy()

        with tempfile.TemporaryDirectory() as tmpdirname:
              model.save_pretrained(lowerCAmelCase      )
              _lowercase			 =TFVisionTextDualEncoderModel.from_pretrained(lowerCAmelCase      )

              _lowercase			 =model(input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase      )
              _lowercase			 =after_output[0].numpy()
              _lowercase			 =np.amax(np.abs(out_a - out_a      )      )
              self.assertLessEqual(lowerCAmelCase							,     1e-5      )




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase=None							,     **lowerCAmelCase      )						->				Optional[int]:
        '''simple docstring'''






        _lowercase , _lowercase			 =self.get_vision_text_model(lowerCAmelCase							,     lowerCAmelCase      )
        _lowercase			 =TFVisionTextDualEncoderModel(vision_model=lowerCAmelCase							,     text_model=lowerCAmelCase      )

        _lowercase			 =model(
            input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase							,     output_attentions=lowerCAmelCase      )

        _lowercase			 =output.vision_model_output.attentions
        self.assertEqual(len(lowerCAmelCase      )							,     vision_config.num_hidden_layers      )

        # in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
        _lowercase			 =to_atuple(vision_model.config.image_size      )
        _lowercase			 =to_atuple(vision_model.config.patch_size      )
        _lowercase			 =(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
        _lowercase			 =num_patches + 1
        self.assertEqual(vision_attentions[0].shape[-3:]							,     (vision_config.num_attention_heads, seq_len, seq_len)      )

        _lowercase			 =output.text_model_output.attentions
        self.assertEqual(len(lowerCAmelCase      )							,     text_config.num_hidden_layers      )

        self.assertEqual(
            text_attentions[0].shape[-3:]							,     (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])							,     )




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase      )						->				Optional[Any]:
        '''simple docstring'''






        _lowercase			 =np.abs((a - b)      ).max()
        self.assertLessEqual(lowerCAmelCase							,     lowerCAmelCase							,     F'''Difference between torch and flax is {diff} (>= {tol}).'''      )




  def 						A__  (       self      )						->				str:
        '''simple docstring'''






        _lowercase			 =self.prepare_config_and_inputs()
        self.check_vision_text_dual_encoder_model(**lowerCAmelCase      )




  def 						A__  (       self      )						->				int:
        '''simple docstring'''






        _lowercase			 =self.prepare_config_and_inputs()
        self.check_model_from_pretrained_configs(**lowerCAmelCase      )




  def 						A__  (       self      )						->				Union[str, Any]:
        '''simple docstring'''






        _lowercase			 =self.prepare_config_and_inputs()
        self.check_vision_text_dual_encoder_from_pretrained(**lowerCAmelCase      )




  def 						A__  (       self      )						->				List[Any]:
        '''simple docstring'''






        _lowercase			 =self.prepare_config_and_inputs()
        self.check_save_load(**lowerCAmelCase      )




  def 						A__  (       self      )						->				Tuple:
        '''simple docstring'''






        _lowercase			 =self.prepare_config_and_inputs()
        self.check_vision_text_output_attention(**lowerCAmelCase      )




  @slow
  def 						A__  (       self      )						->				Union[str, Any]:
        '''simple docstring'''






        _lowercase , _lowercase			 =self.get_pretrained_model_and_inputs()

        _lowercase			 =model_a(**lowerCAmelCase      )
        _lowercase			 =outputs[0].numpy()

        with tempfile.TemporaryDirectory() as tmp_dirname:
              model_a.save_pretrained(lowerCAmelCase      )
              _lowercase			 =TFVisionTextDualEncoderModel.from_pretrained(lowerCAmelCase      )

              _lowercase			 =model_a(**lowerCAmelCase      )
              _lowercase			 =after_outputs[0].numpy()
              _lowercase			 =np.amax(np.abs(out_a - out_a      )      )
              self.assertLessEqual(lowerCAmelCase							,     1e-5      )





@require_tf
class 				__lowerCAmelCase  (      SCREAMING_SNAKE_CASE    ,    unittest.TestCase							):




  def 						A__  (       self      )						->				List[Any]:
        '''simple docstring'''






        _lowercase			 =TFVisionTextDualEncoderModel.from_vision_text_pretrained(
            'hf-internal-testing/tiny-random-vit'							,     'hf-internal-testing/tiny-random-bert'      )
        _lowercase			 =13
        _lowercase			 =floats_tensor(
            [
                batch_size,
                model.vision_model.config.num_channels,
                model.vision_model.config.image_size,
                model.vision_model.config.image_size,
            ]      )
        _lowercase			 =ids_tensor([batch_size, 4]							,     model.text_model.config.vocab_size      )
        _lowercase			 =random_attention_mask([batch_size, 4]      )
        _lowercase			 ={'pixel_values': pixel_values, 'input_ids': input_ids, 'attention_mask': attention_mask}

        return model, inputs




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase      )						->				List[Any]:
        '''simple docstring'''






        _lowercase			 =TFViTModel(lowerCAmelCase							,     name='vision_model'      )
        _lowercase			 =TFBertModel(lowerCAmelCase							,     name='text_model'      )
        return vision_model, text_model




  def 						A__  (       self      )						->				Any:
        '''simple docstring'''






        _lowercase			 =TFViTModelTester(self      )
        _lowercase			 =TFBertModelTester(self      )
        _lowercase			 =vit_model_tester.prepare_config_and_inputs()
        _lowercase			 =bert_model_tester.prepare_config_and_inputs()

        _lowercase , _lowercase , _lowercase			 =vision_config_and_inputs

        (
            (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , 
        )			 =text_config_and_inputs

        return {
            "text_config": text_config,
            "vision_config": vision_config,
            "pixel_values": pixel_values,
            "attention_mask": input_mask,
            "input_ids": input_ids,
            "text_token_type_ids": token_type_ids,
            "text_sequence_labels": sequence_labels,
            "text_token_labels": token_labels,
            "text_choice_labels": choice_labels,
        }





@require_tf
class 				__lowerCAmelCase  (      SCREAMING_SNAKE_CASE    ,    unittest.TestCase							):




  def 						A__  (       self      )						->				str:
        '''simple docstring'''






        _lowercase			 =TFVisionTextDualEncoderModel.from_vision_text_pretrained(
            'Rocketknight1/tiny-random-deit-tf'							,     'hf-internal-testing/tiny-random-roberta'      )
        _lowercase			 =13
        _lowercase			 =floats_tensor(
            [
                batch_size,
                model.vision_model.config.num_channels,
                model.vision_model.config.image_size,
                model.vision_model.config.image_size,
            ]      )
        _lowercase			 =ids_tensor([batch_size, 4]							,     model.text_model.config.vocab_size      )
        _lowercase			 =random_attention_mask([batch_size, 4]      )
        _lowercase			 ={'pixel_values': pixel_values, 'input_ids': input_ids, 'attention_mask': attention_mask}

        return model, inputs




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase							,     lowerCAmelCase=None							,     **lowerCAmelCase      )						->				List[str]:
        '''simple docstring'''






        _lowercase , _lowercase			 =self.get_vision_text_model(lowerCAmelCase							,     lowerCAmelCase      )
        _lowercase			 =TFVisionTextDualEncoderModel(vision_model=lowerCAmelCase							,     text_model=lowerCAmelCase      )

        _lowercase			 =model(
            input_ids=lowerCAmelCase							,     pixel_values=lowerCAmelCase							,     attention_mask=lowerCAmelCase							,     output_attentions=lowerCAmelCase      )

        _lowercase			 =output.vision_model_output.attentions
        self.assertEqual(len(lowerCAmelCase      )							,     vision_config.num_hidden_layers      )

        # in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
        _lowercase			 =to_atuple(vision_model.config.image_size      )
        _lowercase			 =to_atuple(vision_model.config.patch_size      )
        _lowercase			 =(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
        _lowercase			 =num_patches + 2
        self.assertEqual(vision_attentions[0].shape[-3:]							,     (vision_config.num_attention_heads, seq_len, seq_len)      )

        _lowercase			 =output.text_model_output.attentions
        self.assertEqual(len(lowerCAmelCase      )							,     text_config.num_hidden_layers      )

        self.assertEqual(
            text_attentions[0].shape[-3:]							,     (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])							,     )




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase      )						->				Tuple:
        '''simple docstring'''






        _lowercase			 =TFDeiTModel(lowerCAmelCase							,     name='vision_model'      )
        _lowercase			 =TFRobertaModel(lowerCAmelCase							,     name='text_model'      )
        return vision_model, text_model




  def 						A__  (       self      )						->				Any:
        '''simple docstring'''






        _lowercase			 =TFDeiTModelTester(self      )
        _lowercase			 =TFRobertaModelTester(self      )
        _lowercase			 =vit_model_tester.prepare_config_and_inputs()
        _lowercase			 =bert_model_tester.prepare_config_and_inputs()

        _lowercase , _lowercase , _lowercase			 =vision_config_and_inputs

        (
            (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , 
        )			 =text_config_and_inputs

        return {
            "text_config": text_config,
            "vision_config": vision_config,
            "pixel_values": pixel_values,
            "attention_mask": input_mask,
            "input_ids": input_ids,
            "text_token_type_ids": token_type_ids,
            "text_sequence_labels": sequence_labels,
            "text_token_labels": token_labels,
            "text_choice_labels": choice_labels,
        }





@require_tf
class 				__lowerCAmelCase  (      SCREAMING_SNAKE_CASE    ,    unittest.TestCase							):




  def 						A__  (       self      )						->				str:
        '''simple docstring'''






        _lowercase			 =TFVisionTextDualEncoderModel.from_vision_text_pretrained(
            'Rocketknight1/tiny-random-clip-tf'							,     'hf-internal-testing/tiny-random-bert'      )
        _lowercase			 =13
        _lowercase			 =floats_tensor(
            [
                batch_size,
                model.vision_model.config.num_channels,
                model.vision_model.config.image_size,
                model.vision_model.config.image_size,
            ]      )
        _lowercase			 =ids_tensor([batch_size, 4]							,     model.text_model.config.vocab_size      )
        _lowercase			 =random_attention_mask([batch_size, 4]      )
        _lowercase			 ={'pixel_values': pixel_values, 'input_ids': input_ids, 'attention_mask': attention_mask}

        return model, inputs




  def 						A__  (       self							,     lowerCAmelCase							,     lowerCAmelCase      )						->				Tuple:
        '''simple docstring'''






        _lowercase			 =TFCLIPVisionModel(lowerCAmelCase							,     name='vision_model'      )
        _lowercase			 =TFBertModel(lowerCAmelCase							,     name='text_model'      )
        return vision_model, text_model




  def 						A__  (       self      )						->				str:
        '''simple docstring'''






        _lowercase			 =TFCLIPVisionModelTester(self      )
        _lowercase			 =TFBertModelTester(self      )
        _lowercase			 =clip_model_tester.prepare_config_and_inputs()
        _lowercase			 =bert_model_tester.prepare_config_and_inputs()

        _lowercase , _lowercase			 =vision_config_and_inputs

        (
            (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , (
            _lowercase
        ) , 
        )			 =text_config_and_inputs

        return {
            "text_config": text_config,
            "vision_config": vision_config,
            "pixel_values": pixel_values,
            "attention_mask": input_mask,
            "input_ids": input_ids,
            "text_token_type_ids": token_type_ids,
            "text_sequence_labels": sequence_labels,
            "text_token_labels": token_labels,
            "text_choice_labels": choice_labels,
        }





@require_vision
@require_tf
class 				__lowerCAmelCase  (      unittest.TestCase							):




  @slow
  def 						A__  (       self      )						->				Optional[int]:
        '''simple docstring'''






        _lowercase			 =TFVisionTextDualEncoderModel.from_pretrained(
            'clip-italian/clip-italian'							,     logit_scale_init_value=1.0							,     from_pt=lowerCAmelCase      )
        _lowercase			 =VisionTextDualEncoderProcessor.from_pretrained('clip-italian/clip-italian'      )

        _lowercase			 =Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'      )
        _lowercase			 =processor(
            text=['una foto di un gatto', 'una foto di un cane']							,     images=lowerCAmelCase							,     padding=lowerCAmelCase							,     return_tensors='np'      )

        _lowercase			 =model(**lowerCAmelCase      )

        # verify the logits
        self.assertEqual(outputs.logits_per_image.shape							,     (inputs.pixel_values.shape[0], inputs.input_ids.shape[0])      )
        self.assertEqual(
            outputs.logits_per_text.shape							,     (inputs.input_ids.shape[0], inputs.pixel_values.shape[0])							,     )

        _lowercase			 =np.array([[1.2284727, 0.3104122]]      )

        self.assertTrue(np.allclose(outputs.logits_per_image.numpy()							,     lowerCAmelCase							,     atol=1e-3      )      )


