



'''simple docstring'''

import inspect
import unittest
import warnings

from transformers import DeiTConfig
from transformers.models.auto import get_values
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_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, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch
				from torch import nn

				from transformers import (
				    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
				    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
				    MODEL_MAPPING,
				    DeiTForImageClassification,
				    DeiTForImageClassificationWithTeacher,
				    DeiTForMaskedImageModeling,
				    DeiTModel,
				)
				from transformers.models.deit.modeling_deit import DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import DeiTImageProcessor
class __snake_case:


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_=13     ,	A_=30     ,	A_=2     ,	A_=3     ,	A_=True     ,	A_=True     ,	A_=32     ,	A_=5     ,	A_=4     ,	A_=37     ,	A_="gelu"     ,	A_=0.1     ,	A_=0.1     ,	A_=10     ,	A_=0.0_2     ,	A_=3     ,	A_=None     ,	A_=2     ,	)     ->     Optional[int]:
							lowerCAmelCase   =     parent
							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   =     encoder_stride

							# in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
							lowerCAmelCase   =     (image_size // patch_size) ** 2
							lowerCAmelCase   =     num_patches + 2


						def     __snake_case   ( self				)     ->     Dict:
							lowerCAmelCase   =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

							lowerCAmelCase   =     None
							if self.use_labels:
								lowerCAmelCase   =     ids_tensor([self.batch_size]     ,	self.type_sequence_label_size				)

							lowerCAmelCase   =     self.get_config()

							return config, pixel_values, labels


						def     __snake_case   ( self				)     ->     Optional[int]:
							return DeiTConfig(
							    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=snake_case__     ,	initializer_range=self.initializer_range     ,	encoder_stride=self.encoder_stride     ,	)


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_				)     ->     List[Any]:
							lowerCAmelCase   =     DeiTModel(config=snake_case__				)
							model.to(snake_case__				)
							model.eval()
							lowerCAmelCase   =     model(snake_case__				)
							self.parent.assertEqual(result.last_hidden_state.shape     ,	(self.batch_size, self.seq_length, self.hidden_size)				)


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_				)     ->     List[Any]:
							lowerCAmelCase   =     DeiTForMaskedImageModeling(config=snake_case__				)
							model.to(snake_case__				)
							model.eval()
							lowerCAmelCase   =     model(snake_case__				)
							self.parent.assertEqual(
							    result.reconstruction.shape     ,	(self.batch_size, self.num_channels, self.image_size, self.image_size)				)

							# test greyscale images
							lowerCAmelCase   =     1
							lowerCAmelCase   =     DeiTForMaskedImageModeling(snake_case__				)
							model.to(snake_case__				)
							model.eval()

							lowerCAmelCase   =     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]				)
							lowerCAmelCase   =     model(snake_case__				)
							self.parent.assertEqual(result.reconstruction.shape     ,	(self.batch_size, 1, self.image_size, self.image_size)				)


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_				)     ->     List[Any]:
							lowerCAmelCase   =     self.type_sequence_label_size
							lowerCAmelCase   =     DeiTForImageClassification(snake_case__				)
							model.to(snake_case__				)
							model.eval()
							lowerCAmelCase   =     model(snake_case__     ,	labels=snake_case__				)
							self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.type_sequence_label_size)				)

							# test greyscale images
							lowerCAmelCase   =     1
							lowerCAmelCase   =     DeiTForImageClassification(snake_case__				)
							model.to(snake_case__				)
							model.eval()

							lowerCAmelCase   =     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]				)
							lowerCAmelCase   =     model(snake_case__     ,	labels=snake_case__				)
							self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.type_sequence_label_size)				)




						def     __snake_case   ( self				)     ->     int:
							lowerCAmelCase   =     self.prepare_config_and_inputs()
							(
							    lowerCAmelCase       
							)   =     config_and_inputs
							lowerCAmelCase   =     {'pixel_values': pixel_values}
							return config, inputs_dict







