






'''simple docstring'''
import inspect
import unittest

from datasets import load_dataset
from packaging import version

from transformers import BeitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, 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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import (
     MODEL_MAPPING,
     BeitForImageClassification,
     BeitForMaskedImageModeling,
     BeitForSemanticSegmentation,
     BeitModel,
 )
 from transformers.models.beit.modeling_beit import BEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 import PIL
 from PIL import Image

 from transformers import BeitImageProcessor


class 							_UpperCAmelCase    :




    def __init__(      self	:							Dict	,  a	:							int	,  a	:							Tuple=1_0_0	,  a	:							Any=1_3	,  a	:							Optional[int]=3_0	,  a	:							Optional[int]=2	,  a	:							List[str]=3	,  a	:							List[str]=True	,  a	:							Optional[Any]=True	,  a	:							Optional[int]=3_2	,  a	:							Union[str, Any]=4	,  a	:							Dict=4	,  a	:							Dict=3_7	,  a	:							Optional[Any]="gelu"	,  a	:							Optional[int]=0.1	,  a	:							str=0.1	,  a	:							Dict=1_0	,  a	:							Dict=0.02	,  a	:							Any=3	,  a	:							Union[str, Any]=None	,  a	:							List[str]=[0, 1, 2, 3]	,  ):






       '''simple docstring'''






       lowercase_						:     Union[str, Any]							     =  parent
       lowercase_						:     List[str]							     =  1_0_0
       lowercase_						:     str							     =  batch_size
       lowercase_						:     Optional[Any]							     =  image_size
       lowercase_						:     int							     =  patch_size
       lowercase_						:     Optional[int]							     =  num_channels
       lowercase_						:     int							     =  is_training
       lowercase_						:     Any							     =  use_labels
       lowercase_						:     str							     =  hidden_size
       lowercase_						:     Optional[Any]							     =  num_hidden_layers
       lowercase_						:     int							     =  num_attention_heads
       lowercase_						:     Optional[Any]							     =  intermediate_size
       lowercase_						:     int							     =  hidden_act
       lowercase_						:     List[str]							     =  hidden_dropout_prob
       lowercase_						:     List[Any]							     =  attention_probs_dropout_prob
       lowercase_						:     Any							     =  type_sequence_label_size
       lowercase_						:     List[Any]							     =  initializer_range
       lowercase_						:     str							     =  scope
       lowercase_						:     Union[str, Any]							     =  out_indices
       lowercase_						:     Any							     =  num_labels

       # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
       lowercase_						:     Any							     =  (image_size // patch_size) ** 2
       lowercase_						:     Dict							     =  num_patches + 1




    def 					lowerCAmelCase__					(      self	:							Union[str, Any]      ):






       '''simple docstring'''






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

       lowercase_						:     Union[str, Any]							     =  None
       lowercase_						:     Optional[Any]							     =  None
       if self.use_labels:
          lowercase_						:     Union[str, Any]							     =  ids_tensor([self.batch_size]	,  self.type_sequence_label_size      )
          lowercase_						:     Optional[int]							     =  ids_tensor([self.batch_size, self.image_size, self.image_size]	,  self.num_labels      )

       lowercase_						:     Optional[Any]							     =  self.get_config()

       return config, pixel_values, labels, pixel_labels




    def 					lowerCAmelCase__					(      self	:							Optional[int]      ):






       '''simple docstring'''






       return BeitConfig(
           vocab_size=self.vocab_size	,  image_size=self.image_size	,  patch_size=self.patch_size	,  num_channels=self.num_channels	,  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	,  is_decoder=a	,  initializer_range=self.initializer_range	,  out_indices=self.out_indices	,  )




    def 					lowerCAmelCase__					(      self	:							Optional[int]	,  a	:							Tuple	,  a	:							str	,  a	:							Any	,  a	:							Union[str, Any]      ):






       '''simple docstring'''






       lowercase_						:     Optional[Any]							     =  BeitModel(config=a      )
       model.to(a      )
       model.eval()
       lowercase_						:     Optional[Any]							     =  model(a      )
       self.parent.assertEqual(result.last_hidden_state.shape	,  (self.batch_size, self.seq_length, self.hidden_size)      )




    def 					lowerCAmelCase__					(      self	:							Optional[int]	,  a	:							Optional[int]	,  a	:							Dict	,  a	:							str	,  a	:							List[str]      ):






       '''simple docstring'''






       lowercase_						:     Any							     =  BeitForMaskedImageModeling(config=a      )
       model.to(a      )
       model.eval()
       lowercase_						:     Any							     =  model(a      )
       self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.seq_length - 1, self.vocab_size)      )




    def 					lowerCAmelCase__					(      self	:							int	,  a	:							Union[str, Any]	,  a	:							Optional[int]	,  a	:							Tuple	,  a	:							Dict      ):






       '''simple docstring'''






       lowercase_						:     List[str]							     =  self.type_sequence_label_size
       lowercase_						:     List[Any]							     =  BeitForImageClassification(a      )
       model.to(a      )
       model.eval()
       lowercase_						:     int							     =  model(a	,  labels=a      )
       self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.type_sequence_label_size)      )

       # test greyscale images
       lowercase_						:     Any							     =  1
       lowercase_						:     List[str]							     =  BeitForImageClassification(a      )
       model.to(a      )
       model.eval()

       lowercase_						:     int							     =  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
       lowercase_						:     Optional[int]							     =  model(a	,  labels=a      )
       self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.type_sequence_label_size)      )




    def 					lowerCAmelCase__					(      self	:							Union[str, Any]	,  a	:							Union[str, Any]	,  a	:							Dict	,  a	:							Dict	,  a	:							List[Any]      ):






       '''simple docstring'''






       lowercase_						:     int							     =  self.num_labels
       lowercase_						:     Optional[int]							     =  BeitForSemanticSegmentation(a      )
       model.to(a      )
       model.eval()
       lowercase_						:     Tuple							     =  model(a      )
       self.parent.assertEqual(
           result.logits.shape	,  (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)      )
       lowercase_						:     Optional[int]							     =  model(a	,  labels=a      )
       self.parent.assertEqual(
           result.logits.shape	,  (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)      )





    def 					lowerCAmelCase__					(      self	:							List[str]      ):






       '''simple docstring'''






       lowercase_						:     Dict							     =  self.prepare_config_and_inputs()
       lowercase_     ,		lowercase_     ,		lowercase_     ,		lowercase_						:     Optional[int]							     =  config_and_inputs
       lowercase_						:     List[Any]							     =  {"pixel_values": pixel_values}
       return config, inputs_dict


