






from __future__ import annotations

import copy
import inspect
import unittest

import numpy as np

from transformers import is_tf_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import (
			    TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
			    TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
			    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
			    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
			    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
			    LayoutLMvaConfig,
			    TFLayoutLMvaForQuestionAnswering,
			    TFLayoutLMvaForSequenceClassification,
			    TFLayoutLMvaForTokenClassification,
			    TFLayoutLMvaModel,
			)

if is_vision_available():
			from PIL import Image

			from transformers import LayoutLMvaImageProcessor


class  SCREAMING_SNAKE_CASE			:
					'''simple docstring'''


					def __init__(				self       :	List[Any]					, UpperCAmelCase_       :	Union[str, Any]					, UpperCAmelCase_       :	Any=2					, UpperCAmelCase_       :	List[Any]=3					, UpperCAmelCase_       :	Tuple=4					, UpperCAmelCase_       :	Union[str, Any]=2					, UpperCAmelCase_       :	int=7					, UpperCAmelCase_       :	Optional[Any]=True					, UpperCAmelCase_       :	Optional[int]=True					, UpperCAmelCase_       :	Optional[int]=True					, UpperCAmelCase_       :	Tuple=True					, UpperCAmelCase_       :	List[str]=99					, UpperCAmelCase_       :	Dict=36					, UpperCAmelCase_       :	List[Any]=2					, UpperCAmelCase_       :	List[Any]=4					, UpperCAmelCase_       :	List[str]=37					, UpperCAmelCase_       :	List[Any]="gelu"					, UpperCAmelCase_       :	List[str]=0.1					, UpperCAmelCase_       :	Any=0.1					, UpperCAmelCase_       :	Optional[Any]=512					, UpperCAmelCase_       :	str=16					, UpperCAmelCase_       :	Optional[int]=2					, UpperCAmelCase_       :	int=0.02					, UpperCAmelCase_       :	Tuple=6					, UpperCAmelCase_       :	Any=6					, UpperCAmelCase_       :	Tuple=3					, UpperCAmelCase_       :	Union[str, Any]=4					, UpperCAmelCase_       :	Optional[Any]=None					, UpperCAmelCase_       :	Union[str, Any]=1000					, ):
							SCREAMING_SNAKE_CASE       :      str							=    parent
							SCREAMING_SNAKE_CASE       :      str							=    batch_size
							SCREAMING_SNAKE_CASE       :      Tuple							=    num_channels
							SCREAMING_SNAKE_CASE       :      Tuple							=    image_size
							SCREAMING_SNAKE_CASE       :      Tuple							=    patch_size
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    is_training
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    use_input_mask
							SCREAMING_SNAKE_CASE       :      int							=    use_token_type_ids
							SCREAMING_SNAKE_CASE       :      Any							=    use_labels
							SCREAMING_SNAKE_CASE       :      str							=    vocab_size
							SCREAMING_SNAKE_CASE       :      Optional[int]							=    hidden_size
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    num_hidden_layers
							SCREAMING_SNAKE_CASE       :      List[Any]							=    num_attention_heads
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    intermediate_size
							SCREAMING_SNAKE_CASE       :      Tuple							=    hidden_act
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    hidden_dropout_prob
							SCREAMING_SNAKE_CASE       :      List[Any]							=    attention_probs_dropout_prob
							SCREAMING_SNAKE_CASE       :      List[str]							=    max_position_embeddings
							SCREAMING_SNAKE_CASE       :      Optional[int]							=    type_vocab_size
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    type_sequence_label_size
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    initializer_range
							SCREAMING_SNAKE_CASE       :      str							=    coordinate_size
							SCREAMING_SNAKE_CASE       :      List[Any]							=    shape_size
							SCREAMING_SNAKE_CASE       :      Dict							=    num_labels
							SCREAMING_SNAKE_CASE       :      Dict							=    num_choices
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    scope
							SCREAMING_SNAKE_CASE       :      List[Any]							=    range_bbox

							# LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    text_seq_length
							SCREAMING_SNAKE_CASE       :      Optional[int]							=    (image_size // patch_size) ** 2 + 1
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    self.text_seq_length + self.image_seq_length


					def 				_A       (				self       :	Tuple      ):
							SCREAMING_SNAKE_CASE       :      Tuple							=    ids_tensor([self.batch_size, self.text_seq_length]					, self.vocab_size      )

							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    ids_tensor([self.batch_size, self.text_seq_length, 4]					, self.range_bbox      )
							SCREAMING_SNAKE_CASE       :      str							=    bbox.numpy()
							# Ensure that bbox is legal
							for i in range(bbox.shape[0]      ):
									for j in range(bbox.shape[1]      ):
											if bbox[i, j, 3] < bbox[i, j, 1]:
													SCREAMING_SNAKE_CASE       :      Optional[Any]							=    bbox[i, j, 3]
													SCREAMING_SNAKE_CASE       :      str							=    bbox[i, j, 1]
													SCREAMING_SNAKE_CASE       :      Any							=    tmp_coordinate
											if bbox[i, j, 2] < bbox[i, j, 0]:
													SCREAMING_SNAKE_CASE       :      List[Any]							=    bbox[i, j, 2]
													SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    bbox[i, j, 0]
													SCREAMING_SNAKE_CASE       :      Tuple							=    tmp_coordinate
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    tf.constant(UpperCAmelCase_      )

							SCREAMING_SNAKE_CASE       :      Any							=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

							SCREAMING_SNAKE_CASE       :      Tuple							=    None
							if self.use_input_mask:
									SCREAMING_SNAKE_CASE       :      int							=    random_attention_mask([self.batch_size, self.text_seq_length]      )

							SCREAMING_SNAKE_CASE       :      Optional[int]							=    None
							if self.use_token_type_ids:
									SCREAMING_SNAKE_CASE       :      Any							=    ids_tensor([self.batch_size, self.text_seq_length]					, self.type_vocab_size      )

							SCREAMING_SNAKE_CASE       :      Any							=    None
							SCREAMING_SNAKE_CASE       :      Tuple							=    None
							if self.use_labels:
									SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    ids_tensor([self.batch_size]					, self.type_sequence_label_size      )
									SCREAMING_SNAKE_CASE       :      str							=    ids_tensor([self.batch_size, self.text_seq_length]					, self.num_labels      )

							SCREAMING_SNAKE_CASE       :      Tuple							=    LayoutLMvaConfig(
							    vocab_size=self.vocab_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					, max_position_embeddings=self.max_position_embeddings					, type_vocab_size=self.type_vocab_size					, initializer_range=self.initializer_range					, coordinate_size=self.coordinate_size					, shape_size=self.shape_size					, input_size=self.image_size					, patch_size=self.patch_size					, )

							return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels


					def 				_A       (				self       :	str					, UpperCAmelCase_       :	Any					, UpperCAmelCase_       :	int					, UpperCAmelCase_       :	List[str]					, UpperCAmelCase_       :	Dict					, UpperCAmelCase_       :	Optional[Any]					, UpperCAmelCase_       :	Any      ):
							SCREAMING_SNAKE_CASE       :      int							=    TFLayoutLMvaModel(config=UpperCAmelCase_      )

							# text + image
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    model(UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, training=UpperCAmelCase_      )
							SCREAMING_SNAKE_CASE       :      Dict							=    model(
							    UpperCAmelCase_					, bbox=UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, attention_mask=UpperCAmelCase_					, token_type_ids=UpperCAmelCase_					, training=UpperCAmelCase_					, )
							SCREAMING_SNAKE_CASE       :      Dict							=    model(UpperCAmelCase_					, bbox=UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, training=UpperCAmelCase_      )

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

							# text only
							SCREAMING_SNAKE_CASE       :      int							=    model(UpperCAmelCase_					, training=UpperCAmelCase_      )
							self.parent.assertEqual(
							    result.last_hidden_state.shape					, (self.batch_size, self.text_seq_length, self.hidden_size)      )

							# image only
							SCREAMING_SNAKE_CASE       :      List[Any]							=    model({"pixel_values": pixel_values}					, training=UpperCAmelCase_      )
							self.parent.assertEqual(
							    result.last_hidden_state.shape					, (self.batch_size, self.image_seq_length, self.hidden_size)      )


					def 				_A       (				self       :	Optional[int]					, UpperCAmelCase_       :	str					, UpperCAmelCase_       :	Union[str, Any]					, UpperCAmelCase_       :	int					, UpperCAmelCase_       :	str					, UpperCAmelCase_       :	Union[str, Any]					, UpperCAmelCase_       :	Union[str, Any]					, UpperCAmelCase_       :	Optional[int]      ):
							SCREAMING_SNAKE_CASE       :      List[Any]							=    self.num_labels
							SCREAMING_SNAKE_CASE       :      int							=    TFLayoutLMvaForSequenceClassification(config=UpperCAmelCase_      )
							SCREAMING_SNAKE_CASE       :      int							=    model(
							    UpperCAmelCase_					, bbox=UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, attention_mask=UpperCAmelCase_					, token_type_ids=UpperCAmelCase_					, labels=UpperCAmelCase_					, training=UpperCAmelCase_					, )
							self.parent.assertEqual(result.logits.shape					, (self.batch_size, self.num_labels)      )


					def 				_A       (				self       :	str					, UpperCAmelCase_       :	Union[str, Any]					, UpperCAmelCase_       :	Optional[int]					, UpperCAmelCase_       :	Tuple					, UpperCAmelCase_       :	Dict					, UpperCAmelCase_       :	str					, UpperCAmelCase_       :	Tuple					, UpperCAmelCase_       :	List[str]      ):
							SCREAMING_SNAKE_CASE       :      List[Any]							=    self.num_labels
							SCREAMING_SNAKE_CASE       :      List[str]							=    TFLayoutLMvaForTokenClassification(config=UpperCAmelCase_      )
							SCREAMING_SNAKE_CASE       :      Tuple							=    model(
							    UpperCAmelCase_					, bbox=UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, attention_mask=UpperCAmelCase_					, token_type_ids=UpperCAmelCase_					, labels=UpperCAmelCase_					, training=UpperCAmelCase_					, )
							self.parent.assertEqual(result.logits.shape					, (self.batch_size, self.text_seq_length, self.num_labels)      )


					def 				_A       (				self       :	Tuple					, UpperCAmelCase_       :	List[Any]					, UpperCAmelCase_       :	str					, UpperCAmelCase_       :	List[Any]					, UpperCAmelCase_       :	str					, UpperCAmelCase_       :	Optional[Any]					, UpperCAmelCase_       :	Optional[int]					, UpperCAmelCase_       :	List[str]      ):
							SCREAMING_SNAKE_CASE       :      int							=    2
							SCREAMING_SNAKE_CASE       :      List[Any]							=    TFLayoutLMvaForQuestionAnswering(config=UpperCAmelCase_      )
							SCREAMING_SNAKE_CASE       :      List[Any]							=    model(
							    UpperCAmelCase_					, bbox=UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, attention_mask=UpperCAmelCase_					, token_type_ids=UpperCAmelCase_					, start_positions=UpperCAmelCase_					, end_positions=UpperCAmelCase_					, training=UpperCAmelCase_					, )
							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 				_A       (				self       :	Optional[int]      ):
							SCREAMING_SNAKE_CASE       :      Optional[int]							=    self.prepare_config_and_inputs()
							(SCREAMING_SNAKE_CASE)       :      Dict							=    config_and_inputs
							SCREAMING_SNAKE_CASE       :      Tuple							=    {
							    "input_ids": input_ids,
							    "bbox": bbox,
							    "pixel_values": pixel_values,
							    "token_type_ids": token_type_ids,
							    "attention_mask": input_mask,
							}
							return config, inputs_dict





@require_tf
class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase      ,		lowerCAmelCase      ,		unittest.TestCase					):
					'''simple docstring'''


					UpperCamelCase_							:		Any			=	(
					    (
					        TFLayoutLMvaModel,
					        TFLayoutLMvaForQuestionAnswering,
					        TFLayoutLMvaForSequenceClassification,
					        TFLayoutLMvaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					UpperCamelCase_							:		Tuple			=	(
					    {'''document-question-answering''': TFLayoutLMvaForQuestionAnswering, '''feature-extraction''': TFLayoutLMvaModel}
					    if is_tf_available()
					    else {}
					)

					UpperCamelCase_							:		Union[str, Any]			=	False
					UpperCamelCase_							:		Tuple			=	False
					UpperCamelCase_							:		Union[str, Any]			=	False


					def 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	List[str]					, UpperCAmelCase_       :	Optional[Any]					, UpperCAmelCase_       :	Dict					, UpperCAmelCase_       :	List[Any]					, UpperCAmelCase_       :	str      ):
							return True


					def 				_A       (				self       :	int					, UpperCAmelCase_       :	Tuple					, UpperCAmelCase_       :	Union[str, Any]					, UpperCAmelCase_       :	List[str]=False      ):
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    copy.deepcopy(UpperCAmelCase_      )

							if model_class in get_values(UpperCAmelCase_      ):
									SCREAMING_SNAKE_CASE       :      Optional[int]							=    {
									    k: tf.tile(tf.expand_dims(UpperCAmelCase_					, 1      )					, (1, self.model_tester.num_choices) + (1,) * (v.ndim - 1)      )
									    if isinstance(UpperCAmelCase_					, tf.Tensor      ) and v.ndim > 0
									    else v
									    for k, v in inputs_dict.items()
									}

							if return_labels:
									if model_class in get_values(UpperCAmelCase_      ):
											SCREAMING_SNAKE_CASE       :      List[str]							=    tf.ones(self.model_tester.batch_size					, dtype=tf.intaa      )
									elif model_class in get_values(UpperCAmelCase_      ):
											SCREAMING_SNAKE_CASE       :      str							=    tf.zeros(self.model_tester.batch_size					, dtype=tf.intaa      )
											SCREAMING_SNAKE_CASE       :      int							=    tf.zeros(self.model_tester.batch_size					, dtype=tf.intaa      )
									elif model_class in get_values(UpperCAmelCase_      ):
											SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    tf.zeros(self.model_tester.batch_size					, dtype=tf.intaa      )
									elif model_class in get_values(UpperCAmelCase_      ):
											SCREAMING_SNAKE_CASE       :      Any							=    tf.zeros(
											    (self.model_tester.batch_size, self.model_tester.text_seq_length)					, dtype=tf.intaa      )

							return inputs_dict


					def 				_A       (				self       :	Optional[Any]      ):
							SCREAMING_SNAKE_CASE       :      str							=    TFLayoutLMvaModelTester(self      )
							SCREAMING_SNAKE_CASE       :      Dict							=    ConfigTester(self					, config_class=UpperCAmelCase_					, hidden_size=37      )


					def 				_A       (				self       :	int      ):
							self.config_tester.run_common_tests()


					def 				_A       (				self       :	Optional[int]      ):
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    self.model_tester.prepare_config_and_inputs_for_common()
							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE       :      Dict							=    model_class(UpperCAmelCase_      )
									if getattr(UpperCAmelCase_					, "hf_compute_loss"					, UpperCAmelCase_      ):
											# The number of elements in the loss should be the same as the number of elements in the label
											SCREAMING_SNAKE_CASE       :      str							=    self._prepare_for_class(inputs_dict.copy()					, UpperCAmelCase_					, return_labels=UpperCAmelCase_      )
											SCREAMING_SNAKE_CASE       :      Dict							=    prepared_for_class[
											    sorted(prepared_for_class.keys() - inputs_dict.keys()					, reverse=UpperCAmelCase_      )[0]
											]
											SCREAMING_SNAKE_CASE       :      Any							=    added_label.shape.as_list()[:1]

											# Test that model correctly compute the loss with kwargs
											SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    self._prepare_for_class(inputs_dict.copy()					, UpperCAmelCase_					, return_labels=UpperCAmelCase_      )
											SCREAMING_SNAKE_CASE       :      Tuple							=    prepared_for_class.pop("input_ids"      )

											SCREAMING_SNAKE_CASE       :      int							=    model(UpperCAmelCase_					, **UpperCAmelCase_      )[0]
											self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]      )

											# Test that model correctly compute the loss when we mask some positions
											SCREAMING_SNAKE_CASE       :      int							=    self._prepare_for_class(inputs_dict.copy()					, UpperCAmelCase_					, return_labels=UpperCAmelCase_      )
											SCREAMING_SNAKE_CASE       :      Dict							=    prepared_for_class.pop("input_ids"      )
											if "labels" in prepared_for_class:
													SCREAMING_SNAKE_CASE       :      Optional[Any]							=    prepared_for_class["labels"].numpy()
													if len(labels.shape      ) > 1 and labels.shape[1] != 1:
															SCREAMING_SNAKE_CASE       :      List[str]							=    -100
															SCREAMING_SNAKE_CASE       :      Tuple							=    tf.convert_to_tensor(UpperCAmelCase_      )
															SCREAMING_SNAKE_CASE       :      Dict							=    model(UpperCAmelCase_					, **UpperCAmelCase_      )[0]
															self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]      )
															self.assertTrue(not np.any(np.isnan(loss.numpy()      )      )      )

															 # Test that model correctly compute the loss with a dict
											SCREAMING_SNAKE_CASE       :      Dict							=    self._prepare_for_class(inputs_dict.copy()					, UpperCAmelCase_					, return_labels=UpperCAmelCase_      )
											SCREAMING_SNAKE_CASE       :      Optional[Any]							=    model(UpperCAmelCase_      )[0]
											self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]      )

											# Test that model correctly compute the loss with a tuple
											SCREAMING_SNAKE_CASE       :      List[Any]							=    self._prepare_for_class(inputs_dict.copy()					, UpperCAmelCase_					, return_labels=UpperCAmelCase_      )

											# Get keys that were added with the _prepare_for_class function
											SCREAMING_SNAKE_CASE       :      int							=    prepared_for_class.keys() - inputs_dict.keys()
											SCREAMING_SNAKE_CASE       :      int							=    inspect.signature(model.call      ).parameters
											SCREAMING_SNAKE_CASE       :      List[Any]							=    list(signature.keys()      )

											# Create a dictionary holding the location of the tensors in the tuple
											SCREAMING_SNAKE_CASE       :      List[str]							=    {0: "input_ids"}
											for label_key in label_keys:
													SCREAMING_SNAKE_CASE       :      int							=    signature_names.index(UpperCAmelCase_      )
													SCREAMING_SNAKE_CASE       :      List[Any]							=    label_key
											SCREAMING_SNAKE_CASE       :      List[Any]							=    sorted(tuple_index_mapping.items()      )
											# Initialize a list with their default values, update the values and convert to a tuple
											SCREAMING_SNAKE_CASE       :      Dict							=    []

											for name in signature_names:
													if name != "kwargs":
															list_input.append(signature[name].default      )

											for index, value in sorted_tuple_index_mapping:
													SCREAMING_SNAKE_CASE       :      List[str]							=    prepared_for_class[value]

											SCREAMING_SNAKE_CASE       :      Optional[Any]							=    tuple(UpperCAmelCase_      )

											# Send to model
											SCREAMING_SNAKE_CASE       :      Optional[Any]							=    model(tuple_input[:-1]      )[0]

											self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]      )


					def 				_A       (				self       :	List[str]      ):
							(
							    SCREAMING_SNAKE_CASE  
							)       :      Tuple							=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_      )


					def 				_A       (				self       :	Union[str, Any]      ):
							(
							    SCREAMING_SNAKE_CASE  
							)       :      str							=    self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
									SCREAMING_SNAKE_CASE       :      Optional[int]							=    type
									self.model_tester.create_and_check_model(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_      )


					def 				_A       (				self       :	Optional[int]      ):
							(
							    SCREAMING_SNAKE_CASE  
							)       :      int							=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(
							    UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_      )


					def 				_A       (				self       :	Optional[int]      ):
							(
							    SCREAMING_SNAKE_CASE  
							)       :      str							=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(
							    UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_      )


					def 				_A       (				self       :	Tuple      ):
							(
							    SCREAMING_SNAKE_CASE  
							)       :      List[str]							=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(
							    UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_      )






					@slow
					def 				_A       (				self       :	str      ):
							for model_name in TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE       :      Dict							=    TFLayoutLMvaModel.from_pretrained(UpperCAmelCase_      )
									self.assertIsNotNone(UpperCAmelCase_      )