@require_torch
class __snake_case(				SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_		,							unittest.TestCase ):


						'''simple docstring'''



						UpperCAmelCase							:   str									=		(
						    (
						        DeiTModel,
						        DeiTForImageClassification,
						        DeiTForImageClassificationWithTeacher,
						        DeiTForMaskedImageModeling,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCAmelCase							:   List[str]									=		(
						    {
						        "feature-extraction": DeiTModel,
						        "image-classification": (DeiTForImageClassification, DeiTForImageClassificationWithTeacher),
						    }
						    if is_torch_available()
						    else {}
						)

						UpperCAmelCase							:   Any									=		False
						UpperCAmelCase							:   Union[str, Any]									=		False
						UpperCAmelCase							:   List[Any]									=		False


						def     __snake_case   ( self				)     ->     Optional[int]:
							lowerCAmelCase   =     DeiTModelTester(self				)
							lowerCAmelCase   =     ConfigTester(self     ,	config_class=snake_case__     ,	has_text_modality=snake_case__     ,	hidden_size=37				)


						def     __snake_case   ( self				)     ->     Tuple:
							self.config_tester.run_common_tests()


						@unittest.skip(reason="""DeiT does not use inputs_embeds"""				)
						def     __snake_case   ( self				)     ->     List[str]:
							pass


						def     __snake_case   ( self				)     ->     Any:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
								lowerCAmelCase   =     model_class(snake_case__				)
								self.assertIsInstance(model.get_input_embeddings()     ,	(nn.Module)				)
								lowerCAmelCase   =     model.get_output_embeddings()
								self.assertTrue(x is None or isinstance(snake_case__     ,	nn.Linear				)				)


						def     __snake_case   ( self				)     ->     Any:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
								lowerCAmelCase   =     model_class(snake_case__				)
								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]     ,	snake_case__				)


						def     __snake_case   ( self				)     ->     Tuple:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*snake_case__				)


						def     __snake_case   ( self				)     ->     Dict:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_image_modeling(*snake_case__				)


						def     __snake_case   ( self				)     ->     str:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*snake_case__				)


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_=False				)     ->     List[Any]:
							lowerCAmelCase   =     super()._prepare_for_class(snake_case__     ,	snake_case__     ,	return_labels=snake_case__				)

							if return_labels:
								if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
									del inputs_dict["labels"]

							return inputs_dict


						def     __snake_case   ( self				)     ->     Optional[int]:

							if not self.model_tester.is_training:
								return

							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs_for_common()
							lowerCAmelCase   =     True

							for model_class in self.all_model_classes:
								# DeiTForImageClassificationWithTeacher supports inference-only
								if (
								    model_class in get_values(snake_case__				)
								    or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
								):
									continue
								lowerCAmelCase   =     model_class(snake_case__				)
								model.to(snake_case__				)
								model.train()
								lowerCAmelCase   =     self._prepare_for_class(snake_case__     ,	snake_case__     ,	return_labels=snake_case__				)
								lowerCAmelCase   =     model(**snake_case__				).loss
								loss.backward()


						def     __snake_case   ( self				)     ->     Tuple:
							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:
								if model_class in get_values(snake_case__				) or not model_class.supports_gradient_checkpointing:
									continue
								# DeiTForImageClassificationWithTeacher supports inference-only
								if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
									continue
								lowerCAmelCase   =     model_class(snake_case__				)
								model.gradient_checkpointing_enable()
								model.to(snake_case__				)
								model.train()
								lowerCAmelCase   =     self._prepare_for_class(snake_case__     ,	snake_case__     ,	return_labels=snake_case__				)
								lowerCAmelCase   =     model(**snake_case__				).loss
								loss.backward()


						def     __snake_case   ( self				)     ->     Optional[Any]:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs_for_common()

							lowerCAmelCase   =     [
							    {'title': 'multi_label_classification', 'num_labels': 2, 'dtype': torch.float},
							    {'title': 'single_label_classification', 'num_labels': 1, 'dtype': torch.long},
							    {'title': 'regression', 'num_labels': 1, 'dtype': torch.float},
							]

							for model_class in self.all_model_classes:
								if (
								    model_class
								    not in [
								        *get_values(snake_case__				),
								        *get_values(snake_case__				),
								    ]
								    or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
								):
									continue

								for problem_type in problem_types:
									with self.subTest(msg=f'Testing {model_class} with {problem_type["title"]}'				):
										lowerCAmelCase   =     problem_type['title']
										lowerCAmelCase   =     problem_type['num_labels']

										lowerCAmelCase   =     model_class(snake_case__				)
										model.to(snake_case__				)
										model.train()

										lowerCAmelCase   =     self._prepare_for_class(snake_case__     ,	snake_case__     ,	return_labels=snake_case__				)

										if problem_type["num_labels"] > 1:
											lowerCAmelCase   =     inputs['labels'].unsqueeze(1				).repeat(1     ,	problem_type["""num_labels"""]				)

										lowerCAmelCase   =     inputs['labels'].to(problem_type["""dtype"""]				)

										# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
										# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
										# they have the same size." which is a symptom something in wrong for the regression problem.
										# See https://github.com/huggingface/transformers/issues/11780
										with warnings.catch_warnings(record=snake_case__				) as warning_list:
											lowerCAmelCase   =     model(**snake_case__				).loss
										for w in warning_list:
											if "Using a target size that is different to the input size" in str(w.message				):
												raise ValueError(
												    f'Something is going wrong in the regression problem: intercepted {w.message}'				)

										loss.backward()




						@slow
						def     __snake_case   ( self				)     ->     Tuple:

							for model_name in DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								lowerCAmelCase   =     DeiTModel.from_pretrained(snake_case__				)
								self.assertIsNotNone(snake_case__				)







