import inspect
import unittest

from transformers import DPTConfig
from transformers.file_utils import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

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, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTModel
     from transformers.models.dpt.modeling_dpt import DPT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
     from PIL import Image

     from transformers import DPTImageProcessor



class       _snake_case   :


 def __init__(					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_=2					,  SCREAMING_SNAKE_CASE_=32					,  SCREAMING_SNAKE_CASE_=16					,  SCREAMING_SNAKE_CASE_=3					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=32					,  SCREAMING_SNAKE_CASE_=4					,  SCREAMING_SNAKE_CASE_=[0, 1, 2, 3]					,  SCREAMING_SNAKE_CASE_=4					,  SCREAMING_SNAKE_CASE_=37					,  SCREAMING_SNAKE_CASE_="gelu"					,  SCREAMING_SNAKE_CASE_=0.1					,  SCREAMING_SNAKE_CASE_=0.1					,  SCREAMING_SNAKE_CASE_=0.0_2					,  SCREAMING_SNAKE_CASE_=3					,  SCREAMING_SNAKE_CASE_=[1, 3_84, 24, 24]					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=None					,  ):


   '''simple docstring'''




   lowercase__  :   Tuple    		=      parent
   lowercase__  :   Dict    		=      batch_size
   lowercase__  :   Union[str, Any]    		=      image_size
   lowercase__  :   Tuple    		=      patch_size
   lowercase__  :   Any    		=      num_channels
   lowercase__  :   List[str]    		=      is_training
   lowercase__  :   str    		=      use_labels
   lowercase__  :   str    		=      hidden_size
   lowercase__  :   Any    		=      num_hidden_layers
   lowercase__  :   Union[str, Any]    		=      backbone_out_indices
   lowercase__  :   List[str]    		=      num_attention_heads
   lowercase__  :   Any    		=      intermediate_size
   lowercase__  :   int    		=      hidden_act
   lowercase__  :   str    		=      hidden_dropout_prob
   lowercase__  :   List[str]    		=      attention_probs_dropout_prob
   lowercase__  :   int    		=      initializer_range
   lowercase__  :   str    		=      num_labels
   lowercase__  :   str    		=      backbone_featmap_shape
   lowercase__  :   List[str]    		=      scope
   lowercase__  :   Optional[int]    		=      is_hybrid
   # sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
   lowercase__  :   Union[str, Any]    		=      (image_size // patch_size) ** 2
   lowercase__  :   Optional[int]    		=      num_patches + 1


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   List[str]    		=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

   lowercase__  :   List[Any]    		=      None
   if self.use_labels:
     lowercase__  :   int    		=      ids_tensor([self.batch_size, self.image_size, self.image_size]					,  self.num_labels)

   lowercase__  :   List[str]    		=      self.get_config()

   return config, pixel_values, labels


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Any    		=      {
       """global_padding""": """same""",
       """layer_type""": """bottleneck""",
       """depths""": [3, 4, 9],
       """out_features""": ["""stage1""", """stage2""", """stage3"""],
       """embedding_dynamic_padding""": True,
       """hidden_sizes""": [96, 1_92, 3_84, 7_68],
       """num_groups""": 2,
   }

   return DPTConfig(
       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					,  backbone_out_indices=self.backbone_out_indices					,  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=SCREAMING_SNAKE_CASE_					,  initializer_range=self.initializer_range					,  is_hybrid=self.is_hybrid					,  backbone_config=SCREAMING_SNAKE_CASE_					,  backbone_featmap_shape=self.backbone_featmap_shape					,  )


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__  :   Any    		=      DPTModel(config=SCREAMING_SNAKE_CASE_)
   model.to(SCREAMING_SNAKE_CASE_)
   model.eval()
   lowercase__  :   Union[str, Any]    		=      model(SCREAMING_SNAKE_CASE_)
   self.parent.assertEqual(result.last_hidden_state.shape					,  (self.batch_size, self.seq_length, self.hidden_size))


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__  :   List[Any]    		=      self.num_labels
   lowercase__  :   List[str]    		=      DPTForDepthEstimation(SCREAMING_SNAKE_CASE_)
   model.to(SCREAMING_SNAKE_CASE_)
   model.eval()
   lowercase__  :   Any    		=      model(SCREAMING_SNAKE_CASE_)
   self.parent.assertEqual(result.predicted_depth.shape					,  (self.batch_size, self.image_size, self.image_size))


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__  :   List[str]    		=      self.num_labels
   lowercase__  :   List[str]    		=      DPTForSemanticSegmentation(SCREAMING_SNAKE_CASE_)
   model.to(SCREAMING_SNAKE_CASE_)
   model.eval()
   lowercase__  :   Dict    		=      model(SCREAMING_SNAKE_CASE_					,  labels=SCREAMING_SNAKE_CASE_)
   self.parent.assertEqual(
       result.logits.shape					,  (self.batch_size, self.num_labels, self.image_size, self.image_size))



 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Tuple    		=      self.prepare_config_and_inputs()
   lowercase__  :   Optional[int]    		=      config_and_inputs
   lowercase__  :   List[Any]    		=      {"""pixel_values""": pixel_values}
   return config, inputs_dict



@require_torch
class       _snake_case   (	UpperCAmelCase_  ,						UpperCAmelCase_  ,						unittest.TestCase							):
 __lowerCAmelCase  :     Optional[Any]        =			(DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
 __lowerCAmelCase  :     List[Any]        =			(
     {
         'depth-estimation': DPTForDepthEstimation,
         'feature-extraction': DPTModel,
         'image-segmentation': DPTForSemanticSegmentation,
     }
     if is_torch_available()
     else {}
 )

 __lowerCAmelCase  :     Tuple        =			False
 __lowerCAmelCase  :     Any        =			False
 __lowerCAmelCase  :     int        =			False


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   List[Any]    		=      DPTModelTester(self)
   lowercase__  :   List[str]    		=      ConfigTester(self					,  config_class=SCREAMING_SNAKE_CASE_					,  has_text_modality=SCREAMING_SNAKE_CASE_					,  hidden_size=37)


 def      lowercase__     (					self):


   '''simple docstring'''




   self.config_tester.run_common_tests()


 @unittest.skip(reason="""DPT does not use inputs_embeds""")
 def      lowercase__     (					self):


   '''simple docstring'''




   pass


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   List[str]    		=      self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowercase__  :   Optional[Any]    		=      model_class(SCREAMING_SNAKE_CASE_)
     self.assertIsInstance(model.get_input_embeddings()					,  (nn.Module))
     lowercase__  :   str    		=      model.get_output_embeddings()
     self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_					,  nn.Linear))


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Optional[int]    		=      self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowercase__  :   List[Any]    		=      model_class(SCREAMING_SNAKE_CASE_)
     lowercase__  :   Optional[Any]    		=      inspect.signature(model.forward)
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     lowercase__  :   int    		=      [*signature.parameters.keys()]

     lowercase__  :   List[str]    		=      ["""pixel_values"""]
     self.assertListEqual(arg_names[:1]					,  SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Dict    		=      self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Union[str, Any]    		=      self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_depth_estimation(*SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   int    		=      self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_semantic_segmentation(*SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self):


   '''simple docstring'''




   for model_class in self.all_model_classes:
     if model_class.__name__ == "DPTForDepthEstimation":
       continue

     lowercase__  :   int    		=      self.model_tester.prepare_config_and_inputs_for_common()
     lowercase__  :   Dict    		=      True

     if model_class in get_values(SCREAMING_SNAKE_CASE_):
       continue

     lowercase__  :   Optional[Any]    		=      model_class(SCREAMING_SNAKE_CASE_)
     model.to(SCREAMING_SNAKE_CASE_)
     model.train()
     lowercase__  :   Union[str, Any]    		=      self._prepare_for_class(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  return_labels=SCREAMING_SNAKE_CASE_)
     lowercase__  :   Tuple    		=      model(**SCREAMING_SNAKE_CASE_).loss
     loss.backward()


 def      lowercase__     (					self):


   '''simple docstring'''




   for model_class in self.all_model_classes:
     if model_class.__name__ == "DPTForDepthEstimation":
       continue

     lowercase__  :   Tuple    		=      self.model_tester.prepare_config_and_inputs_for_common()
     lowercase__  :   Optional[int]    		=      False
     lowercase__  :   List[Any]    		=      True

     if model_class in get_values(SCREAMING_SNAKE_CASE_) or not model_class.supports_gradient_checkpointing:
       continue
     lowercase__  :   Any    		=      model_class(SCREAMING_SNAKE_CASE_)
     model.to(SCREAMING_SNAKE_CASE_)
     model.gradient_checkpointing_enable()
     model.train()
     lowercase__  :   Union[str, Any]    		=      self._prepare_for_class(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  return_labels=SCREAMING_SNAKE_CASE_)
     lowercase__  :   Tuple    		=      model(**SCREAMING_SNAKE_CASE_).loss
     loss.backward()


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Any    		=      self.model_tester.prepare_config_and_inputs_for_common()

   lowercase__  :   Dict    		=      _config_zero_init(SCREAMING_SNAKE_CASE_)
   for model_class in self.all_model_classes:
     lowercase__  :   Tuple    		=      model_class(config=SCREAMING_SNAKE_CASE_)
     # Skip the check for the backbone
     lowercase__  :   List[Any]    		=      []
     for name, module in model.named_modules():
       if module.__class__.__name__ == "DPTViTHybridEmbeddings":
         lowercase__  :   Dict    		=      [f'{name}.{key}' for key in module.state_dict().keys()]
         break

     for name, param in model.named_parameters():
       if param.requires_grad:
         if name in backbone_params:
           continue
         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'					,  )


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


   '''simple docstring'''




   pass


 @slow
 def      lowercase__     (					self):


   '''simple docstring'''




   for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[1:]:
     lowercase__  :   Any    		=      DPTModel.from_pretrained(SCREAMING_SNAKE_CASE_)
     self.assertIsNotNone(SCREAMING_SNAKE_CASE_)



 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   Tuple    		=      self.model_tester.prepare_config_and_inputs_for_common()
   lowercase__  :   int    		=      """add"""
   with self.assertRaises(SCREAMING_SNAKE_CASE_):
     lowercase__  :   Any    		=      DPTForDepthEstimation(SCREAMING_SNAKE_CASE_)

def 		UpperCamelCase	(      )		->	Optional[Any]:


  '''simple docstring'''






  lowercase__  :   int    		=      Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""   )
  return image



@require_torch
@require_vision
@slow
class       _snake_case   (	unittest.TestCase							):


 def      lowercase__     (					self):


   '''simple docstring'''




   lowercase__  :   List[Any]    		=      DPTImageProcessor.from_pretrained("""Intel/dpt-hybrid-midas""")
   lowercase__  :   Union[str, Any]    		=      DPTForDepthEstimation.from_pretrained("""Intel/dpt-hybrid-midas""").to(SCREAMING_SNAKE_CASE_)

   lowercase__  :   Any    		=      prepare_img()
   lowercase__  :   List[Any]    		=      image_processor(images=SCREAMING_SNAKE_CASE_					,  return_tensors="""pt""").to(SCREAMING_SNAKE_CASE_)

   # forward pass
   with torch.no_grad():
     lowercase__  :   Optional[int]    		=      model(**SCREAMING_SNAKE_CASE_)
     lowercase__  :   Tuple    		=      outputs.predicted_depth

   # verify the predicted depth
   lowercase__  :   Optional[Any]    		=      torch.Size((1, 3_84, 3_84))
   self.assertEqual(predicted_depth.shape					,  SCREAMING_SNAKE_CASE_)

   lowercase__  :   Optional[int]    		=      torch.tensor(
       [[[5.6_4_3_7, 5.6_1_4_6, 5.6_5_1_1], [5.4_3_7_1, 5.5_6_4_9, 5.5_9_5_8], [5.5_2_1_5, 5.5_1_8_4, 5.5_2_9_3]]]).to(SCREAMING_SNAKE_CASE_)

   self.assertTrue(torch.allclose(outputs.predicted_depth[:3, :3, :3] / 1_00					,  SCREAMING_SNAKE_CASE_					,  atol=1E-4))








import sys

lowerCamelCase__    :		List[Any]          =   (
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)

def 		UpperCamelCase	(      lowercase_ = N   )		->	int:


  '''simple docstring'''






  lowercase__  :   int    		=      -sys.maxsize - 1
  for i in range(len(lowercase_   ) - 12   ):
    lowercase__  :   Optional[int]    		=      1
    for j in range(13   ):
      product *= int(n[i + j]   )
    if product > largest_product:
      lowercase__  :   int    		=      product
  return largest_product


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