@require_torch
class 							_UpperCAmelCase    (		snake_case					,       snake_case					,       unittest.TestCase      ):
    __lowerCamelCase: Optional[int]									=     (
        (BeitModel, BeitForImageClassification, BeitForMaskedImageModeling, BeitForSemanticSegmentation)
        if is_torch_available()
        else ()
    )
    __lowerCamelCase: Dict									=     (
        {
            'feature-extraction': BeitModel,
            'image-classification': BeitForImageClassification,
            'image-segmentation': BeitForSemanticSegmentation,
        }
        if is_torch_available()
        else {}
    )

    __lowerCamelCase: int									=     False
    __lowerCamelCase: List[Any]									=     False
    __lowerCamelCase: Any									=     False




    def 					lowerCAmelCase__					(      self	:							Union[str, Any]      ):






       '''simple docstring'''






       lowercase_						:     Any							     =  BeitModelTester(self      )
       lowercase_						:     Dict							     =  ConfigTester(self	,  config_class=a	,  has_text_modality=a	,  hidden_size=3_7      )




    def 					lowerCAmelCase__					(      self	:							Any      ):






       '''simple docstring'''






       self.config_tester.run_common_tests()




    @unittest.skip(reason="BEiT does not use inputs_embeds"      )
    def 					lowerCAmelCase__					(      self	:							Optional[Any]      ):






       '''simple docstring'''






       pass




    @require_torch_multi_gpu
    @unittest.skip(reason="BEiT has some layers using `add_module` which doesn't work well with `nn.DataParallel`"      )
    def 					lowerCAmelCase__					(      self	:							Optional[Any]      ):






       '''simple docstring'''






       pass




    def 					lowerCAmelCase__					(      self	:							Dict      ):






       '''simple docstring'''






       lowercase_     ,		lowercase_						:     Union[str, Any]							     =  self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
          lowercase_						:     Optional[int]							     =  model_class(a      )
          self.assertIsInstance(model.get_input_embeddings()	,  (nn.Module)      )
          lowercase_						:     Union[str, Any]							     =  model.get_output_embeddings()
          self.assertTrue(x is None or isinstance(a	,  nn.Linear      )      )




    def 					lowerCAmelCase__					(      self	:							List[Any]      ):






       '''simple docstring'''






       lowercase_     ,		lowercase_						:     str							     =  self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
          lowercase_						:     List[str]							     =  model_class(a      )
          lowercase_						:     Dict							     =  inspect.signature(model.forward      )
          # signature.parameters is an OrderedDict => so arg_names order is deterministic
          lowercase_						:     List[Any]							     =  [*signature.parameters.keys()]

          lowercase_						:     List[Any]							     =  ["pixel_values"]
          self.assertListEqual(arg_names[:1]	,  a      )




    def 					lowerCAmelCase__					(      self	:							Optional[int]      ):






       '''simple docstring'''






       lowercase_						:     Optional[Any]							     =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*a      )




    def 					lowerCAmelCase__					(      self	:							Tuple      ):






       '''simple docstring'''






       lowercase_						:     str							     =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*a      )




    def 					lowerCAmelCase__					(      self	:							Optional[Any]      ):






       '''simple docstring'''






       lowercase_						:     List[Any]							     =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*a      )




    def 					lowerCAmelCase__					(      self	:							Union[str, Any]      ):






       '''simple docstring'''






       lowercase_						:     List[str]							     =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_semantic_segmentation(*a      )




    def 					lowerCAmelCase__					(      self	:							Union[str, Any]      ):






       '''simple docstring'''






       if not self.model_tester.is_training:
          return

       lowercase_     ,		lowercase_						:     Any							     =  self.model_tester.prepare_config_and_inputs_for_common()
       lowercase_						:     List[Any]							     =  True

       for model_class in self.all_model_classes:
          # we don't test BeitForMaskedImageModeling
          if model_class in [*get_values(a      ), BeitForMaskedImageModeling]:
             continue

          lowercase_						:     int							     =  model_class(a      )
          model.to(a      )
          model.train()
          lowercase_						:     int							     =  self._prepare_for_class(a	,  a	,  return_labels=a      )
          lowercase_						:     int							     =  model(**a      ).loss
          loss.backward()




    def 					lowerCAmelCase__					(      self	:							Any      ):






       '''simple docstring'''






       lowercase_     ,		lowercase_						:     List[str]							     =  self.model_tester.prepare_config_and_inputs_for_common()
       if not self.model_tester.is_training:
          return

       lowercase_						:     int							     =  False
       lowercase_						:     int							     =  True

       for model_class in self.all_model_classes:
          # we don't test BeitForMaskedImageModeling
          if (
              model_class in [*get_values(a      ), BeitForMaskedImageModeling]
              or not model_class.supports_gradient_checkpointing
          ):
             continue

          lowercase_						:     int							     =  model_class(a      )
          model.gradient_checkpointing_enable()
          model.to(a      )
          model.train()
          lowercase_						:     Union[str, Any]							     =  self._prepare_for_class(a	,  a	,  return_labels=a      )
          lowercase_						:     Optional[int]							     =  model(**a      ).loss
          loss.backward()




    def 					lowerCAmelCase__					(      self	:							List[str]      ):






       '''simple docstring'''






       lowercase_     ,		lowercase_						:     Union[str, Any]							     =  self.model_tester.prepare_config_and_inputs_for_common()

       lowercase_						:     Tuple							     =  _config_zero_init(a      )
       for model_class in self.all_model_classes:
          lowercase_						:     Any							     =  model_class(config=a      )
          for name, param in model.named_parameters():
             # we skip lambda parameters as these require special initial values
             # determined by config.layer_scale_init_value
             if "lambda" in name:
                continue
             if param.requires_grad:
                self.assertIn(
                    ((param.data.mean() * 1e9).round() / 1e9).item()	,  [0.0, 1.0]	,  msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""	,  )





    @slow
    def 					lowerCAmelCase__					(      self	:							Optional[int]      ):






       '''simple docstring'''






       for model_name in BEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          lowercase_						:     int							     =  BeitModel.from_pretrained(a      )
          self.assertIsNotNone(a      )