def 		_snake_case		( )      ->						str:







	"""simple docstring"""
	lowerCAmelCase   =     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
	return image





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


						'''simple docstring'''



						@cached_property
						def     __snake_case   ( self				)     ->     Dict:
							return (
							    DeiTImageProcessor.from_pretrained("""facebook/deit-base-distilled-patch16-224"""				)
							    if is_vision_available()
							    else None
							)


						@slow
						def     __snake_case   ( self				)     ->     str:
							lowerCAmelCase   =     DeiTForImageClassificationWithTeacher.from_pretrained("""facebook/deit-base-distilled-patch16-224"""				).to(
							    snake_case__				)

							lowerCAmelCase   =     self.default_image_processor
							lowerCAmelCase   =     prepare_img()
							lowerCAmelCase   =     image_processor(images=snake_case__     ,	return_tensors="""pt"""				).to(snake_case__				)

							# forward pass
							with torch.no_grad():
								lowerCAmelCase   =     model(**snake_case__				)

							# verify the logits
							lowerCAmelCase   =     torch.Size((1, 1000)				)
							self.assertEqual(outputs.logits.shape     ,	snake_case__				)

							lowerCAmelCase   =     torch.tensor([-1.0_2_6_6, 0.1_9_1_2, -1.2_8_6_1]				).to(snake_case__				)

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




						@slow
						@require_accelerate
						@require_torch_gpu
						def     __snake_case   ( self				)     ->     Any:
							lowerCAmelCase   =     DeiTModel.from_pretrained(
							    """facebook/deit-base-distilled-patch16-224"""     ,	torch_dtype=torch.floataa     ,	device_map="""auto"""				)
							lowerCAmelCase   =     self.default_image_processor

							lowerCAmelCase   =     prepare_img()
							lowerCAmelCase   =     image_processor(images=snake_case__     ,	return_tensors="""pt"""				)
							lowerCAmelCase   =     inputs.pixel_values.to(snake_case__				)

							# forward pass to make sure inference works in fp16
							with torch.no_grad():
								lowerCAmelCase   =     model(snake_case__				)




