

from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import logging


if TYPE_CHECKING:
						from ...processing_utils import ProcessorMixin
						from ...utils import TensorType


A__						=							logging.get_logger(__name__)

A__						=							{
    "microsoft/layoutlmv3-base": "https://huggingface.co/microsoft/layoutlmv3-base/resolve/main/config.json",
}

class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   Optional[Any]       				=  "layoutlmv3"







	def __init__(   self: Tuple  , __UpperCamelCase: List[Any]=5_02_65  , __UpperCamelCase: Union[str, Any]=7_68  , __UpperCamelCase: Optional[int]=12  , __UpperCamelCase: List[str]=12  , __UpperCamelCase: List[Any]=30_72  , __UpperCamelCase: Union[str, Any]="gelu"  , __UpperCamelCase: Union[str, Any]=0.1  , __UpperCamelCase: Union[str, Any]=0.1  , __UpperCamelCase: List[Any]=5_12  , __UpperCamelCase: int=2  , __UpperCamelCase: Union[str, Any]=0.02  , __UpperCamelCase: Dict=1E-5  , __UpperCamelCase: int=1  , __UpperCamelCase: Dict=0  , __UpperCamelCase: Tuple=2  , __UpperCamelCase: Any=10_24  , __UpperCamelCase: Union[str, Any]=1_28  , __UpperCamelCase: Dict=1_28  , __UpperCamelCase: Any=True  , __UpperCamelCase: Any=32  , __UpperCamelCase: int=1_28  , __UpperCamelCase: List[str]=64  , __UpperCamelCase: Union[str, Any]=2_56  , __UpperCamelCase: int=True  , __UpperCamelCase: Optional[int]=True  , __UpperCamelCase: Union[str, Any]=True  , __UpperCamelCase: Union[str, Any]=2_24  , __UpperCamelCase: Tuple=3  , __UpperCamelCase: Any=16  , __UpperCamelCase: List[Any]=None  , **__UpperCamelCase: str  , ):

						'''simple docstring'''





						super().__init__(
						    vocab_size=__UpperCamelCase  , hidden_size=__UpperCamelCase  , num_hidden_layers=__UpperCamelCase  , num_attention_heads=__UpperCamelCase  , intermediate_size=__UpperCamelCase  , hidden_act=__UpperCamelCase  , hidden_dropout_prob=__UpperCamelCase  , attention_probs_dropout_prob=__UpperCamelCase  , max_position_embeddings=__UpperCamelCase  , type_vocab_size=__UpperCamelCase  , initializer_range=__UpperCamelCase  , layer_norm_eps=__UpperCamelCase  , pad_token_id=__UpperCamelCase  , bos_token_id=__UpperCamelCase  , eos_token_id=__UpperCamelCase  , **__UpperCamelCase  , )
						__magic_name__							=    max_ad_position_embeddings
						__magic_name__							=    coordinate_size
						__magic_name__							=    shape_size
						__magic_name__							=    has_relative_attention_bias
						__magic_name__							=    rel_pos_bins
						__magic_name__							=    max_rel_pos
						__magic_name__							=    has_spatial_attention_bias
						__magic_name__							=    rel_ad_pos_bins
						__magic_name__							=    max_rel_ad_pos
						__magic_name__							=    text_embed
						__magic_name__							=    visual_embed
						__magic_name__							=    input_size
						__magic_name__							=    num_channels
						__magic_name__							=    patch_size
						__magic_name__							=    classifier_dropout




