


'''simple docstring'''
import unittest

from transformers import TrOCRConfig
from transformers.testing_utils import is_torch_available, require_torch, 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.models.trocr.modeling_trocr import TrOCRDecoder, TrOCRForCausalLM
@require_torch
class    lowercase	:

		"""simple docstring"""

		def __init__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_=99    ,   UpperCamelCase_=13    ,   UpperCamelCase_=16    ,   UpperCamelCase_=7    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_=False    ,   UpperCamelCase_=True    ,   UpperCamelCase_=2    ,   UpperCamelCase_=32    ,   UpperCamelCase_=4    ,   UpperCamelCase_=4    ,   UpperCamelCase_=30    ,   UpperCamelCase_=0    ,   UpperCamelCase_=1    ,   UpperCamelCase_=2    ,   UpperCamelCase_=None    ,   ):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= parent
							UpperCamelCase__   :Optional[int]												= batch_size
							UpperCamelCase__   :Any												= decoder_seq_length
							# For common tests
							UpperCamelCase__   :List[Any]												= self.decoder_seq_length
							UpperCamelCase__   :Union[str, Any]												= is_training
							UpperCamelCase__   :List[str]												= use_attention_mask
							UpperCamelCase__   :Tuple												= use_labels

							UpperCamelCase__   :Any												= vocab_size
							UpperCamelCase__   :Optional[Any]												= d_model
							UpperCamelCase__   :Any												= d_model
							UpperCamelCase__   :Tuple												= decoder_layers
							UpperCamelCase__   :List[Any]												= decoder_layers
							UpperCamelCase__   :Optional[Any]												= decoder_ffn_dim
							UpperCamelCase__   :int												= decoder_attention_heads
							UpperCamelCase__   :List[str]												= decoder_attention_heads
							UpperCamelCase__   :Optional[Any]												= eos_token_id
							UpperCamelCase__   :Any												= bos_token_id
							UpperCamelCase__   :Optional[Any]												= pad_token_id
							UpperCamelCase__   :List[str]												= decoder_start_token_id
							UpperCamelCase__   :Dict												= use_cache
							UpperCamelCase__   :List[str]												= max_position_embeddings

							UpperCamelCase__   :Tuple												= None
							UpperCamelCase__   :List[Any]												= decoder_seq_length
							UpperCamelCase__   :List[str]												= 2
							UpperCamelCase__   :List[str]												= 1




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= ids_tensor([self.batch_size, self.decoder_seq_length]    ,   self.vocab_size							)

							UpperCamelCase__   :Union[str, Any]												= None
							if self.use_attention_mask:
												UpperCamelCase__   :Dict												= ids_tensor([self.batch_size, self.decoder_seq_length]    ,   vocab_size=2							)

							UpperCamelCase__   :str												= None
							if self.use_labels:
												UpperCamelCase__   :Tuple												= ids_tensor([self.batch_size, self.decoder_seq_length]    ,   self.vocab_size							)

							UpperCamelCase__   :Tuple												= TrOCRConfig(
							    vocab_size=self.vocab_size    ,   d_model=self.d_model    ,   decoder_layers=self.decoder_layers    ,   decoder_ffn_dim=self.decoder_ffn_dim    ,   decoder_attention_heads=self.decoder_attention_heads    ,   eos_token_id=self.eos_token_id    ,   bos_token_id=self.bos_token_id    ,   use_cache=self.use_cache    ,   pad_token_id=self.pad_token_id    ,   decoder_start_token_id=self.decoder_start_token_id    ,   max_position_embeddings=self.max_position_embeddings    ,   )

							return (config, input_ids, attention_mask, lm_labels)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   ):

							'''simple docstring'''


							UpperCamelCase__   :int												= True
							UpperCamelCase__   :int												= TrOCRDecoder(config=UpperCamelCase_							).to(UpperCamelCase_							).eval()
							UpperCamelCase__   :Any												= input_ids[:2]

							input_ids[input_ids == 0] += 1
							# first forward pass
							UpperCamelCase__   :List[Any]												= model(UpperCamelCase_    ,   use_cache=UpperCamelCase_							)
							UpperCamelCase__   :List[Any]												= model(UpperCamelCase_							)
							UpperCamelCase__   :Union[str, Any]												= model(UpperCamelCase_    ,   use_cache=UpperCamelCase_							)

							self.parent.assertTrue(len(UpperCamelCase_							) == len(UpperCamelCase_							)							)
							self.parent.assertTrue(len(UpperCamelCase_							) == len(UpperCamelCase_							) + 1							)

							UpperCamelCase__   :Optional[int]												= outputs['''past_key_values''']

							# create hypothetical next token and extent to next_input_ids
							UpperCamelCase__   :Union[str, Any]												= ids_tensor((2, 1)    ,   config.vocab_size - 1							) + 1

							# append to next input_ids and
							UpperCamelCase__   :Optional[Any]												= torch.cat([input_ids, next_tokens]    ,   dim=-1							)

							UpperCamelCase__   :Dict												= model(UpperCamelCase_							)['''last_hidden_state''']
							UpperCamelCase__   :Dict												= model(UpperCamelCase_    ,   past_key_values=UpperCamelCase_							)['''last_hidden_state''']

							# select random slice
							UpperCamelCase__   :Union[str, Any]												= ids_tensor((1,)    ,   output_from_past.shape[-1]							).item()
							UpperCamelCase__   :Optional[Any]												= output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
							UpperCamelCase__   :Optional[Any]												= output_from_past[:, 0, random_slice_idx].detach()

							# test that outputs are equal for slice
							assert torch.allclose(UpperCamelCase_    ,   UpperCamelCase_    ,   atol=1e-3							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= self.prepare_config_and_inputs()
							UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__   :Union[str, Any]												= config_and_inputs

							UpperCamelCase__   :Optional[int]												= {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
							return config, inputs_dict



@require_torch
class    lowercase	(							A__	,		A__	,		A__	,		unittest.TestCase					):

		"""simple docstring"""

		_a     =				(TrOCRDecoder, TrOCRForCausalLM) if is_torch_available() else ()
		_a     =				(TrOCRForCausalLM,) if is_torch_available() else ()
		_a     =				{'text-generation': TrOCRForCausalLM} if is_torch_available() else {}
		_a     =				True
		_a     =				False




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= TrOCRStandaloneDecoderModelTester(self    ,   is_training=UpperCamelCase_							)
							UpperCamelCase__   :Dict												= ConfigTester(self    ,   config_class=UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_decoder_model_past(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							return




		@unittest.skip('''The model doesn\'t support left padding'''							)  # and it's not used enough to be worth fixing :)
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass


def 			UpperCAmelCase__				(			):





  '''simple docstring'''







  return [
      a * b * (10_00 - a - b)
      for a in range(1	,      9_99							)
      for b in range(_A	,      9_99							)
      if (a * a + b * b == (10_00 - a - b) ** 2)
  ][0]


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