



import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

				if is_vision_available():
								from transformers import MaskFormerImageProcessor

if is_vision_available():
				from PIL import Image





class 		UpperCAmelCase						:





			def __init__(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase=2       ,     _lowerCAmelCase=True       ,     _lowerCAmelCase=False       ,     _lowerCAmelCase=10       ,     _lowerCAmelCase=3       ,     _lowerCAmelCase=32 * 4       ,     _lowerCAmelCase=32 * 6       ,     _lowerCAmelCase=4       ,     _lowerCAmelCase=32       ,     ):
									_lowerCAmelCase 			=  parent
									_lowerCAmelCase 			=  batch_size
									_lowerCAmelCase 			=  is_training
									_lowerCAmelCase 			=  use_auxiliary_loss
									_lowerCAmelCase 			=  num_queries
									_lowerCAmelCase 			=  num_channels
									_lowerCAmelCase 			=  min_size
									_lowerCAmelCase 			=  max_size
									_lowerCAmelCase 			=  num_labels
									_lowerCAmelCase 			=  mask_feature_size





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]			).to(
									    _lowerCAmelCase			)

									_lowerCAmelCase 			=  torch.ones([self.batch_size, self.min_size, self.max_size]       ,     device=_lowerCAmelCase			)

									_lowerCAmelCase 			=  (
									    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]       ,     device=_lowerCAmelCase			) > 0.5
									).float()
									_lowerCAmelCase 			=  (torch.rand((self.batch_size, self.num_labels)       ,     device=_lowerCAmelCase			) > 0.5).long()

									_lowerCAmelCase 			=  self.get_config()
									return config, pixel_values, pixel_mask, mask_labels, class_labels





			def 	__lowerCAmelCase							(	self			):
									return MaskFormerConfig.from_backbone_and_decoder_configs(
									    backbone_config=SwinConfig(
									        depths=[1, 1, 1, 1]       ,     )       ,     decoder_config=DetrConfig(
									        decoder_ffn_dim=128       ,     num_queries=self.num_queries       ,     decoder_attention_heads=2       ,     d_model=self.mask_feature_size       ,     )       ,     mask_feature_size=self.mask_feature_size       ,     fpn_feature_size=self.mask_feature_size       ,     num_channels=self.num_channels       ,     num_labels=self.num_labels       ,     )





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase 			=  self.prepare_config_and_inputs()
									_lowerCAmelCase 			=  {'''pixel_values''': pixel_values, '''pixel_mask''': pixel_mask}
									return config, inputs_dict





			def 	__lowerCAmelCase							(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase			):
									_lowerCAmelCase 			=  output.encoder_hidden_states
									_lowerCAmelCase 			=  output.pixel_decoder_hidden_states
									_lowerCAmelCase 			=  output.transformer_decoder_hidden_states

									self.parent.assertTrue(len(_lowerCAmelCase			)       ,     len(config.backbone_config.depths			)			)
									self.parent.assertTrue(len(_lowerCAmelCase			)       ,     len(config.backbone_config.depths			)			)
									self.parent.assertTrue(len(_lowerCAmelCase			)       ,     config.decoder_config.decoder_layers			)





			def 	__lowerCAmelCase							(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase=False			):
									with torch.no_grad():
															_lowerCAmelCase 			=  MaskFormerModel(config=_lowerCAmelCase			)
															model.to(_lowerCAmelCase			)
															model.eval()

															_lowerCAmelCase 			=  model(pixel_values=_lowerCAmelCase       ,     pixel_mask=_lowerCAmelCase			)
															_lowerCAmelCase 			=  model(_lowerCAmelCase       ,     output_hidden_states=_lowerCAmelCase			)
									# the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
									# encoder and pixel decoder
									self.parent.assertEqual(
									    output.transformer_decoder_last_hidden_state.shape       ,     (self.batch_size, self.num_queries, self.mask_feature_size)       ,     )
									# let's ensure the other two hidden state exists
									self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None			)
									self.parent.assertTrue(output.encoder_last_hidden_state is not None			)

									if output_hidden_states:
															self.check_output_hidden_state(_lowerCAmelCase       ,     _lowerCAmelCase			)





			def 	__lowerCAmelCase							(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase       ,     _lowerCAmelCase			):
									_lowerCAmelCase 			=  MaskFormerForInstanceSegmentation(config=_lowerCAmelCase			)
									model.to(_lowerCAmelCase			)
									model.eval()

									def comm_check_on_output(_lowerCAmelCase			):
															# let's still check that all the required stuff is there
															self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None			)
															self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None			)
															self.parent.assertTrue(result.encoder_last_hidden_state is not None			)
															# okay, now we need to check the logits shape
															# due to the encoder compression, masks have a //4 spatial size
															self.parent.assertEqual(
															    result.masks_queries_logits.shape       ,     (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)       ,     )
															# + 1 for null class
															self.parent.assertEqual(
															    result.class_queries_logits.shape       ,     (self.batch_size, self.num_queries, self.num_labels + 1)			)

									with torch.no_grad():
															_lowerCAmelCase 			=  model(pixel_values=_lowerCAmelCase       ,     pixel_mask=_lowerCAmelCase			)
															_lowerCAmelCase 			=  model(_lowerCAmelCase			)

															comm_check_on_output(_lowerCAmelCase			)

															_lowerCAmelCase 			=  model(
															    pixel_values=_lowerCAmelCase       ,     pixel_mask=_lowerCAmelCase       ,     mask_labels=_lowerCAmelCase       ,     class_labels=_lowerCAmelCase			)

									comm_check_on_output(_lowerCAmelCase			)

									self.parent.assertTrue(result.loss is not None			)
									self.parent.assertEqual(result.loss.shape       ,     torch.Size([1]			)			)






