




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     SCREAMING_SNAKE_CASE__		:
     def __init__(						self	:		Dict       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		Tuple=1_00       ,						__lowerCamelCase	:		List[Any]=13       ,						__lowerCamelCase	:		Optional[int]=30       ,						__lowerCamelCase	:		List[str]=2       ,						__lowerCamelCase	:		Optional[Any]=3       ,						__lowerCamelCase	:		int=True       ,						__lowerCamelCase	:		int=True       ,						__lowerCamelCase	:		str=32       ,						__lowerCamelCase	:		List[Any]=4       ,						__lowerCamelCase	:		Tuple=4       ,						__lowerCamelCase	:		Tuple=37       ,						__lowerCamelCase	:		List[Any]="gelu"       ,						__lowerCamelCase	:		List[Any]=0.1       ,						__lowerCamelCase	:		Dict=0.1       ,						__lowerCamelCase	:		Union[str, Any]=10       ,						__lowerCamelCase	:		Any=0.02       ,						__lowerCamelCase	:		str=3       ,						__lowerCamelCase	:		Union[str, Any]=None       ,						__lowerCamelCase	:		str=[0, 1, 2, 3]       ,						):



       """simple docstring"""
       lowerCAmelCase__										=      parent
       lowerCAmelCase__										=      1_00
       lowerCAmelCase__										=      batch_size
       lowerCAmelCase__										=      image_size
       lowerCAmelCase__										=      patch_size
       lowerCAmelCase__										=      num_channels
       lowerCAmelCase__										=      is_training
       lowerCAmelCase__										=      use_labels
       lowerCAmelCase__										=      hidden_size
       lowerCAmelCase__										=      num_hidden_layers
       lowerCAmelCase__										=      num_attention_heads
       lowerCAmelCase__										=      intermediate_size
       lowerCAmelCase__										=      hidden_act
       lowerCAmelCase__										=      hidden_dropout_prob
       lowerCAmelCase__										=      attention_probs_dropout_prob
       lowerCAmelCase__										=      type_sequence_label_size
       lowerCAmelCase__										=      initializer_range
       lowerCAmelCase__										=      scope
       lowerCAmelCase__										=      out_indices
       lowerCAmelCase__										=      num_labels

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



       """simple docstring"""
       lowerCAmelCase__										=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

       lowerCAmelCase__										=      None
       lowerCAmelCase__										=      None
       if self.use_labels:
         lowerCAmelCase__										=      ids_tensor([self.batch_size]       ,						self.type_sequence_label_size						)
         lowerCAmelCase__										=      ids_tensor([self.batch_size, self.image_size, self.image_size]       ,						self.num_labels						)

       lowerCAmelCase__										=      self.get_config()

       return config, pixel_values, labels, pixel_labels
     def        A__      (						self	:		Tuple						):



       """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=__lowerCamelCase       ,						initializer_range=self.initializer_range       ,						out_indices=self.out_indices       ,						)
     def        A__      (						self	:		Optional[Any]       ,						__lowerCamelCase	:		str       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		Any       ,						__lowerCamelCase	:		str						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitModel(config=__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase						)
       self.parent.assertEqual(result.last_hidden_state.shape       ,						(self.batch_size, self.seq_length, self.hidden_size)						)
     def        A__      (						self	:		List[Any]       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		Optional[Any]       ,						__lowerCamelCase	:		Optional[int]       ,						__lowerCamelCase	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitForMaskedImageModeling(config=__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.seq_length - 1, self.vocab_size)						)
     def        A__      (						self	:		Dict       ,						__lowerCamelCase	:		Optional[Any]       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		Optional[Any]       ,						__lowerCamelCase	:		Dict						):



       """simple docstring"""
       lowerCAmelCase__										=      self.type_sequence_label_size
       lowerCAmelCase__										=      BeitForImageClassification(__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase       ,						labels=__lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.type_sequence_label_size)						)

       # test greyscale images
       lowerCAmelCase__										=      1
       lowerCAmelCase__										=      BeitForImageClassification(__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()

       lowerCAmelCase__										=      floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
       lowerCAmelCase__										=      model(__lowerCamelCase       ,						labels=__lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.type_sequence_label_size)						)
     def        A__      (						self	:		Any       ,						__lowerCamelCase	:		List[str]       ,						__lowerCamelCase	:		Union[str, Any]       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		List[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.num_labels
       lowerCAmelCase__										=      BeitForSemanticSegmentation(__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase						)
       self.parent.assertEqual(
           result.logits.shape       ,						(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)						)
       lowerCAmelCase__										=      model(__lowerCamelCase       ,						labels=__lowerCamelCase						)
       self.parent.assertEqual(
           result.logits.shape       ,						(self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)						)



     def        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.prepare_config_and_inputs()
       lowerCAmelCase__				,      lowerCAmelCase__				,      lowerCAmelCase__				,      lowerCAmelCase__										=      config_and_inputs
       lowerCAmelCase__										=      {'''pixel_values''': pixel_values}
       return config, inputs_dict





@require_torch
class     SCREAMING_SNAKE_CASE__		(_a    ,					_a    ,					unittest.TestCase			):
     lowercase_ :      Optional[int]				= (
         (BeitModel, BeitForImageClassification, BeitForMaskedImageModeling, BeitForSemanticSegmentation)
         if is_torch_available()
         else ()
     )
     lowercase_ :      str				= (
         {
             "feature-extraction": BeitModel,
             "image-classification": BeitForImageClassification,
             "image-segmentation": BeitForSemanticSegmentation,
         }
         if is_torch_available()
         else {}
     )

     lowercase_ :      Union[str, Any]				= False
     lowercase_ :      List[str]				= False
     lowercase_ :      int				= False
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitModelTester(self						)
       lowerCAmelCase__										=      ConfigTester(self       ,						config_class=__lowerCamelCase       ,						has_text_modality=__lowerCamelCase       ,						hidden_size=37						)
     def        A__      (						self	:		int						):



       """simple docstring"""
       self.config_tester.run_common_tests()
     @unittest.skip(reason='''BEiT does not use inputs_embeds'''						)
     def        A__      (						self	:		List[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        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       pass
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__				,      lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         lowerCAmelCase__										=      model_class(__lowerCamelCase						)
         self.assertIsInstance(model.get_input_embeddings()       ,						(nn.Module)						)
         lowerCAmelCase__										=      model.get_output_embeddings()
         self.assertTrue(x is None or isinstance(__lowerCamelCase       ,						nn.Linear						)						)
     def        A__      (						self	:		List[str]						):



       """simple docstring"""
       lowerCAmelCase__				,      lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
         lowerCAmelCase__										=      model_class(__lowerCamelCase						)
         lowerCAmelCase__										=      inspect.signature(model.forward						)
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         lowerCAmelCase__										=      [*signature.parameters.keys()]

         lowerCAmelCase__										=      ['''pixel_values''']
         self.assertListEqual(arg_names[:1]       ,						__lowerCamelCase						)
     def        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__lowerCamelCase						)
     def        A__      (						self	:		str						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase						)
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase						)
     def        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_semantic_segmentation(*__lowerCamelCase						)
     def        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       if not self.model_tester.is_training:
         return

       lowerCAmelCase__				,      lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs_for_common()
       lowerCAmelCase__										=      True

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

         lowerCAmelCase__										=      model_class(__lowerCamelCase						)
         model.to(__lowerCamelCase						)
         model.train()
         lowerCAmelCase__										=      self._prepare_for_class(__lowerCamelCase       ,						__lowerCamelCase       ,						return_labels=__lowerCamelCase						)
         lowerCAmelCase__										=      model(**__lowerCamelCase						).loss
         loss.backward()
     def        A__      (						self	:		str						):



       """simple docstring"""
       lowerCAmelCase__				,      lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs_for_common()
       if not self.model_tester.is_training:
         return

       lowerCAmelCase__										=      False
       lowerCAmelCase__										=      True

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

         lowerCAmelCase__										=      model_class(__lowerCamelCase						)
         model.gradient_checkpointing_enable()
         model.to(__lowerCamelCase						)
         model.train()
         lowerCAmelCase__										=      self._prepare_for_class(__lowerCamelCase       ,						__lowerCamelCase       ,						return_labels=__lowerCamelCase						)
         lowerCAmelCase__										=      model(**__lowerCamelCase						).loss
         loss.backward()
     def        A__      (						self	:		str						):



       """simple docstring"""
       lowerCAmelCase__				,      lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs_for_common()

       lowerCAmelCase__										=      _config_zero_init(__lowerCamelCase						)
       for model_class in self.all_model_classes:
         lowerCAmelCase__										=      model_class(config=__lowerCamelCase						)
         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        A__      (						self	:		List[str]						):



       """simple docstring"""
       for model_name in BEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         lowerCAmelCase__										=      BeitModel.from_pretrained(__lowerCamelCase						)
         self.assertIsNotNone(__lowerCamelCase						)



def 		a_							( ):
  lowerCAmelCase__										=      Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
  return image





@require_torch
@require_vision
class     SCREAMING_SNAKE_CASE__		(unittest.TestCase			):
     @cached_property
     def        A__      (						self	:		Optional[int]						):



       """simple docstring"""
       return BeitImageProcessor.from_pretrained('''microsoft/beit-base-patch16-224'''						) if is_vision_available() else None
     @slow
     def        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitForMaskedImageModeling.from_pretrained('''microsoft/beit-base-patch16-224-pt22k'''						).to(__lowerCamelCase						)

       lowerCAmelCase__										=      self.default_image_processor
       lowerCAmelCase__										=      prepare_img()
       lowerCAmelCase__										=      image_processor(images=__lowerCamelCase       ,						return_tensors='''pt'''						).pixel_values.to(__lowerCamelCase						)

       # prepare bool_masked_pos
       lowerCAmelCase__										=      torch.ones((1, 1_96)       ,						dtype=torch.bool						).to(__lowerCamelCase						)

       # forward pass
       with torch.no_grad():
         lowerCAmelCase__										=      model(pixel_values=__lowerCamelCase       ,						bool_masked_pos=__lowerCamelCase						)
       lowerCAmelCase__										=      outputs.logits

       # verify the logits
       lowerCAmelCase__										=      torch.Size((1, 1_96, 81_92)						)
       self.assertEqual(logits.shape       ,						__lowerCamelCase						)

       lowerCAmelCase__										=      torch.tensor(
           [[-3.2437, 0.5072, -13.9174], [-3.2456, 0.4948, -13.9401], [-3.2033, 0.5121, -13.8550]]						).to(__lowerCamelCase						)

       self.assertTrue(torch.allclose(logits[bool_masked_pos][:3, :3]       ,						__lowerCamelCase       ,						atol=1e-2						)						)
     @slow
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitForImageClassification.from_pretrained('''microsoft/beit-base-patch16-224'''						).to(__lowerCamelCase						)

       lowerCAmelCase__										=      self.default_image_processor
       lowerCAmelCase__										=      prepare_img()
       lowerCAmelCase__										=      image_processor(images=__lowerCamelCase       ,						return_tensors='''pt'''						).to(__lowerCamelCase						)

       # forward pass
       with torch.no_grad():
         lowerCAmelCase__										=      model(**__lowerCamelCase						)
       lowerCAmelCase__										=      outputs.logits

       # verify the logits
       lowerCAmelCase__										=      torch.Size((1, 10_00)						)
       self.assertEqual(logits.shape       ,						__lowerCamelCase						)

       lowerCAmelCase__										=      torch.tensor([-1.2385, -1.0987, -1.0108]						).to(__lowerCamelCase						)

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

       lowerCAmelCase__										=      2_81
       self.assertEqual(logits.argmax(-1						).item()       ,						__lowerCamelCase						)
     @slow
     def        A__      (						self	:		Optional[int]						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitForImageClassification.from_pretrained('''microsoft/beit-large-patch16-224-pt22k-ft22k'''						).to(
           __lowerCamelCase						)

       lowerCAmelCase__										=      self.default_image_processor
       lowerCAmelCase__										=      prepare_img()
       lowerCAmelCase__										=      image_processor(images=__lowerCamelCase       ,						return_tensors='''pt'''						).to(__lowerCamelCase						)

       # forward pass
       with torch.no_grad():
         lowerCAmelCase__										=      model(**__lowerCamelCase						)
       lowerCAmelCase__										=      outputs.logits

       # verify the logits
       lowerCAmelCase__										=      torch.Size((1, 2_18_41)						)
       self.assertEqual(logits.shape       ,						__lowerCamelCase						)

       lowerCAmelCase__										=      torch.tensor([1.6881, -0.2787, 0.5901]						).to(__lowerCamelCase						)

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

       lowerCAmelCase__										=      23_96
       self.assertEqual(logits.argmax(-1						).item()       ,						__lowerCamelCase						)
     @slow
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      BeitForSemanticSegmentation.from_pretrained('''microsoft/beit-base-finetuned-ade-640-640'''						)
       lowerCAmelCase__										=      model.to(__lowerCamelCase						)

       lowerCAmelCase__										=      BeitImageProcessor(do_resize=__lowerCamelCase       ,						size=6_40       ,						do_center_crop=__lowerCamelCase						)

       lowerCAmelCase__										=      load_dataset('''hf-internal-testing/fixtures_ade20k'''       ,						split='''test'''						)
       lowerCAmelCase__										=      Image.open(ds[0]['''file''']						)
       lowerCAmelCase__										=      image_processor(images=__lowerCamelCase       ,						return_tensors='''pt'''						).to(__lowerCamelCase						)

       # forward pass
       with torch.no_grad():
         lowerCAmelCase__										=      model(**__lowerCamelCase						)
       lowerCAmelCase__										=      outputs.logits

       # verify the logits
       lowerCAmelCase__										=      torch.Size((1, 1_50, 1_60, 1_60)						)
       self.assertEqual(logits.shape       ,						__lowerCamelCase						)

       lowerCAmelCase__										=      version.parse(PIL.__version__						) < version.parse('''9.0.0'''						)

       if is_pillow_less_than_a:
         lowerCAmelCase__										=      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=__lowerCamelCase       ,						)
       else:
         lowerCAmelCase__										=      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=__lowerCamelCase       ,						)

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



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



       """simple docstring"""
       lowerCAmelCase__										=      BeitForSemanticSegmentation.from_pretrained('''microsoft/beit-base-finetuned-ade-640-640'''						)
       lowerCAmelCase__										=      model.to(__lowerCamelCase						)

       lowerCAmelCase__										=      BeitImageProcessor(do_resize=__lowerCamelCase       ,						size=6_40       ,						do_center_crop=__lowerCamelCase						)

       lowerCAmelCase__										=      load_dataset('''hf-internal-testing/fixtures_ade20k'''       ,						split='''test'''						)
       lowerCAmelCase__										=      Image.open(ds[0]['''file''']						)
       lowerCAmelCase__										=      image_processor(images=__lowerCamelCase       ,						return_tensors='''pt'''						).to(__lowerCamelCase						)

       # forward pass
       with torch.no_grad():
         lowerCAmelCase__										=      model(**__lowerCamelCase						)

       lowerCAmelCase__										=      outputs.logits.detach().cpu()

       lowerCAmelCase__										=      image_processor.post_process_semantic_segmentation(outputs=__lowerCamelCase       ,						target_sizes=[(5_00, 3_00)]						)
       lowerCAmelCase__										=      torch.Size((5_00, 3_00)						)
       self.assertEqual(segmentation[0].shape       ,						__lowerCamelCase						)

       lowerCAmelCase__										=      image_processor.post_process_semantic_segmentation(outputs=__lowerCamelCase						)
       lowerCAmelCase__										=      torch.Size((1_60, 1_60)						)
       self.assertEqual(segmentation[0].shape       ,						__lowerCamelCase						)







from typing import TYPE_CHECKING

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


__magic_name__  :  Any					=       {
    """configuration_layoutlmv2""": ["""LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LayoutLMv2Config"""],
    """processing_layoutlmv2""": ["""LayoutLMv2Processor"""],
    """tokenization_layoutlmv2""": ["""LayoutLMv2Tokenizer"""],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  List[str]					=       ["""LayoutLMv2TokenizerFast"""]

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  Any					=       ["""LayoutLMv2FeatureExtractor"""]
      __magic_name__  :  Any					=       ["""LayoutLMv2ImageProcessor"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  Any					=       [
          """LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """LayoutLMv2ForQuestionAnswering""",
          """LayoutLMv2ForSequenceClassification""",
          """LayoutLMv2ForTokenClassification""",
          """LayoutLMv2Layer""",
          """LayoutLMv2Model""",
          """LayoutLMv2PreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
      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_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

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

      __magic_name__  :  Union[str, Any]					=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