'''simple docstring'''

import unittest

from transformers import LiltConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    LiltForQuestionAnswering,
				    LiltForSequenceClassification,
				    LiltForTokenClassification,
				    LiltModel,
				)
				from transformers.models.lilt.modeling_lilt import LILT_PRETRAINED_MODEL_ARCHIVE_LIST

class __snake_case:


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_=13     ,	A_=7     ,	A_=True     ,	A_=True     ,	A_=True     ,	A_=True     ,	A_=99     ,	A_=24     ,	A_=2     ,	A_=6     ,	A_=37     ,	A_="gelu"     ,	A_=0.1     ,	A_=0.1     ,	A_=512     ,	A_=16     ,	A_=2     ,	A_=0.0_2     ,	A_=3     ,	A_=None     ,	A_=1000     ,	)     ->     Union[str, Any]:
							lowerCAmelCase   =     parent
							lowerCAmelCase   =     batch_size
							lowerCAmelCase   =     seq_length
							lowerCAmelCase   =     is_training
							lowerCAmelCase   =     use_input_mask
							lowerCAmelCase   =     use_token_type_ids
							lowerCAmelCase   =     use_labels
							lowerCAmelCase   =     vocab_size
							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   =     max_position_embeddings
							lowerCAmelCase   =     type_vocab_size
							lowerCAmelCase   =     type_sequence_label_size
							lowerCAmelCase   =     initializer_range
							lowerCAmelCase   =     num_labels
							lowerCAmelCase   =     scope
							lowerCAmelCase   =     range_bbox


						def     __snake_case   ( self				)     ->     List[Any]:
							lowerCAmelCase   =     ids_tensor([self.batch_size, self.seq_length]     ,	self.vocab_size				)

							lowerCAmelCase   =     ids_tensor([self.batch_size, self.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]:
										lowerCAmelCase   =     bbox[i, j, 3]
										lowerCAmelCase   =     bbox[i, j, 1]
										lowerCAmelCase   =     t
									if bbox[i, j, 2] < bbox[i, j, 0]:
										lowerCAmelCase   =     bbox[i, j, 2]
										lowerCAmelCase   =     bbox[i, j, 0]
										lowerCAmelCase   =     t

							lowerCAmelCase   =     None
							if self.use_input_mask:
								lowerCAmelCase   =     ids_tensor([self.batch_size, self.seq_length]     ,	vocab_size=2				)

							lowerCAmelCase   =     None
							if self.use_token_type_ids:
								lowerCAmelCase   =     ids_tensor([self.batch_size, self.seq_length]     ,	self.type_vocab_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.seq_length]     ,	self.num_labels				)

							lowerCAmelCase   =     self.get_config()

							return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels


						def     __snake_case   ( self				)     ->     int:
							return LiltConfig(
							    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     ,	)


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	)     ->     int:
							lowerCAmelCase   =     LiltModel(config=A_				)
							model.to(A_				)
							model.eval()
							lowerCAmelCase   =     model(A_     ,	bbox=A_     ,	attention_mask=A_     ,	token_type_ids=A_				)
							lowerCAmelCase   =     model(A_     ,	bbox=A_     ,	token_type_ids=A_				)
							lowerCAmelCase   =     model(A_     ,	bbox=A_				)

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


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	)     ->     Union[str, Any]:
							lowerCAmelCase   =     self.num_labels
							lowerCAmelCase   =     LiltForTokenClassification(config=A_				)
							model.to(A_				)
							model.eval()
							lowerCAmelCase   =     model(
							    A_     ,	bbox=A_     ,	attention_mask=A_     ,	token_type_ids=A_     ,	labels=A_				)
							self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.seq_length, self.num_labels)				)


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_     ,	)     ->     Optional[Any]:
							lowerCAmelCase   =     LiltForQuestionAnswering(config=A_				)
							model.to(A_				)
							model.eval()
							lowerCAmelCase   =     model(
							    A_     ,	bbox=A_     ,	attention_mask=A_     ,	token_type_ids=A_     ,	start_positions=A_     ,	end_positions=A_     ,	)
							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     __snake_case   ( self				)     ->     Optional[int]:
							lowerCAmelCase   =     self.prepare_config_and_inputs()
							(
							    (
							    lowerCAmelCase
							),       (
							    lowerCAmelCase
							),       (
							    lowerCAmelCase
							),       (
							    lowerCAmelCase
							),       (
							    lowerCAmelCase
							),       (
							    lowerCAmelCase
							),       (
							    lowerCAmelCase
							),       
							)   =     config_and_inputs
							lowerCAmelCase   =     {
							    """input_ids""": input_ids,
							    """bbox""": bbox,
							    """token_type_ids""": token_type_ids,
							    """attention_mask""": input_mask,
							}
							return config, inputs_dict