class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   Any       				=  version.parse("1.12"			)







	@property
	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						if self.task in ["question-answering", "sequence-classification"]:
											return OrderedDict(
											    [
											        ('input_ids', {0: 'batch', 1: 'sequence'}),
											        ('attention_mask', {0: 'batch', 1: 'sequence'}),
											        ('bbox', {0: 'batch', 1: 'sequence'}),
											        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
											    ]      )
						else:
											return OrderedDict(
											    [
											        ('input_ids', {0: 'batch', 1: 'sequence'}),
											        ('bbox', {0: 'batch', 1: 'sequence'}),
											        ('attention_mask', {0: 'batch', 1: 'sequence'}),
											        ('pixel_values', {0: 'batch', 1: 'num_channels'}),
											    ]      )







	@property
	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						return 1E-5







	@property
	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]      ):

						'''simple docstring'''





						return 12







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple  , __UpperCamelCase: "ProcessorMixin"  , __UpperCamelCase: int = -1  , __UpperCamelCase: int = -1  , __UpperCamelCase: bool = False  , __UpperCamelCase: Optional["TensorType"] = None  , __UpperCamelCase: int = 3  , __UpperCamelCase: int = 40  , __UpperCamelCase: int = 40  , ):

						'''simple docstring'''





						setattr(processor.image_processor  , 'apply_ocr'  , __UpperCamelCase      )

						# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
						__magic_name__							=    compute_effective_axis_dimension(
						    __UpperCamelCase  , fixed_dimension=OnnxConfig.default_fixed_batch  , num_token_to_add=0      )
						# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
						__magic_name__							=    processor.tokenizer.num_special_tokens_to_add(__UpperCamelCase      )
						__magic_name__							=    compute_effective_axis_dimension(
						    __UpperCamelCase  , fixed_dimension=OnnxConfig.default_fixed_sequence  , num_token_to_add=__UpperCamelCase      )
						# Generate dummy inputs according to compute batch and sequence
						__magic_name__							=    [[' '.join([processor.tokenizer.unk_token]      ) * seq_length]] * batch_size

						# Generate dummy bounding boxes
						__magic_name__							=    [[[48, 84, 73, 1_28]]] * batch_size

						# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
						# batch_size = compute_effective_axis_dimension(batch_size, fixed_dimension=OnnxConfig.default_fixed_batch)
						__magic_name__							=    self._generate_dummy_images(__UpperCamelCase  , __UpperCamelCase  , __UpperCamelCase  , __UpperCamelCase      )

						__magic_name__							=    dict(
						    processor(
						        __UpperCamelCase  , text=__UpperCamelCase  , boxes=__UpperCamelCase  , return_tensors=__UpperCamelCase  , )      )

						return inputs







import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
						import jax

						from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
						from transformers.models.bert.modeling_flax_bert import FlaxBertModel
						from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel

@require_flax
class 				__UpperCamelCase				(					unittest.TestCase			):







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						for model_name in ["bert-base-cased", "bert-large-uncased"]:
											with self.subTest(__UpperCamelCase      ):
																__magic_name__							=    AutoConfig.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )

																__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						for model_name in ["roberta-base", "roberta-large"]:
											with self.subTest(__UpperCamelCase      ):
																__magic_name__							=    AutoConfig.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )

																__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Dict      ):

						'''simple docstring'''





						for model_name in ["bert-base-cased", "bert-large-uncased"]:
											__magic_name__							=    AutoTokenizer.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    FlaxBertModel.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    tokenizer('Do you support jax jitted function?'  , return_tensors=TensorType.JAX      )

											@jax.jit
											def eval(**__UpperCamelCase: Optional[Any]      ):
																return model(**__UpperCamelCase      )

											eval(**__UpperCamelCase      ).block_until_ready()







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						for model_name in ["roberta-base", "roberta-large"]:
											__magic_name__							=    AutoTokenizer.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    FlaxRobertaModel.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    tokenizer('Do you support jax jitted function?'  , return_tensors=TensorType.JAX      )

											@jax.jit
											def eval(**__UpperCamelCase: Any      ):
																return model(**__UpperCamelCase      )

											eval(**__UpperCamelCase      ).block_until_ready()







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , 'bert-base is not a local folder and is not a valid model identifier'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('bert-base'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase  , revision='aaaaaa'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: str      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , 'hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack'  , ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('hf-internal-testing/config-no-model'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						with self.assertRaisesRegex(__UpperCamelCase  , 'Use `from_pt=True` to load this model'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only'      )




