






"""simple docstring"""
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      UpperCamelCase_			:





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

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





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[Any]		)		->     str:
				UpperCAmelCase_	:					Optional[int]     	=   ids_tensor([self.batch_size, self.text_seq_length]      ,      self.vocab_size		)

				UpperCAmelCase_	:					Optional[int]     	=   ids_tensor([self.batch_size, self.text_seq_length, 4]      ,      self.range_bbox		)
				UpperCAmelCase_	:					Union[str, Any]     	=   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]:
													UpperCAmelCase_	:					Any     	=   bbox[i, j, 3]
													UpperCAmelCase_	:					Any     	=   bbox[i, j, 1]
													UpperCAmelCase_	:					Tuple     	=   tmp_coordinate
										if bbox[i, j, 2] < bbox[i, j, 0]:
													UpperCAmelCase_	:					Any     	=   bbox[i, j, 2]
													UpperCAmelCase_	:					int     	=   bbox[i, j, 0]
													UpperCAmelCase_	:					int     	=   tmp_coordinate
				UpperCAmelCase_	:					Any     	=   tf.constant(lowerCAmelCase_		)

				UpperCAmelCase_	:					int     	=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

				UpperCAmelCase_	:					str     	=   None
				if self.use_input_mask:
							UpperCAmelCase_	:					Optional[Any]     	=   random_attention_mask([self.batch_size, self.text_seq_length]		)

				UpperCAmelCase_	:					List[str]     	=   None
				if self.use_token_type_ids:
							UpperCAmelCase_	:					Any     	=   ids_tensor([self.batch_size, self.text_seq_length]      ,      self.type_vocab_size		)

				UpperCAmelCase_	:					Any     	=   None
				UpperCAmelCase_	:					int     	=   None
				if self.use_labels:
							UpperCAmelCase_	:					Optional[int]     	=   ids_tensor([self.batch_size]      ,      self.type_sequence_label_size		)
							UpperCAmelCase_	:					List[Any]     	=   ids_tensor([self.batch_size, self.text_seq_length]      ,      self.num_labels		)

				UpperCAmelCase_	:					List[Any]     	=   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 	_SCREAMING_SNAKE_CASE ( self   :					Tuple      ,      lowerCAmelCase_   :					List[Any]      ,      lowerCAmelCase_   :					int      ,      lowerCAmelCase_   :					str      ,      lowerCAmelCase_   :					List[str]      ,      lowerCAmelCase_   :					List[str]      ,      lowerCAmelCase_   :					Any		)		->     Any:
				UpperCAmelCase_	:					Optional[Any]     	=   TFLayoutLMvaModel(config=lowerCAmelCase_		)

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

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

				# text only
				UpperCAmelCase_	:					Optional[Any]     	=   model(lowerCAmelCase_      ,      training=lowerCAmelCase_		)
				self.parent.assertEqual(
				    result.last_hidden_state.shape      ,      (self.batch_size, self.text_seq_length, self.hidden_size)		)

				# image only
				UpperCAmelCase_	:					str     	=   model({"pixel_values": pixel_values}      ,      training=lowerCAmelCase_		)
				self.parent.assertEqual(
				    result.last_hidden_state.shape      ,      (self.batch_size, self.image_seq_length, self.hidden_size)		)





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





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





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]      ,      lowerCAmelCase_   :					str      ,      lowerCAmelCase_   :					Optional[Any]      ,      lowerCAmelCase_   :					Union[str, Any]      ,      lowerCAmelCase_   :					List[str]      ,      lowerCAmelCase_   :					int      ,      lowerCAmelCase_   :					Union[str, Any]      ,      lowerCAmelCase_   :					Union[str, Any]		)		->     List[str]:
				UpperCAmelCase_	:					Tuple     	=   2
				UpperCAmelCase_	:					str     	=   TFLayoutLMvaForQuestionAnswering(config=lowerCAmelCase_		)
				UpperCAmelCase_	:					Any     	=   model(
				    lowerCAmelCase_      ,      bbox=lowerCAmelCase_      ,      pixel_values=lowerCAmelCase_      ,      attention_mask=lowerCAmelCase_      ,      token_type_ids=lowerCAmelCase_      ,      start_positions=lowerCAmelCase_      ,      end_positions=lowerCAmelCase_      ,      training=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 	_SCREAMING_SNAKE_CASE ( self   :					str		)		->     Any:
				UpperCAmelCase_	:					int     	=   self.prepare_config_and_inputs()
				((UpperCAmelCase_)	,      (UpperCAmelCase_)	,      (UpperCAmelCase_)	,      (UpperCAmelCase_)	,      (UpperCAmelCase_)	,      (UpperCAmelCase_)	,      (UpperCAmelCase_)	,      (UpperCAmelCase_))	:					Tuple     	=   config_and_inputs
				UpperCAmelCase_	:					str     	=   {
				    "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      UpperCamelCase_			(__A							,		__A							,		unittest.TestCase	):
	__magic_name__       =							(
	    (
	        TFLayoutLMvaModel,
	        TFLayoutLMvaForQuestionAnswering,
	        TFLayoutLMvaForSequenceClassification,
	        TFLayoutLMvaForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	__magic_name__       =							(
	    {'''document-question-answering''': TFLayoutLMvaForQuestionAnswering, '''feature-extraction''': TFLayoutLMvaModel}
	    if is_tf_available()
	    else {}
	)

	__magic_name__       =							False
	__magic_name__       =							False
	__magic_name__       =							False





	def 	_SCREAMING_SNAKE_CASE ( self   :					Any      ,      lowerCAmelCase_   :					Tuple      ,      lowerCAmelCase_   :					List[str]      ,      lowerCAmelCase_   :					Any      ,      lowerCAmelCase_   :					int      ,      lowerCAmelCase_   :					Optional[int]		)		->     Optional[Any]:
				return True





	def 	_SCREAMING_SNAKE_CASE ( self   :					Any      ,      lowerCAmelCase_   :					int      ,      lowerCAmelCase_   :					Union[str, Any]      ,      lowerCAmelCase_   :					Optional[Any]=False		)		->     dict:
				UpperCAmelCase_	:					Optional[int]     	=   copy.deepcopy(lowerCAmelCase_		)

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

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

				return inputs_dict





	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]		)		->     Union[str, Any]:
				UpperCAmelCase_	:					Optional[Any]     	=   TFLayoutLMvaModelTester(self		)
				UpperCAmelCase_	:					List[str]     	=   ConfigTester(self      ,      config_class=lowerCAmelCase_      ,      hidden_size=37		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     Union[str, Any]:
				self.config_tester.run_common_tests()





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

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

										UpperCAmelCase_	:					int     	=   model(lowerCAmelCase_      ,      **lowerCAmelCase_		)[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
										UpperCAmelCase_	:					Tuple     	=   self._prepare_for_class(inputs_dict.copy()      ,      lowerCAmelCase_      ,      return_labels=lowerCAmelCase_		)
										UpperCAmelCase_	:					Optional[Any]     	=   prepared_for_class.pop("input_ids"		)
										if "labels" in prepared_for_class:
													UpperCAmelCase_	:					Tuple     	=   prepared_for_class["labels"].numpy()
													if len(labels.shape		) > 1 and labels.shape[1] != 1:
																UpperCAmelCase_	:					List[str]     	=   -100
																UpperCAmelCase_	:					str     	=   tf.convert_to_tensor(lowerCAmelCase_		)
																UpperCAmelCase_	:					List[Any]     	=   model(lowerCAmelCase_      ,      **lowerCAmelCase_		)[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
										UpperCAmelCase_	:					List[str]     	=   self._prepare_for_class(inputs_dict.copy()      ,      lowerCAmelCase_      ,      return_labels=lowerCAmelCase_		)
										UpperCAmelCase_	:					Dict     	=   model(lowerCAmelCase_		)[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
										UpperCAmelCase_	:					Optional[int]     	=   self._prepare_for_class(inputs_dict.copy()      ,      lowerCAmelCase_      ,      return_labels=lowerCAmelCase_		)

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

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

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

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

										UpperCAmelCase_	:					int     	=   tuple(lowerCAmelCase_		)

										# Send to model
										UpperCAmelCase_	:					int     	=   model(tuple_input[:-1]		)[0]

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





	def 	_SCREAMING_SNAKE_CASE ( self   :					Tuple		)		->     Optional[Any]:
				(
				    (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      
				)	:					int     	=   self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     List[Any]:
				(
				    (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      
				)	:					Optional[Any]     	=   self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
							UpperCAmelCase_	:					List[str]     	=   type
							self.model_tester.create_and_check_model(lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     List[str]:
				(
				    (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      
				)	:					List[Any]     	=   self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(
				    lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					str		)		->     Dict:
				(
				    (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      
				)	:					Dict     	=   self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(
				    lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[Any]		)		->     List[str]:
				(
				    (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      (
				    UpperCAmelCase_
				)	,      
				)	:					List[Any]     	=   self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(
				    lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)





	@slow
	def 	_SCREAMING_SNAKE_CASE ( self   :					List[Any]		)		->     Optional[int]:
				for model_name in TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_	:					Tuple     	=   TFLayoutLMvaModel.from_pretrained(lowerCAmelCase_		)
							self.assertIsNotNone(lowerCAmelCase_		)





def 							snake_case (  ):
			UpperCAmelCase_	:					Optional[int]     	=   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
			return image







@require_tf
class      UpperCamelCase_			(unittest.TestCase	):





	@cached_property
	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]		)		->     int:
				return LayoutLMvaImageProcessor(apply_ocr=lowerCAmelCase_		) if is_vision_available() else None





	@slow
	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]		)		->     List[Any]:
				UpperCAmelCase_	:					Dict     	=   TFLayoutLMvaModel.from_pretrained("microsoft/layoutlmv3-base"		)

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

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

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

				# verify the logits
				UpperCAmelCase_	:					Optional[int]     	=   (1, 199, 768)
				self.assertEqual(outputs.last_hidden_state.shape      ,      lowerCAmelCase_		)

				UpperCAmelCase_	:					Dict     	=   tf.constant(
				    [[-0.0_5_2_9, 0.3_6_1_8, 0.1_6_3_2], [-0.1_5_8_7, -0.1_6_6_7, -0.0_4_0_0], [-0.1_5_5_7, -0.1_6_7_1, -0.0_5_0_5]]		)

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





"""simple docstring"""






from itertools import count




def __magic_name__	(				_lowerCamelCase:		int = 50			)					->						int:

	'''simple docstring'''




	lowerCAmelCase												=  [1] * min_block_length

	for n in count(_lowerCamelCase			):
		fill_count_functions.append(1			)

		for block_length in range(_lowerCamelCase,					n + 1			):
			for block_start in range(n - block_length			):
				fill_count_functions[n] += fill_count_functions[
				    n - block_start - block_length - 1
				]

			fill_count_functions[n] += 1

		if fill_count_functions[n] > 1_000_000:
			break

	return n


if __name__ == "__main__":
					print(f"""{solution() = }""")