def 		__SCREAMING_SNAKE_CASE       (	):


   """simple docstring"""




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





@require_torch
@require_vision
class 							_UpperCAmelCase    (		unittest.TestCase      ):




    @cached_property
    def 					lowerCAmelCase__					(      self	:							Union[str, Any]      ):






       '''simple docstring'''






       return BeitImageProcessor.from_pretrained("microsoft/beit-base-patch16-224"      ) if is_vision_available() else None




    @slow
    def 					lowerCAmelCase__					(      self	:							int      ):






       '''simple docstring'''






       lowercase_						:     str							     =  BeitForMaskedImageModeling.from_pretrained("microsoft/beit-base-patch16-224-pt22k"      ).to(a      )

       lowercase_						:     Dict							     =  self.default_image_processor
       lowercase_						:     Union[str, Any]							     =  prepare_img()
       lowercase_						:     Tuple							     =  image_processor(images=a	,  return_tensors="pt"      ).pixel_values.to(a      )

       # prepare bool_masked_pos
       lowercase_						:     List[str]							     =  torch.ones((1, 1_9_6)	,  dtype=torch.bool      ).to(a      )

       # forward pass
       with torch.no_grad():
          lowercase_						:     List[str]							     =  model(pixel_values=a	,  bool_masked_pos=a      )
       lowercase_						:     int							     =  outputs.logits

       # verify the logits
       lowercase_						:     int							     =  torch.Size((1, 1_9_6, 8_1_9_2)      )
       self.assertEqual(logits.shape	,  a      )

       lowercase_						:     Tuple							     =  torch.tensor(
           [[-3.2437, 0.5072, -13.9174], [-3.2456, 0.4948, -13.9401], [-3.2033, 0.5121, -13.8550]]      ).to(a      )

       self.assertTrue(torch.allclose(logits[bool_masked_pos][:3, :3]	,  a	,  atol=1e-2      )      )




    @slow
    def 					lowerCAmelCase__					(      self	:							Union[str, Any]      ):






       '''simple docstring'''






       lowercase_						:     Tuple							     =  BeitForImageClassification.from_pretrained("microsoft/beit-base-patch16-224"      ).to(a      )

       lowercase_						:     Union[str, Any]							     =  self.default_image_processor
       lowercase_						:     int							     =  prepare_img()
       lowercase_						:     Optional[int]							     =  image_processor(images=a	,  return_tensors="pt"      ).to(a      )

       # forward pass
       with torch.no_grad():
          lowercase_						:     str							     =  model(**a      )
       lowercase_						:     Any							     =  outputs.logits

       # verify the logits
       lowercase_						:     int							     =  torch.Size((1, 1_0_0_0)      )
       self.assertEqual(logits.shape	,  a      )

       lowercase_						:     str							     =  torch.tensor([-1.2385, -1.0987, -1.0108]      ).to(a      )

       self.assertTrue(torch.allclose(logits[0, :3]	,  a	,  atol=1e-4      )      )

       lowercase_						:     Optional[int]							     =  2_8_1
       self.assertEqual(logits.argmax(-1      ).item()	,  a      )




    @slow
    def 					lowerCAmelCase__					(      self	:							Optional[Any]      ):






       '''simple docstring'''






       lowercase_						:     Dict							     =  BeitForImageClassification.from_pretrained("microsoft/beit-large-patch16-224-pt22k-ft22k"      ).to(
           a      )

       lowercase_						:     Union[str, Any]							     =  self.default_image_processor
       lowercase_						:     str							     =  prepare_img()
       lowercase_						:     Any							     =  image_processor(images=a	,  return_tensors="pt"      ).to(a      )

       # forward pass
       with torch.no_grad():
          lowercase_						:     Union[str, Any]							     =  model(**a      )
       lowercase_						:     Tuple							     =  outputs.logits

       # verify the logits
       lowercase_						:     List[str]							     =  torch.Size((1, 2_1_8_4_1)      )
       self.assertEqual(logits.shape	,  a      )

       lowercase_						:     Any							     =  torch.tensor([1.6881, -0.2787, 0.5901]      ).to(a      )

       self.assertTrue(torch.allclose(logits[0, :3]	,  a	,  atol=1e-4      )      )

       lowercase_						:     Tuple							     =  2_3_9_6
       self.assertEqual(logits.argmax(-1      ).item()	,  a      )




    @slow
    def 					lowerCAmelCase__					(      self	:							str      ):






       '''simple docstring'''






       lowercase_						:     List[Any]							     =  BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"      )
       lowercase_						:     str							     =  model.to(a      )

       lowercase_						:     List[Any]							     =  BeitImageProcessor(do_resize=a	,  size=6_4_0	,  do_center_crop=a      )

       lowercase_						:     Tuple							     =  load_dataset("hf-internal-testing/fixtures_ade20k"	,  split="test"      )
       lowercase_						:     Any							     =  Image.open(ds[0]["file"]      )
       lowercase_						:     Union[str, Any]							     =  image_processor(images=a	,  return_tensors="pt"      ).to(a      )

       # forward pass
       with torch.no_grad():
          lowercase_						:     Union[str, Any]							     =  model(**a      )
       lowercase_						:     Dict							     =  outputs.logits

       # verify the logits
       lowercase_						:     Any							     =  torch.Size((1, 1_5_0, 1_6_0, 1_6_0)      )
       self.assertEqual(logits.shape	,  a      )

       lowercase_						:     Tuple							     =  version.parse(PIL.__version__      ) < version.parse("9.0.0"      )

       if is_pillow_less_than_a:
          lowercase_						:     List[Any]							     =  torch.tensor(
              [
                  [[-4.9225, -2.3954, -3.0522], [-2.8822, -1.0046, -1.7561], [-2.9549, -1.3228, -2.1347]],
                  [[-5.8168, -3.4129, -4.0778], [-3.8651, -2.2214, -3.0277], [-3.8356, -2.4643, -3.3535]],
                  [[-0.0078, 3.9952, 4.0754], [2.9856, 4.6944, 5.0035], [3.2413, 4.7813, 4.9969]],
              ]	,  device=a	,  )
       else:
          lowercase_						:     List[str]							     =  torch.tensor(
              [
                  [[-4.8960, -2.3688, -3.0355], [-2.8478, -0.9836, -1.7418], [-2.9449, -1.3332, -2.1456]],
                  [[-5.8081, -3.4124, -4.1006], [-3.8561, -2.2081, -3.0323], [-3.8365, -2.4601, -3.3669]],
                  [[-0.0309, 3.9868, 4.0540], [2.9640, 4.6877, 4.9976], [3.2081, 4.7690, 4.9942]],
              ]	,  device=a	,  )

       self.assertTrue(torch.allclose(logits[0, :3, :3, :3]	,  a	,  atol=1e-4      )      )





    @slow
    def 					lowerCAmelCase__					(      self	:							Tuple      ):






       '''simple docstring'''






       lowercase_						:     Optional[Any]							     =  BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"      )
       lowercase_						:     List[Any]							     =  model.to(a      )

       lowercase_						:     List[str]							     =  BeitImageProcessor(do_resize=a	,  size=6_4_0	,  do_center_crop=a      )

       lowercase_						:     Dict							     =  load_dataset("hf-internal-testing/fixtures_ade20k"	,  split="test"      )
       lowercase_						:     List[Any]							     =  Image.open(ds[0]["file"]      )
       lowercase_						:     Dict							     =  image_processor(images=a	,  return_tensors="pt"      ).to(a      )

       # forward pass
       with torch.no_grad():
          lowercase_						:     int							     =  model(**a      )

       lowercase_						:     Optional[Any]							     =  outputs.logits.detach().cpu()

       lowercase_						:     int							     =  image_processor.post_process_semantic_segmentation(outputs=a	,  target_sizes=[(5_0_0, 3_0_0)]      )
       lowercase_						:     Tuple							     =  torch.Size((5_0_0, 3_0_0)      )
       self.assertEqual(segmentation[0].shape	,  a      )

       lowercase_						:     List[Any]							     =  image_processor.post_process_semantic_segmentation(outputs=a      )
       lowercase_						:     List[Any]							     =  torch.Size((1_6_0, 1_6_0)      )
       self.assertEqual(segmentation[0].shape	,  a      )












