



'''simple docstring'''





import copy
import unittest

from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
       import torch

       from transformers import (
           MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
           MODEL_FOR_QUESTION_ANSWERING_MAPPING,
           MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
           MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
           LayoutLMvaConfig,
           LayoutLMvaForQuestionAnswering,
           LayoutLMvaForSequenceClassification,
           LayoutLMvaForTokenClassification,
           LayoutLMvaModel,
       )
       from transformers.models.layoutlmva.modeling_layoutlmva import LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
       from PIL import Image

       from transformers import LayoutLMvaImageProcessor







class        UpperCAmelCase_			:
    """simple docstring"""







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

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




    def lowerCamelCase			(       self   :	Tuple		):
          snake_case__    :       List[str]       		= ids_tensor([self.batch_size, self.text_seq_length]					,	self.vocab_size		)

          snake_case__    :       Optional[Any]       		= ids_tensor([self.batch_size, self.text_seq_length, 4]					,	self.range_bbox		)
          # 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]:
                            snake_case__    :       List[Any]       		= bbox[i, j, 3]
                            snake_case__    :       Dict       		= bbox[i, j, 1]
                            snake_case__    :       Optional[Any]       		= t
                      if bbox[i, j, 2] < bbox[i, j, 0]:
                            snake_case__    :       List[Any]       		= bbox[i, j, 2]
                            snake_case__    :       Union[str, Any]       		= bbox[i, j, 0]
                            snake_case__    :       Any       		= t

          snake_case__    :       Tuple       		= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

          snake_case__    :       Dict       		= None
          if self.use_input_mask:
                snake_case__    :       List[str]       		= random_attention_mask([self.batch_size, self.text_seq_length]		)

          snake_case__    :       Dict       		= None
          if self.use_token_type_ids:
                snake_case__    :       Tuple       		= ids_tensor([self.batch_size, self.text_seq_length]					,	self.type_vocab_size		)

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

          snake_case__    :       Union[str, 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 lowerCamelCase			(       self   :	List[Any]					,	snake_case_   :	int					,	snake_case_   :	Union[str, Any]					,	snake_case_   :	Any					,	snake_case_   :	List[str]					,	snake_case_   :	Optional[Any]					,	snake_case_   :	Optional[Any]					,	snake_case_   :	List[Any]					,	snake_case_   :	str		):
          snake_case__    :       Any       		= LayoutLMvaModel(config=snake_case_		)
          model.to(snake_case_		)
          model.eval()

          # text + image
          snake_case__    :       Optional[int]       		= model(snake_case_					,	pixel_values=snake_case_		)
          snake_case__    :       Optional[Any]       		= model(
              snake_case_					,	bbox=snake_case_					,	pixel_values=snake_case_					,	attention_mask=snake_case_					,	token_type_ids=snake_case_		)
          snake_case__    :       Any       		= model(snake_case_					,	bbox=snake_case_					,	pixel_values=snake_case_					,	token_type_ids=snake_case_		)
          snake_case__    :       List[str]       		= model(snake_case_					,	bbox=snake_case_					,	pixel_values=snake_case_		)

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

          # text only
          snake_case__    :       List[Any]       		= model(snake_case_		)
          self.parent.assertEqual(
              result.last_hidden_state.shape					,	(self.batch_size, self.text_seq_length, self.hidden_size)		)

          # image only
          snake_case__    :       List[Any]       		= model(pixel_values=snake_case_		)
          self.parent.assertEqual(
              result.last_hidden_state.shape					,	(self.batch_size, self.image_seq_length, self.hidden_size)		)




    def lowerCamelCase			(       self   :	Optional[Any]					,	snake_case_   :	Union[str, Any]					,	snake_case_   :	Dict					,	snake_case_   :	List[Any]					,	snake_case_   :	Dict					,	snake_case_   :	Tuple					,	snake_case_   :	Union[str, Any]					,	snake_case_   :	Dict					,	snake_case_   :	List[str]		):
          snake_case__    :       Optional[Any]       		= self.num_labels
          snake_case__    :       Dict       		= LayoutLMvaForSequenceClassification(snake_case_		)
          model.to(snake_case_		)
          model.eval()
          snake_case__    :       List[Any]       		= model(
              snake_case_					,	bbox=snake_case_					,	pixel_values=snake_case_					,	attention_mask=snake_case_					,	token_type_ids=snake_case_					,	labels=snake_case_					,	)
          self.parent.assertEqual(result.logits.shape					,	(self.batch_size, self.num_labels)		)




    def lowerCamelCase			(       self   :	Optional[int]					,	snake_case_   :	Optional[int]					,	snake_case_   :	Dict					,	snake_case_   :	Optional[int]					,	snake_case_   :	Tuple					,	snake_case_   :	str					,	snake_case_   :	str					,	snake_case_   :	Union[str, Any]					,	snake_case_   :	Optional[Any]		):
          snake_case__    :       Optional[Any]       		= self.num_labels
          snake_case__    :       Union[str, Any]       		= LayoutLMvaForTokenClassification(config=snake_case_		)
          model.to(snake_case_		)
          model.eval()
          snake_case__    :       List[Any]       		= model(
              snake_case_					,	bbox=snake_case_					,	pixel_values=snake_case_					,	attention_mask=snake_case_					,	token_type_ids=snake_case_					,	labels=snake_case_					,	)
          self.parent.assertEqual(result.logits.shape					,	(self.batch_size, self.text_seq_length, self.num_labels)		)




    def lowerCamelCase			(       self   :	List[str]					,	snake_case_   :	Optional[int]					,	snake_case_   :	List[Any]					,	snake_case_   :	Any					,	snake_case_   :	Union[str, Any]					,	snake_case_   :	List[Any]					,	snake_case_   :	List[Any]					,	snake_case_   :	Tuple					,	snake_case_   :	str		):
          snake_case__    :       str       		= LayoutLMvaForQuestionAnswering(config=snake_case_		)
          model.to(snake_case_		)
          model.eval()
          snake_case__    :       Union[str, Any]       		= model(
              snake_case_					,	bbox=snake_case_					,	pixel_values=snake_case_					,	attention_mask=snake_case_					,	token_type_ids=snake_case_					,	start_positions=snake_case_					,	end_positions=snake_case_					,	)
          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 lowerCamelCase			(       self   :	Optional[int]		):
          snake_case__    :       Any       		= self.prepare_config_and_inputs()
          (
              (
              snake_case__
          )		,							(
              snake_case__
          )		,							(
              snake_case__
          )		,							(
              snake_case__
          )		,							(
              snake_case__
          )		,							(
              snake_case__
          )		,							(
              snake_case__
          )		,							(
              snake_case__
          )		,							
          )    :       Optional[int]       		= config_and_inputs
          snake_case__    :       Optional[Any]       		= {
              """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_torch
class        UpperCAmelCase_			(			_a						,						_a						,						unittest.TestCase      ):
    """simple docstring"""







    lowercase   =						False
    lowercase   =						False
    lowercase   =						False

    lowercase   =						(
        (
            LayoutLMvaModel,
            LayoutLMvaForSequenceClassification,
            LayoutLMvaForTokenClassification,
            LayoutLMvaForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    lowercase   =						(
        {"document-question-answering": LayoutLMvaForQuestionAnswering, "feature-extraction": LayoutLMvaModel}
        if is_torch_available()
        else {}
    )




    def lowerCamelCase			(       self   :	Dict					,	snake_case_   :	str					,	snake_case_   :	Optional[Any]					,	snake_case_   :	List[Any]					,	snake_case_   :	List[Any]					,	snake_case_   :	Optional[Any]		):
          # `DocumentQuestionAnsweringPipeline` is expected to work with this model, but it combines the text and visual
          # embedding along the sequence dimension (dim 1), which causes an error during post-processing as `p_mask` has
          # the sequence dimension of the text embedding only.
          # (see the line `embedding_output = torch.cat([embedding_output, visual_embeddings], dim=1)`)
          return True




    def lowerCamelCase			(       self   :	List[Any]		):
          snake_case__    :       List[str]       		= LayoutLMvaModelTester(self		)
          snake_case__    :       Tuple       		= ConfigTester(self					,	config_class=snake_case_					,	hidden_size=37		)




    def lowerCamelCase			(       self   :	Tuple					,	snake_case_   :	Optional[Any]					,	snake_case_   :	Tuple					,	snake_case_   :	Union[str, Any]=False		):
          snake_case__    :       Tuple       		= copy.deepcopy(snake_case_		)
          if model_class in get_values(snake_case_		):
                snake_case__    :       Optional[Any]       		= {
                    k: v.unsqueeze(1		).expand(-1					,	self.model_tester.num_choices					,	-1		).contiguous()
                    if isinstance(snake_case_					,	torch.Tensor		) and v.ndim > 1
                    else v
                    for k, v in inputs_dict.items()
                }
          if return_labels:
                if model_class in get_values(snake_case_		):
                      snake_case__    :       int       		= torch.ones(self.model_tester.batch_size					,	dtype=torch.long					,	device=snake_case_		)
                elif model_class in get_values(snake_case_		):
                      snake_case__    :       List[Any]       		= torch.zeros(
                          self.model_tester.batch_size					,	dtype=torch.long					,	device=snake_case_		)
                      snake_case__    :       Optional[int]       		= torch.zeros(
                          self.model_tester.batch_size					,	dtype=torch.long					,	device=snake_case_		)
                elif model_class in [
                    *get_values(snake_case_		),
                ]:
                      snake_case__    :       Dict       		= torch.zeros(
                          self.model_tester.batch_size					,	dtype=torch.long					,	device=snake_case_		)
                elif model_class in [
                    *get_values(snake_case_		),
                ]:
                      snake_case__    :       str       		= torch.zeros(
                          (self.model_tester.batch_size, self.model_tester.text_seq_length)					,	dtype=torch.long					,	device=snake_case_					,	)

          return inputs_dict




    def lowerCamelCase			(       self   :	Tuple		):
          self.config_tester.run_common_tests()




    def lowerCamelCase			(       self   :	Dict		):
          snake_case__    :       Dict       		= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case_		)




    def lowerCamelCase			(       self   :	Any		):
          snake_case__    :       str       		= self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
                snake_case__    :       Optional[Any]       		= type
                self.model_tester.create_and_check_model(*snake_case_		)




    def lowerCamelCase			(       self   :	Optional[Any]		):
          snake_case__    :       List[Any]       		= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*snake_case_		)




    def lowerCamelCase			(       self   :	Tuple		):
          snake_case__    :       int       		= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*snake_case_		)




    def lowerCamelCase			(       self   :	Optional[int]		):
          snake_case__    :       Any       		= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*snake_case_		)




    @slow
    def lowerCamelCase			(       self   :	Any		):
          for model_name in LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                snake_case__    :       Optional[Any]       		= LayoutLMvaModel.from_pretrained(snake_case_		)
                self.assertIsNotNone(snake_case_		)





def 		__snake_case(							)						->					Optional[int]:
      snake_case__    :       int       		= Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""						)
      return image







@require_torch
class        UpperCAmelCase_			(			unittest.TestCase      ):
    """simple docstring"""







    @cached_property
    def lowerCamelCase			(       self   :	List[str]		):
          return LayoutLMvaImageProcessor(apply_ocr=snake_case_		) if is_vision_available() else None




    @slow
    def lowerCamelCase			(       self   :	Optional[int]		):
          snake_case__    :       Optional[int]       		= LayoutLMvaModel.from_pretrained("""microsoft/layoutlmv3-base"""		).to(snake_case_		)

          snake_case__    :       Union[str, Any]       		= self.default_image_processor
          snake_case__    :       List[str]       		= prepare_img()
          snake_case__    :       str       		= image_processor(images=snake_case_					,	return_tensors="""pt"""		).pixel_values.to(snake_case_		)

          snake_case__    :       str       		= torch.tensor([[1, 2]]		)
          snake_case__    :       str       		= torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]		).unsqueeze(0		)

          # forward pass
          snake_case__    :       int       		= model(
              input_ids=input_ids.to(snake_case_		)					,	bbox=bbox.to(snake_case_		)					,	pixel_values=pixel_values.to(snake_case_		)					,	)

          # verify the logits
          snake_case__    :       Union[str, Any]       		= torch.Size((1, 199, 768)		)
          self.assertEqual(outputs.last_hidden_state.shape					,	snake_case_		)

          snake_case__    :       int       		= torch.tensor(
              [[-0.0529, 0.3618, 0.1632], [-0.1587, -0.1667, -0.0400], [-0.1557, -0.1671, -0.0505]]		).to(snake_case_		)

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





'''simple docstring'''





import sys

__a  			=						(
    "73167176531330624919225119674426574742355349194934"
    "96983520312774506326239578318016984801869478851843"
    "85861560789112949495459501737958331952853208805511"
    "12540698747158523863050715693290963295227443043557"
    "66896648950445244523161731856403098711121722383113"
    "62229893423380308135336276614282806444486645238749"
    "30358907296290491560440772390713810515859307960866"
    "70172427121883998797908792274921901699720888093776"
    "65727333001053367881220235421809751254540594752243"
    "52584907711670556013604839586446706324415722155397"
    "53697817977846174064955149290862569321978468622482"
    "83972241375657056057490261407972968652414535100474"
    "82166370484403199890008895243450658541227588666881"
    "16427171479924442928230863465674813919123162824586"
    "17866458359124566529476545682848912883142607690042"
    "24219022671055626321111109370544217506941658960408"
    "07198403850962455444362981230987879927244284909188"
    "84580156166097919133875499200524063689912560717606"
    "05886116467109405077541002256983155200055935729725"
    "71636269561882670428252483600823257530420752963450"
)





def 		__snake_case(							_lowerCAmelCase = N						)						->					int:
      snake_case__    :       Dict       		= -sys.maxsize - 1
      for i in range(len(_lowerCAmelCase						) - 12						):
            snake_case__    :       Any       		= 1
            for j in range(13						):
                  product *= int(n[i + j]						)
            if product > largest_product:
                  snake_case__    :       List[str]       		= product
      return largest_product


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