code: from __future__ import annotations
  
  import unittest
  
  from transformers import is_tf_available
  from transformers.testing_utils import require_tf, slow
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_tf_available():
  		import tensorflow as tf
  
  		from transformers import (
  		    TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
  		    TFXLMForMultipleChoice,
  		    TFXLMForQuestionAnsweringSimple,
  		    TFXLMForSequenceClassification,
  		    TFXLMForTokenClassification,
  		    TFXLMModel,
  		    TFXLMWithLMHeadModel,
  		    XLMConfig,
  		)
  
  
  
  
  class 					UpperCamelCase	:
  
  
  
  
  					def __init__( self :					int      ,_lowerCAmelCase :					Any      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     parent
  							__snake_case		       =     13
  							__snake_case		       =     7
  							__snake_case		       =     True
  							__snake_case		       =     True
  							__snake_case		       =     True
  							__snake_case		       =     True
  							__snake_case		       =     True
  							__snake_case		       =     False
  							__snake_case		       =     False
  							__snake_case		       =     False
  							__snake_case		       =     2
  							__snake_case		       =     99
  							__snake_case		       =     0
  							__snake_case		       =     32
  							__snake_case		       =     2
  							__snake_case		       =     4
  							__snake_case		       =     0.1
  							__snake_case		       =     0.1
  							__snake_case		       =     512
  							__snake_case		       =     16
  							__snake_case		       =     2
  							__snake_case		       =     0.0_2
  							__snake_case		       =     3
  							__snake_case		       =     4
  							__snake_case		       =     "last"
  							__snake_case		       =     True
  							__snake_case		       =     None
  							__snake_case		       =     0
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size						)
  							__snake_case		       =     random_attention_mask([self.batch_size, self.seq_length]      ,dtype=tf.floataa						)
  
  							__snake_case		       =     None
  							if self.use_input_lengths:
  									__snake_case		       =     (
  									    ids_tensor([self.batch_size]      ,vocab_size=2						) + self.seq_length - 2
  									)  # small variation of seq_length
  
  							__snake_case		       =     None
  							if self.use_token_type_ids:
  									__snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,self.n_langs						)
  
  							__snake_case		       =     None
  							__snake_case		       =     None
  							__snake_case		       =     None
  							if self.use_labels:
  									__snake_case		       =     ids_tensor([self.batch_size]      ,self.type_sequence_label_size						)
  									__snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,self.num_labels						)
  									__snake_case		       =     ids_tensor([self.batch_size]      ,2      ,dtype=tf.floataa						)
  									__snake_case		       =     ids_tensor([self.batch_size]      ,self.num_choices						)
  
  							__snake_case		       =     XLMConfig(
  							    vocab_size=self.vocab_size      ,n_special=self.n_special      ,emb_dim=self.hidden_size      ,n_layers=self.num_hidden_layers      ,n_heads=self.num_attention_heads      ,dropout=self.hidden_dropout_prob      ,attention_dropout=self.attention_probs_dropout_prob      ,gelu_activation=self.gelu_activation      ,sinusoidal_embeddings=self.sinusoidal_embeddings      ,asm=self.asm      ,causal=self.causal      ,n_langs=self.n_langs      ,max_position_embeddings=self.max_position_embeddings      ,initializer_range=self.initializer_range      ,summary_type=self.summary_type      ,use_proj=self.use_proj      ,bos_token_id=self.bos_token_id      ,)
  
  							return (
  							    config,
  							    input_ids,
  							    token_type_ids,
  							    input_lengths,
  							    sequence_labels,
  							    token_labels,
  							    is_impossible_labels,
  							    choice_labels,
  							    input_mask,
  							)
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[str]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Union[str, Any]      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     TFXLMModel(config=_lowerCAmelCase						)
  							__snake_case		       =     {"input_ids": input_ids, "lengths": input_lengths, "langs": token_type_ids}
  							__snake_case		       =     model(_lowerCAmelCase						)
  
  							__snake_case		       =     [input_ids, input_mask]
  							__snake_case		       =     model(_lowerCAmelCase						)
  							self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					List[Any]      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     TFXLMWithLMHeadModel(_lowerCAmelCase						)
  
  							__snake_case		       =     {"input_ids": input_ids, "lengths": input_lengths, "langs": token_type_ids}
  							__snake_case		       =     model(_lowerCAmelCase						)
  
  							__snake_case		       =     outputs
  
  							self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[Any]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					List[str]      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     TFXLMForQuestionAnsweringSimple(_lowerCAmelCase						)
  
  							__snake_case		       =     {"input_ids": input_ids, "lengths": input_lengths}
  
  							__snake_case		       =     model(_lowerCAmelCase						)
  
  							self.parent.assertEqual(result.start_logits.shape      ,(self.batch_size, self.seq_length)						)
  							self.parent.assertEqual(result.end_logits.shape      ,(self.batch_size, self.seq_length)						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					int      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Optional[Any]      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     TFXLMForSequenceClassification(_lowerCAmelCase						)
  
  							__snake_case		       =     {"input_ids": input_ids, "lengths": input_lengths}
  
  							__snake_case		       =     model(_lowerCAmelCase						)
  
  							self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.type_sequence_label_size)						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					int      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.num_labels
  							__snake_case		       =     TFXLMForTokenClassification(config=_lowerCAmelCase						)
  							__snake_case		       =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
  							__snake_case		       =     model(_lowerCAmelCase						)
  							self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length, self.num_labels)						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[Any]      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					int      ,):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.num_choices
  							__snake_case		       =     TFXLMForMultipleChoice(config=_lowerCAmelCase						)
  							__snake_case		       =     tf.tile(tf.expand_dims(_lowerCAmelCase      ,1						)      ,(1, self.num_choices, 1)						)
  							__snake_case		       =     tf.tile(tf.expand_dims(_lowerCAmelCase      ,1						)      ,(1, self.num_choices, 1)						)
  							__snake_case		       =     tf.tile(tf.expand_dims(_lowerCAmelCase      ,1						)      ,(1, self.num_choices, 1)						)
  							__snake_case		       =     {
  							    "input_ids": multiple_choice_inputs_ids,
  							    "attention_mask": multiple_choice_input_mask,
  							    "token_type_ids": multiple_choice_token_type_ids,
  							}
  							__snake_case		       =     model(_lowerCAmelCase						)
  							self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_choices)						)
  
  
  
  
  
  
  
  					def 							UpperCamelCase_						( self :					Dict						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.prepare_config_and_inputs()
  							(
  							    (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       (
  							    __snake_case
  							)       ,       
  							)		       =     config_and_inputs
  							__snake_case		       =     {
  							    "input_ids": input_ids,
  							    "token_type_ids": token_type_ids,
  							    "langs": token_type_ids,
  							    "lengths": input_lengths,
  							}
  							return config, inputs_dict
  
  
  
  
  @require_tf
  class 					UpperCamelCase	(     snake_case__			,      snake_case__			,      unittest.TestCase      ):
  					__UpperCamelCase						=   (
  					    (
  					        TFXLMModel,
  					        TFXLMWithLMHeadModel,
  					        TFXLMForSequenceClassification,
  					        TFXLMForQuestionAnsweringSimple,
  					        TFXLMForTokenClassification,
  					        TFXLMForMultipleChoice,
  					    )
  					    if is_tf_available()
  					    else ()
  					)
  					__UpperCamelCase						=   (
  					    (TFXLMWithLMHeadModel,) if is_tf_available() else ()
  					)  # TODO (PVP): Check other models whether language generation is also applicable
  					__UpperCamelCase						=   (
  					    {
  					        """feature-extraction""": TFXLMModel,
  					        """fill-mask""": TFXLMWithLMHeadModel,
  					        """question-answering""": TFXLMForQuestionAnsweringSimple,
  					        """text-classification""": TFXLMForSequenceClassification,
  					        """text-generation""": TFXLMWithLMHeadModel,
  					        """token-classification""": TFXLMForTokenClassification,
  					        """zero-shot""": TFXLMForSequenceClassification,
  					    }
  					    if is_tf_available()
  					    else {}
  					)
  					__UpperCamelCase						=   False
  					__UpperCamelCase						=   False
  
  
  
  
  					def 							UpperCamelCase_						( self :					Union[str, Any]      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Union[str, Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							if (
  							    pipeline_test_casse_name == "QAPipelineTests"
  							    and tokenizer_name is not None
  							    and not tokenizer_name.endswith("Fast"						)
  							):
  									# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
  									# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
  									# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
  									return True
  
  							return False
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     TFXLMModelTester(self						)
  							__snake_case		       =     ConfigTester(self      ,config_class=_lowerCAmelCase      ,emb_dim=37						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							self.config_tester.run_common_tests()
  
  
  
  
  					def 							UpperCamelCase_						( self :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_xlm_model(*_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Dict						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_xlm_lm_head(*_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Union[str, Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_xlm_qa(*_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_xlm_sequence_classif(*_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_xlm_for_token_classification(*_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_xlm_for_multiple_choice(*_lowerCAmelCase						)
  
  
  
  
  
  
  
  					@slow
  					def 							UpperCamelCase_						( self :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  									__snake_case		       =     TFXLMModel.from_pretrained(_lowerCAmelCase						)
  									self.assertIsNotNone(_lowerCAmelCase						)
  
  
  
  
  @require_tf
  class 					UpperCamelCase	(     unittest.TestCase      ):
  
  
  
  
  					@slow
  					def 							UpperCamelCase_						( self :					Optional[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     TFXLMWithLMHeadModel.from_pretrained("xlm-mlm-en-2048"						)
  							__snake_case		       =     tf.convert_to_tensor([[14, 447]]      ,dtype=tf.intaa						)  # the president
  							__snake_case		       =     [
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							    14,
  							    447,
  							]  # the president the president the president the president the president the president the president the president the president the president
  							# TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference
  							__snake_case		       =     model.generate(_lowerCAmelCase      ,do_sample=_lowerCAmelCase						)
  							self.assertListEqual(output_ids[0].numpy().tolist()      ,_lowerCAmelCase						)
  
  
  
  
  
  
style_context: import shutil
  import tempfile
  import unittest
  
  import numpy as np
  import pytest
  
  from transformers.testing_utils import require_torch, require_vision
  from transformers.utils import is_torch_available, is_vision_available
  
  
  if is_torch_available():
  		from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
  else:
  		lowerCamelCase__           =				False
  
  if is_vision_available():
  		from PIL import Image
  
  		from transformers import (
  		    AutoProcessor,
  		    PixaStructImageProcessor,
  		    PixaStructProcessor,
  		    PreTrainedTokenizerFast,
  		    TaTokenizer,
  		)
  
  
  
  
  @unittest.skipIf(
      not is_torch_greater_or_equal_than_1_11			,      reason="""`Pix2StructImageProcessor` requires `torch>=1.11.0`."""			,      )
  @require_vision
  @require_torch
  class 					UpperCamelCase	(     unittest.TestCase      ):
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     tempfile.mkdtemp()
  
  							__snake_case		       =     PixaStructImageProcessor()
  							__snake_case		       =     TaTokenizer.from_pretrained("t5-small"						)
  
  							__snake_case		       =     PixaStructProcessor(_lowerCAmelCase      ,_lowerCAmelCase						)
  
  							processor.save_pretrained(self.tmpdirname						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Dict      ,**_lowerCAmelCase :					List[str]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							return AutoProcessor.from_pretrained(self.tmpdirname      ,**_lowerCAmelCase						).tokenizer
  
  
  
  
  					def 							UpperCamelCase_						( self :					Any      ,**_lowerCAmelCase :					List[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							return AutoProcessor.from_pretrained(self.tmpdirname      ,**_lowerCAmelCase						).image_processor
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							shutil.rmtree(self.tmpdirname						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     [np.random.randint(255      ,size=(3, 30, 400)      ,dtype=np.uinta						)]
  
  							__snake_case		       =     [Image.fromarray(np.moveaxis(_lowerCAmelCase      ,0      ,-1						)						) for x in image_inputs]
  
  							return image_inputs
  
  
  
  
  					def 							UpperCamelCase_						( self :					Any						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=self.get_tokenizer()      ,image_processor=self.get_image_processor()						)
  							processor.save_pretrained(self.tmpdirname						)
  
  							__snake_case		       =     self.get_tokenizer(bos_token="(BOS)"      ,eos_token="(EOS)"						)
  							__snake_case		       =     self.get_image_processor(do_normalize=_lowerCAmelCase      ,padding_value=1.0						)
  
  							__snake_case		       =     PixaStructProcessor.from_pretrained(
  							    self.tmpdirname      ,bos_token="(BOS)"      ,eos_token="(EOS)"      ,do_normalize=_lowerCAmelCase      ,padding_value=1.0						)
  
  							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 							UpperCamelCase_						( self :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_image_processor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=_lowerCAmelCase      ,image_processor=_lowerCAmelCase						)
  
  							__snake_case		       =     self.prepare_image_inputs()
  
  							__snake_case		       =     image_processor(_lowerCAmelCase      ,return_tensors="np"						)
  							__snake_case		       =     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 							UpperCamelCase_						( self :					List[str]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_image_processor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=_lowerCAmelCase      ,image_processor=_lowerCAmelCase						)
  
  							__snake_case		       =     "lower newer"
  
  							__snake_case		       =     processor(text=_lowerCAmelCase						)
  
  							__snake_case		       =     tokenizer(_lowerCAmelCase      ,return_token_type_ids=_lowerCAmelCase      ,add_special_tokens=_lowerCAmelCase						)
  
  							for key in encoded_tok.keys():
  									self.assertListEqual(encoded_tok[key]      ,encoded_processor[key]						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Any						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_image_processor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=_lowerCAmelCase      ,image_processor=_lowerCAmelCase						)
  
  							__snake_case		       =     "lower newer"
  							__snake_case		       =     self.prepare_image_inputs()
  
  							__snake_case		       =     processor(text=_lowerCAmelCase      ,images=_lowerCAmelCase						)
  
  							self.assertListEqual(
  							    list(inputs.keys()						)      ,["flattened_patches", "attention_mask", "decoder_attention_mask", "decoder_input_ids"]						)
  
  							# test if it raises when no input is passed
  							with pytest.raises(_lowerCAmelCase						):
  									processor()
  
  
  
  
  					def 							UpperCamelCase_						( self :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_image_processor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=_lowerCAmelCase      ,image_processor=_lowerCAmelCase						)
  
  							__snake_case		       =     "lower newer"
  							__snake_case		       =     self.prepare_image_inputs()
  
  							__snake_case		       =     processor(text=_lowerCAmelCase      ,images=_lowerCAmelCase						)
  
  							__snake_case		       =     [512, 1_024, 2_048, 4_096]
  							__snake_case		       =     [770, 770, 770, 770]
  							# with text
  							for i, max_patch in enumerate(_lowerCAmelCase						):
  									__snake_case		       =     processor(text=_lowerCAmelCase      ,images=_lowerCAmelCase      ,max_patches=_lowerCAmelCase						)
  									self.assertEqual(inputs["flattened_patches"][0].shape[0]      ,_lowerCAmelCase						)
  									self.assertEqual(inputs["flattened_patches"][0].shape[1]      ,expected_hidden_size[i]						)
  
  							# without text input
  							for i, max_patch in enumerate(_lowerCAmelCase						):
  									__snake_case		       =     processor(images=_lowerCAmelCase      ,max_patches=_lowerCAmelCase						)
  									self.assertEqual(inputs["flattened_patches"][0].shape[0]      ,_lowerCAmelCase						)
  									self.assertEqual(inputs["flattened_patches"][0].shape[1]      ,expected_hidden_size[i]						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Union[str, Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_image_processor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=_lowerCAmelCase      ,image_processor=_lowerCAmelCase						)
  
  							__snake_case		       =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  							__snake_case		       =     processor.batch_decode(_lowerCAmelCase						)
  							__snake_case		       =     tokenizer.batch_decode(_lowerCAmelCase						)
  
  							self.assertListEqual(_lowerCAmelCase      ,_lowerCAmelCase						)
  
  
  
  
  
  
  
  					def 							UpperCamelCase_						( self :					Tuple						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_image_processor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     PixaStructProcessor(tokenizer=_lowerCAmelCase      ,image_processor=_lowerCAmelCase						)
  
  							__snake_case		       =     "lower newer"
  							__snake_case		       =     self.prepare_image_inputs()
  
  							__snake_case		       =     processor(text=_lowerCAmelCase      ,images=_lowerCAmelCase						)
  
  							# For now the processor supports only ["flattened_patches", "input_ids", "attention_mask", "decoder_attention_mask"]
  							self.assertListEqual(
  							    list(inputs.keys()						)      ,["flattened_patches", "attention_mask", "decoder_attention_mask", "decoder_input_ids"]						)
  
  							__snake_case		       =     processor(text=_lowerCAmelCase						)
  
  							# For now the processor supports only ["flattened_patches", "input_ids", "attention_mask", "decoder_attention_mask"]
  							self.assertListEqual(list(inputs.keys()						)      ,["input_ids", "attention_mask"]						)
  
  
  
  
  
  