@require_torch
class 		UpperCAmelCase						(						snake_case_       ,snake_case_       ,unittest.TestCase				):
			SCREAMING_SNAKE_CASE__							=     (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
			SCREAMING_SNAKE_CASE__							=     (
			    {'''feature-extraction''': MaskFormerModel, '''image-segmentation''': MaskFormerForInstanceSegmentation}
			    if is_torch_available()
			    else {}
			)

			SCREAMING_SNAKE_CASE__							=     False
			SCREAMING_SNAKE_CASE__							=     False
			SCREAMING_SNAKE_CASE__							=     False
			SCREAMING_SNAKE_CASE__							=     False





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  MaskFormerModelTester(self			)
									_lowerCAmelCase 			=  ConfigTester(self       ,     config_class=_lowerCAmelCase       ,     has_text_modality=_lowerCAmelCase			)





			def 	__lowerCAmelCase							(	self			):
									self.config_tester.run_common_tests()





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase			,   _lowerCAmelCase 			=  self.model_tester.prepare_config_and_inputs_for_common()
									self.model_tester.create_and_check_maskformer_model(_lowerCAmelCase       ,     **_lowerCAmelCase       ,     output_hidden_states=_lowerCAmelCase			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_lowerCAmelCase			)





			@unittest.skip(reason='''MaskFormer does not use inputs_embeds'''			)
			def 	__lowerCAmelCase							(	self			):
									pass





			@unittest.skip(reason='''MaskFormer does not have a get_input_embeddings method'''			)
			def 	__lowerCAmelCase							(	self			):
									pass





			@unittest.skip(reason='''MaskFormer is not a generative model'''			)
			def 	__lowerCAmelCase							(	self			):
									pass





			@unittest.skip(reason='''MaskFormer does not use token embeddings'''			)
			def 	__lowerCAmelCase							(	self			):
									pass





			@require_torch_multi_gpu
			@unittest.skip(
			    reason='''MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''			)
			def 	__lowerCAmelCase							(	self			):
									pass





			@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''			)
			def 	__lowerCAmelCase							(	self			):
									pass





			def 	__lowerCAmelCase							(	self			):
									_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			)





			@slow
			def 	__lowerCAmelCase							(	self			):
									for model_name in ["facebook/maskformer-swin-small-coco"]:
															_lowerCAmelCase 			=  MaskFormerModel.from_pretrained(_lowerCAmelCase			)
															self.assertIsNotNone(_lowerCAmelCase			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  (self.model_tester.min_size,) * 2
									_lowerCAmelCase 			=  {
									    '''pixel_values''': torch.randn((2, 3, *size)       ,     device=_lowerCAmelCase			),
									    '''mask_labels''': torch.randn((2, 10, *size)       ,     device=_lowerCAmelCase			),
									    '''class_labels''': torch.zeros(2       ,     10       ,     device=_lowerCAmelCase			).long(),
									}

									_lowerCAmelCase 			=  MaskFormerForInstanceSegmentation(MaskFormerConfig()			).to(_lowerCAmelCase			)
									_lowerCAmelCase 			=  model(**_lowerCAmelCase			)
									self.assertTrue(outputs.loss is not None			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase			,   _lowerCAmelCase 			=  self.model_tester.prepare_config_and_inputs_for_common()
									self.model_tester.create_and_check_maskformer_model(_lowerCAmelCase       ,     **_lowerCAmelCase       ,     output_hidden_states=_lowerCAmelCase			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase			,   _lowerCAmelCase 			=  self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
															_lowerCAmelCase 			=  model_class(_lowerCAmelCase			).to(_lowerCAmelCase			)
															_lowerCAmelCase 			=  model(**_lowerCAmelCase       ,     output_attentions=_lowerCAmelCase			)
															self.assertTrue(outputs.attentions is not None			)





			def 	__lowerCAmelCase							(	self			):
									if not self.model_tester.is_training:
															return
									# only MaskFormerForInstanceSegmentation has the loss
									_lowerCAmelCase 			=  self.all_model_classes[1]
									_lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase 			=  self.model_tester.prepare_config_and_inputs()

									_lowerCAmelCase 			=  model_class(_lowerCAmelCase			)
									model.to(_lowerCAmelCase			)
									model.train()

									_lowerCAmelCase 			=  model(_lowerCAmelCase       ,     mask_labels=_lowerCAmelCase       ,     class_labels=_lowerCAmelCase			).loss
									loss.backward()





			def 	__lowerCAmelCase							(	self			):
									# only MaskFormerForInstanceSegmentation has the loss
									_lowerCAmelCase 			=  self.all_model_classes[1]
									_lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase			,   _lowerCAmelCase 			=  self.model_tester.prepare_config_and_inputs()
									_lowerCAmelCase 			=  True
									_lowerCAmelCase 			=  True

									_lowerCAmelCase 			=  model_class(_lowerCAmelCase			)
									model.to(_lowerCAmelCase			)
									model.train()

									_lowerCAmelCase 			=  model(_lowerCAmelCase       ,     mask_labels=_lowerCAmelCase       ,     class_labels=_lowerCAmelCase			)

									_lowerCAmelCase 			=  outputs.encoder_hidden_states[0]
									encoder_hidden_states.retain_grad()

									_lowerCAmelCase 			=  outputs.pixel_decoder_hidden_states[0]
									pixel_decoder_hidden_states.retain_grad()
									# we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
									_lowerCAmelCase 			=  outputs.transformer_decoder_hidden_states[0]
									transformer_decoder_hidden_states.retain_grad()

									_lowerCAmelCase 			=  outputs.attentions[0]
									attentions.retain_grad()

									outputs.loss.backward(retain_graph=_lowerCAmelCase			)

									self.assertIsNotNone(encoder_hidden_states.grad			)
									self.assertIsNotNone(pixel_decoder_hidden_states.grad			)
									self.assertIsNotNone(transformer_decoder_hidden_states.grad			)
									self.assertIsNotNone(attentions.grad			)






UpperCAmelCase_									=							1E-4
def 							UpperCAmelCase__		(				)->Union[str, Any]:
						_lowerCAmelCase 			=  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
						return image





@require_vision
@slow
class 		UpperCAmelCase						(						unittest.TestCase				):





			@cached_property
			def 	__lowerCAmelCase							(	self			):
									return (
									    MaskFormerImageProcessor.from_pretrained('''facebook/maskformer-swin-small-coco'''			)
									    if is_vision_available()
									    else None
									)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  MaskFormerModel.from_pretrained('''facebook/maskformer-swin-small-coco'''			).to(_lowerCAmelCase			)
									_lowerCAmelCase 			=  self.default_image_processor
									_lowerCAmelCase 			=  prepare_img()
									_lowerCAmelCase 			=  image_processor(_lowerCAmelCase       ,     return_tensors='''pt'''			).to(_lowerCAmelCase			)
									_lowerCAmelCase 			=  inputs['''pixel_values'''].shape
									# check size is divisible by 32
									self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0			)
									# check size
									self.assertEqual(_lowerCAmelCase       ,     (1, 3, 800, 1_088)			)

									with torch.no_grad():
															_lowerCAmelCase 			=  model(**_lowerCAmelCase			)

									_lowerCAmelCase 			=  torch.tensor(
									    [[-0.0_482, 0.9_228, 0.4_951], [-0.2_547, 0.8_017, 0.8_527], [-0.0_069, 0.3_385, -0.0_089]]			).to(_lowerCAmelCase			)
									self.assertTrue(
									    torch.allclose(
									        outputs.encoder_last_hidden_state[0, 0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)

									_lowerCAmelCase 			=  torch.tensor(
									    [[-0.8_422, -0.8_434, -0.9_718], [-1.0_144, -0.5_565, -0.4_195], [-1.0_038, -0.4_484, -0.1_961]]			).to(_lowerCAmelCase			)
									self.assertTrue(
									    torch.allclose(
									        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)

									_lowerCAmelCase 			=  torch.tensor(
									    [[0.2_852, -0.0_159, 0.9_735], [0.6_254, 0.1_858, 0.8_529], [-0.0_680, -0.4_116, 1.8_413]]			).to(_lowerCAmelCase			)
									self.assertTrue(
									    torch.allclose(
									        outputs.transformer_decoder_last_hidden_state[0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  (
									    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''			)
									    .to(_lowerCAmelCase			)
									    .eval()
									)
									_lowerCAmelCase 			=  self.default_image_processor
									_lowerCAmelCase 			=  prepare_img()
									_lowerCAmelCase 			=  image_processor(_lowerCAmelCase       ,     return_tensors='''pt'''			).to(_lowerCAmelCase			)
									_lowerCAmelCase 			=  inputs['''pixel_values'''].shape
									# check size is divisible by 32
									self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0			)
									# check size
									self.assertEqual(_lowerCAmelCase       ,     (1, 3, 800, 1_088)			)

									with torch.no_grad():
															_lowerCAmelCase 			=  model(**_lowerCAmelCase			)
									# masks_queries_logits
									_lowerCAmelCase 			=  outputs.masks_queries_logits
									self.assertEqual(
									    masks_queries_logits.shape       ,     (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)       ,     )
									_lowerCAmelCase 			=  [
									    [-1.3_737_124, -1.7_724_937, -1.9_364_233],
									    [-1.5_977_281, -1.9_867_939, -2.1_523_695],
									    [-1.5_795_398, -1.9_269_832, -2.093_942],
									]
									_lowerCAmelCase 			=  torch.tensor(_lowerCAmelCase			).to(_lowerCAmelCase			)
									self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)
									# class_queries_logits
									_lowerCAmelCase 			=  outputs.class_queries_logits
									self.assertEqual(
									    class_queries_logits.shape       ,     (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)			)
									_lowerCAmelCase 			=  torch.tensor(
									    [
									        [1.6512E00, -5.2572E00, -3.3519E00],
									        [3.6169E-02, -5.9025E00, -2.9313E00],
									        [1.0766E-04, -7.7630E00, -5.1263E00],
									    ]			).to(_lowerCAmelCase			)
									self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  (
									    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-resnet101-coco-stuff'''			)
									    .to(_lowerCAmelCase			)
									    .eval()
									)
									_lowerCAmelCase 			=  self.default_image_processor
									_lowerCAmelCase 			=  prepare_img()
									_lowerCAmelCase 			=  image_processor(_lowerCAmelCase       ,     return_tensors='''pt'''			).to(_lowerCAmelCase			)
									_lowerCAmelCase 			=  inputs['''pixel_values'''].shape
									# check size is divisible by 32
									self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0			)
									# check size
									self.assertEqual(_lowerCAmelCase       ,     (1, 3, 800, 1_088)			)

									with torch.no_grad():
															_lowerCAmelCase 			=  model(**_lowerCAmelCase			)
									# masks_queries_logits
									_lowerCAmelCase 			=  outputs.masks_queries_logits
									self.assertEqual(
									    masks_queries_logits.shape       ,     (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)       ,     )
									_lowerCAmelCase 			=  [[-0.9_046, -2.6_366, -4.6_062], [-3.4_179, -5.7_890, -8.8_057], [-4.9_179, -7.6_560, -10.7_711]]
									_lowerCAmelCase 			=  torch.tensor(_lowerCAmelCase			).to(_lowerCAmelCase			)
									self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)
									# class_queries_logits
									_lowerCAmelCase 			=  outputs.class_queries_logits
									self.assertEqual(
									    class_queries_logits.shape       ,     (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)			)
									_lowerCAmelCase 			=  torch.tensor(
									    [[4.7_188, -3.2_585, -2.8_857], [6.6_871, -2.9_181, -1.2_487], [7.2_449, -2.2_764, -2.1_874]]			).to(_lowerCAmelCase			)
									self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]       ,     _lowerCAmelCase       ,     atol=_lowerCAmelCase			)			)





			def 	__lowerCAmelCase							(	self			):
									_lowerCAmelCase 			=  (
									    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''			)
									    .to(_lowerCAmelCase			)
									    .eval()
									)
									_lowerCAmelCase 			=  self.default_image_processor

									_lowerCAmelCase 			=  image_processor(
									    [np.zeros((3, 800, 1_333)			), np.zeros((3, 800, 1_333)			)]       ,     segmentation_maps=[np.zeros((384, 384)			).astype(np.floataa			), np.zeros((384, 384)			).astype(np.floataa			)]       ,     return_tensors='''pt'''       ,     )

									_lowerCAmelCase 			=  inputs['''pixel_values'''].to(_lowerCAmelCase			)
									_lowerCAmelCase 			=  [el.to(_lowerCAmelCase			) for el in inputs['''mask_labels''']]
									_lowerCAmelCase 			=  [el.to(_lowerCAmelCase			) for el in inputs['''class_labels''']]

									with torch.no_grad():
															_lowerCAmelCase 			=  model(**_lowerCAmelCase			)

									self.assertTrue(outputs.loss is not None			)




from typing import TYPE_CHECKING

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


UpperCAmelCase_									=							{"processing_layoutxlm": ["LayoutXLMProcessor"]}

try:
    if not is_sentencepiece_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCAmelCase_									=							["LayoutXLMTokenizer"]

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    UpperCAmelCase_									=							["LayoutXLMTokenizerFast"]

if TYPE_CHECKING:
    from .processing_layoutxlm import LayoutXLMProcessor

    try:
        if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_layoutxlm import LayoutXLMTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_layoutxlm_fast import LayoutXLMTokenizerFast

else:
    import sys

    UpperCAmelCase_									=							_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)