def   lowerCamelCase__			(     ):

		"""simple docstring"""






		SCREAMING_SNAKE_CASE       :      List[str]							=    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
		return image


@require_tf
class  SCREAMING_SNAKE_CASE			(			unittest.TestCase					):
					'''simple docstring'''


					@cached_property
					def 				_A       (				self       :	Optional[Any]      ):
							return LayoutLMvaImageProcessor(apply_ocr=UpperCAmelCase_      ) if is_vision_available() else None






					@slow
					def 				_A       (				self       :	List[str]      ):
							SCREAMING_SNAKE_CASE       :      List[str]							=    TFLayoutLMvaModel.from_pretrained("microsoft/layoutlmv3-base"      )

							SCREAMING_SNAKE_CASE       :      Optional[int]							=    self.default_image_processor
							SCREAMING_SNAKE_CASE       :      Optional[Any]							=    prepare_img()
							SCREAMING_SNAKE_CASE       :      List[Any]							=    image_processor(images=UpperCAmelCase_					, return_tensors="tf"      ).pixel_values

							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    tf.constant([[1, 2]]      )
							SCREAMING_SNAKE_CASE       :      Optional[int]							=    tf.expand_dims(tf.constant([[1, 2, 3, 4], [5, 6, 7, 8]]      )					, axis=0      )

							# forward pass
							SCREAMING_SNAKE_CASE       :      str							=    model(input_ids=UpperCAmelCase_					, bbox=UpperCAmelCase_					, pixel_values=UpperCAmelCase_					, training=UpperCAmelCase_      )

							# verify the logits
							SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    (1, 199, 768)
							self.assertEqual(outputs.last_hidden_state.shape					, UpperCAmelCase_      )

							SCREAMING_SNAKE_CASE       :      List[str]							=    tf.constant(
							    [[-0.0_529, 0.3_618, 0.1_632], [-0.1_587, -0.1_667, -0.0_400], [-0.1_557, -0.1_671, -0.0_505]]      )

							self.assertTrue(np.allclose(outputs.last_hidden_state[0, :3, :3]					, UpperCAmelCase_					, atol=1E-4      )      )














snake_case    				=		"""Tobias Carryer"""

from time import time


class  SCREAMING_SNAKE_CASE			:
     '''simple docstring'''


     def __init__(				self       :	List[Any]					, UpperCAmelCase_       :	List[str]					, UpperCAmelCase_       :	Optional[int]					, UpperCAmelCase_       :	Any					, UpperCAmelCase_       :	int=int(time()      )      ):  # noqa: B008
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    multiplier
       SCREAMING_SNAKE_CASE       :      Tuple							=    increment
       SCREAMING_SNAKE_CASE       :      int							=    modulo
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    seed






     def 				_A       (				self       :	Tuple      ):
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    (self.multiplier * self.seed + self.increment) % self.modulo
       return self.seed


if __name__ == "__main__":
   # Show the LCG in action.
   snake_case    				=		LinearCongruentialGenerator(1_664_525, 1_013_904_223, 2 << 31)
   while True:
      print(lcg.next_number())