@require_torch
class __snake_case(				_lowerCAmelCase		,							_lowerCAmelCase		,							_lowerCAmelCase		,							unittest.TestCase ):


						'''simple docstring'''



						UpperCAmelCase							:   int									=		(
						    (
						        LiltModel,
						        LiltForSequenceClassification,
						        LiltForTokenClassification,
						        LiltForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCAmelCase							:   Union[str, Any]									=		(
						    {
						        "feature-extraction": LiltModel,
						        "question-answering": LiltForQuestionAnswering,
						        "text-classification": LiltForSequenceClassification,
						        "token-classification": LiltForTokenClassification,
						        "zero-shot": LiltForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						UpperCAmelCase							:   Optional[int]									=		False
						UpperCAmelCase							:   Dict									=		False


						def     __snake_case   ( self     ,	A_     ,	A_     ,	A_     ,	A_     ,	A_				)     ->     Union[str, Any]:
							return True


						def     __snake_case   ( self				)     ->     int:
							lowerCAmelCase   =     LiltModelTester(self				)
							lowerCAmelCase   =     ConfigTester(self     ,	config_class=A_     ,	hidden_size=37				)


						def     __snake_case   ( self				)     ->     Any:
							self.config_tester.run_common_tests()


						def     __snake_case   ( self				)     ->     str:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*A_				)


						def     __snake_case   ( self				)     ->     int:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
								lowerCAmelCase   =     type
								self.model_tester.create_and_check_model(*A_				)


						def     __snake_case   ( self				)     ->     List[Any]:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*A_				)


						def     __snake_case   ( self				)     ->     str:
							lowerCAmelCase   =     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*A_				)




						@slow
						def     __snake_case   ( self				)     ->     Union[str, Any]:
							for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								lowerCAmelCase   =     LiltModel.from_pretrained(A_				)
								self.assertIsNotNone(A_				)







@require_torch
@slow
class __snake_case(				unittest.TestCase ):


						'''simple docstring'''



						def     __snake_case   ( self				)     ->     Tuple:
							lowerCAmelCase   =     LiltModel.from_pretrained("""SCUT-DLVCLab/lilt-roberta-en-base"""				).to(A_				)

							lowerCAmelCase   =     torch.tensor([[1, 2]]     ,	device=A_				)
							lowerCAmelCase   =     torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]     ,	device=A_				)

							# forward pass
							with torch.no_grad():
								lowerCAmelCase   =     model(input_ids=A_     ,	bbox=A_				)

							lowerCAmelCase   =     torch.Size([1, 2, 768]				)
							lowerCAmelCase   =     torch.tensor(
							    [[-0.0_6_5_3, 0.0_9_5_0, -0.0_0_6_1], [-0.0_5_4_5, 0.0_9_2_6, -0.0_3_2_4]]     ,	device=A_     ,	)

							self.assertTrue(outputs.last_hidden_state.shape     ,	A_				)
							self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :, :3]     ,	A_     ,	atol=1e-3				)				)