'''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 				a__:


			'''simple docstring'''






			def __init__(   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase=13       ,    __lowerCAmelCase=7       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=99       ,    __lowerCAmelCase=24       ,    __lowerCAmelCase=2       ,    __lowerCAmelCase=6       ,    __lowerCAmelCase=37       ,    __lowerCAmelCase="gelu"       ,    __lowerCAmelCase=0.1       ,    __lowerCAmelCase=0.1       ,    __lowerCAmelCase=512       ,    __lowerCAmelCase=16       ,    __lowerCAmelCase=2       ,    __lowerCAmelCase=0.02       ,    __lowerCAmelCase=3       ,    __lowerCAmelCase=None       ,    __lowerCAmelCase=1000       ,    ):




					"""simple docstring"""


					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 							a_       (   self):




					"""simple docstring"""


					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 							a_       (   self):




					"""simple docstring"""


					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 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  LiltModel(config=__lowerCAmelCase)
					model.to(__lowerCAmelCase)
					model.eval()
					lowerCAmelCase   					=  model(__lowerCAmelCase       ,    bbox=__lowerCAmelCase       ,    attention_mask=__lowerCAmelCase       ,    token_type_ids=__lowerCAmelCase)
					lowerCAmelCase   					=  model(__lowerCAmelCase       ,    bbox=__lowerCAmelCase       ,    token_type_ids=__lowerCAmelCase)
					lowerCAmelCase   					=  model(__lowerCAmelCase       ,    bbox=__lowerCAmelCase)

					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 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  self.num_labels
					lowerCAmelCase   					=  LiltForTokenClassification(config=__lowerCAmelCase)
					model.to(__lowerCAmelCase)
					model.eval()
					lowerCAmelCase   					=  model(
					    __lowerCAmelCase       ,    bbox=__lowerCAmelCase       ,    attention_mask=__lowerCAmelCase       ,    token_type_ids=__lowerCAmelCase       ,    labels=__lowerCAmelCase)
					self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.seq_length, self.num_labels))



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    ):




					"""simple docstring"""


					lowerCAmelCase   					=  LiltForQuestionAnswering(config=__lowerCAmelCase)
					model.to(__lowerCAmelCase)
					model.eval()
					lowerCAmelCase   					=  model(
					    __lowerCAmelCase       ,    bbox=__lowerCAmelCase       ,    attention_mask=__lowerCAmelCase       ,    token_type_ids=__lowerCAmelCase       ,    start_positions=__lowerCAmelCase       ,    end_positions=__lowerCAmelCase       ,    )
					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 							a_       (   self):




					"""simple docstring"""


					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 				a__(					lowerCAmelCase__ ,						lowerCAmelCase__ ,						lowerCAmelCase__ ,						unittest.TestCase	):


			'''simple docstring'''






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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase       ,    __lowerCAmelCase):




					"""simple docstring"""


					return True



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  LiltModelTester(self)
					lowerCAmelCase   					=  ConfigTester(self       ,    config_class=__lowerCAmelCase       ,    hidden_size=37)



			def 							a_       (   self):




					"""simple docstring"""


					self.config_tester.run_common_tests()



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					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(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase)







			@slow
			def 							a_       (   self):




					"""simple docstring"""


					for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							lowerCAmelCase   					=  LiltModel.from_pretrained(__lowerCAmelCase)
							self.assertIsNotNone(__lowerCAmelCase)







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


			'''simple docstring'''






			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  LiltModel.from_pretrained("""SCUT-DLVCLab/lilt-roberta-en-base""").to(__lowerCAmelCase)

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

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

					lowerCAmelCase   					=  torch.Size([1, 2, 768])
					lowerCAmelCase   					=  torch.tensor(
					    [[-0.0653, 0.0950, -0.0061], [-0.0545, 0.0926, -0.0324]]       ,    device=__lowerCAmelCase       ,    )

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





'''simple docstring'''




from math import sqrt






def 				snake_case__							(			_A:					int = 1000000 )    ->	int:

		'''simple docstring'''


		lowerCAmelCase   					=  0
		lowerCAmelCase   					=  0
		lowerCAmelCase   					=  42

		while num_cuboids <= limit:
				max_cuboid_size += 1
				for sum_shortest_sides in range(2      ,   2 * max_cuboid_size + 1 ):
						if sqrt(sum_shortest_sides**2 + max_cuboid_size**2 ).is_integer():
								num_cuboids += (
								    min(_A      ,   sum_shortest_sides // 2 )
								    - max(1      ,   sum_shortest_sides - max_cuboid_size )
								    + 1
								)

		return max_cuboid_size


if __name__ == "__main__":
						print(f'{solution() = }')