'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


UpperCamelCase__			=      {
    'configuration_layoutlmv3': [
        'LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'LayoutLMv3Config',
        'LayoutLMv3OnnxConfig',
    ],
    'processing_layoutlmv3': ['LayoutLMv3Processor'],
    'tokenization_layoutlmv3': ['LayoutLMv3Tokenizer'],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCamelCase__			=      ['LayoutLMv3TokenizerFast']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCamelCase__			=      [
     'LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST',
     'LayoutLMv3ForQuestionAnswering',
     'LayoutLMv3ForSequenceClassification',
     'LayoutLMv3ForTokenClassification',
     'LayoutLMv3Model',
     'LayoutLMv3PreTrainedModel',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCamelCase__			=      [
     'TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFLayoutLMv3ForQuestionAnswering',
     'TFLayoutLMv3ForSequenceClassification',
     'TFLayoutLMv3ForTokenClassification',
     'TFLayoutLMv3Model',
     'TFLayoutLMv3PreTrainedModel',
 ]

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCamelCase__			=      ['LayoutLMv3FeatureExtractor']
 UpperCamelCase__			=      ['LayoutLMv3ImageProcessor']


if TYPE_CHECKING:
 from .configuration_layoutlmva import (
     LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP,
     LayoutLMvaConfig,
     LayoutLMvaOnnxConfig,
 )
 from .processing_layoutlmva import LayoutLMvaProcessor
 from .tokenization_layoutlmva import LayoutLMvaTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_layoutlmva import (
      LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
      LayoutLMvaForQuestionAnswering,
      LayoutLMvaForSequenceClassification,
      LayoutLMvaForTokenClassification,
      LayoutLMvaModel,
      LayoutLMvaPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_layoutlmva import (
      TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFLayoutLMvaForQuestionAnswering,
      TFLayoutLMvaForSequenceClassification,
      TFLayoutLMvaForTokenClassification,
      TFLayoutLMvaModel,
      TFLayoutLMvaPreTrainedModel,
  )

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor
  from .image_processing_layoutlmva import LayoutLMvaImageProcessor

else:
 import sys

 UpperCamelCase__			=      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




