code: 
  
  
  
  """simple docstring"""
  
  
  
  
  import inspect
  import unittest
  
  import requests
  
  from transformers import MgpstrConfig
  from transformers.testing_utils import require_torch, require_vision, slow, torch_device
  from transformers.utils import is_torch_available, is_vision_available
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
    import torch
    from torch import nn
  
    from transformers import MgpstrForSceneTextRecognition
  
  
  if is_vision_available():
    from PIL import Image
  
    from transformers import MgpstrProcessor
  class 							lowerCamelCase		:
  
  
  
  
  
  
  
     def __init__(							self    ,      SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_=False    ,      SCREAMING_SNAKE_CASE_=13    ,      SCREAMING_SNAKE_CASE_=(32, 128)    ,      SCREAMING_SNAKE_CASE_=4    ,      SCREAMING_SNAKE_CASE_=3    ,      SCREAMING_SNAKE_CASE_=27    ,      SCREAMING_SNAKE_CASE_=38    ,      SCREAMING_SNAKE_CASE_=99    ,      SCREAMING_SNAKE_CASE_=99    ,      SCREAMING_SNAKE_CASE_=32    ,      SCREAMING_SNAKE_CASE_=5    ,      SCREAMING_SNAKE_CASE_=4    ,      SCREAMING_SNAKE_CASE_=4.0    ,      SCREAMING_SNAKE_CASE_=257    ,      SCREAMING_SNAKE_CASE_=None    ,      ):
         UpperCamelCase				:   List[Any]          =							parent
         UpperCamelCase				:   int          =							is_training
         UpperCamelCase				:   Any          =							batch_size
         UpperCamelCase				:   Union[str, Any]          =							image_size
         UpperCamelCase				:   List[Any]          =							patch_size
         UpperCamelCase				:   str          =							num_channels
         UpperCamelCase				:   str          =							max_token_length
         UpperCamelCase				:   Tuple          =							num_character_labels
         UpperCamelCase				:   Tuple          =							num_bpe_labels
         UpperCamelCase				:   Union[str, Any]          =							num_wordpiece_labels
         UpperCamelCase				:   str          =							hidden_size
         UpperCamelCase				:   Optional[Any]          =							num_hidden_layers
         UpperCamelCase				:   str          =							num_attention_heads
         UpperCamelCase				:   Optional[Any]          =							mlp_ratio
         UpperCamelCase				:   Dict          =							patch_embeds_hidden_size
         UpperCamelCase				:   Optional[int]          =							output_hidden_states
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   Union[str, Any]          =							floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]] )
         UpperCamelCase				:   Any          =							self.get_config()
         return config, pixel_values
  
  
  
  
  
  
  
     def       a_							(							self ):
         return MgpstrConfig(
             image_size=self.image_size    ,      patch_size=self.patch_size    ,      num_channels=self.num_channels    ,      max_token_length=self.max_token_length    ,      num_character_labels=self.num_character_labels    ,      num_bpe_labels=self.num_bpe_labels    ,      num_wordpiece_labels=self.num_wordpiece_labels    ,      hidden_size=self.hidden_size    ,      num_hidden_layers=self.num_hidden_layers    ,      num_attention_heads=self.num_attention_heads    ,      mlp_ratio=self.mlp_ratio    ,      output_hidden_states=self.output_hidden_states    ,      )
  
  
  
  
  
  
  
     def       a_							(							self    ,      SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_ ):
         UpperCamelCase				:   Dict          =							MgpstrForSceneTextRecognition(SCREAMING_SNAKE_CASE_ )
         model.to(SCREAMING_SNAKE_CASE_ )
         model.eval()
         with torch.no_grad():
             UpperCamelCase				:   int          =							model(SCREAMING_SNAKE_CASE_ )
         self.parent.assertEqual(
             generated_ids[0][0].shape    ,      (self.batch_size, self.max_token_length, self.num_character_labels) )
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   Optional[Any]          =							self.prepare_config_and_inputs()
         UpperCamelCase				:   str          =							config_and_inputs
         UpperCamelCase				:   str          =							{"""pixel_values""": pixel_values}
         return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class 							lowerCamelCase		( _UpperCAmelCase	,  _UpperCAmelCase	,  unittest.TestCase				):
     lowercase       :  Union[str, Any]      =				(MgpstrForSceneTextRecognition,) if is_torch_available() else ()
     lowercase       :  Optional[Any]      =				{'feature-extraction': MgpstrForSceneTextRecognition} if is_torch_available() else {}
     lowercase       :  List[Any]      =				False
  
     lowercase       :  List[str]      =				False
     lowercase       :  Optional[Any]      =				False
     lowercase       :  List[Any]      =				False
     lowercase       :  Union[str, Any]      =				False
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   int          =							MgpstrModelTester(self )
         UpperCamelCase				:   Any          =							ConfigTester(self    ,      config_class=SCREAMING_SNAKE_CASE_    ,      has_text_modality=SCREAMING_SNAKE_CASE_ )
  
  
  
  
  
  
  
     def       a_							(							self ):
         self.config_tester.run_common_tests()
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   List[str]          =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_ )
  
  
  
  
  
  
  
     @unittest.skip(reason="""MgpstrModel does not use inputs_embeds""" )
     def       a_							(							self ):
         pass
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   Union[str, Any]          =							self.model_tester.prepare_config_and_inputs_for_common()
  
         for model_class in self.all_model_classes:
             UpperCamelCase				:   str          =							model_class(SCREAMING_SNAKE_CASE_ )
             self.assertIsInstance(model.get_input_embeddings()    ,      (nn.Module) )
             UpperCamelCase				:   List[Any]          =							model.get_output_embeddings()
             self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_    ,      nn.Linear ) )
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   Optional[Any]          =							self.model_tester.prepare_config_and_inputs_for_common()
  
         for model_class in self.all_model_classes:
             UpperCamelCase				:   int          =							model_class(SCREAMING_SNAKE_CASE_ )
             UpperCamelCase				:   Tuple          =							inspect.signature(model.forward )
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             UpperCamelCase				:   Any          =							[*signature.parameters.keys()]
  
             UpperCamelCase				:   int          =							["""pixel_values"""]
             self.assertListEqual(arg_names[:1]    ,      SCREAMING_SNAKE_CASE_ )
  
  
  
  
  
  
  
     @unittest.skip(reason="""MgpstrModel does not support feedforward chunking""" )
     def       a_							(							self ):
         pass
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   Optional[Any]          =							self.model_tester.prepare_config_and_inputs_for_common()
  
         for model_class in self.all_model_classes:
             if not model_class.supports_gradient_checkpointing:
                 continue
  
             UpperCamelCase				:   Optional[int]          =							True
             UpperCamelCase				:   Any          =							model_class(SCREAMING_SNAKE_CASE_ )
             self.assertTrue(model.is_gradient_checkpointing )
  
  
  
  
  
  
  
     def       a_							(							self ):
         def check_hidden_states_output(SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_ ):
             UpperCamelCase				:   Dict          =							model_class(SCREAMING_SNAKE_CASE_ )
             model.to(SCREAMING_SNAKE_CASE_ )
             model.eval()
  
             with torch.no_grad():
                 UpperCamelCase				:   Dict          =							model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_ ) )
  
             UpperCamelCase				:   str          =							outputs.hidden_states
  
             UpperCamelCase				:   Optional[int]          =							getattr(
                 self.model_tester    ,      """expected_num_hidden_layers"""    ,      self.model_tester.num_hidden_layers + 1 )
             self.assertEqual(len(SCREAMING_SNAKE_CASE_ )    ,      SCREAMING_SNAKE_CASE_ )
  
             self.assertListEqual(
                 list(hidden_states[0].shape[-2:] )    ,      [self.model_tester.patch_embeds_hidden_size, self.model_tester.hidden_size]    ,      )
  
         UpperCamelCase				:   List[str]          =							self.model_tester.prepare_config_and_inputs_for_common()
  
         for model_class in self.all_model_classes:
             UpperCamelCase				:   Dict          =							True
             check_hidden_states_output(SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_ )
  
             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             UpperCamelCase				:   Dict          =							True
  
             check_hidden_states_output(SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_ )
  
  
  
  
  
  
  
     def       a_							(							self ):
         UpperCamelCase				:   List[str]          =							self.model_tester.prepare_config_and_inputs_for_common()
  
         UpperCamelCase				:   List[Any]          =							_config_zero_init(SCREAMING_SNAKE_CASE_ )
         for model_class in self.all_model_classes:
             UpperCamelCase				:   Any          =							model_class(config=SCREAMING_SNAKE_CASE_ )
             for name, param in model.named_parameters():
                 if isinstance(SCREAMING_SNAKE_CASE_    ,      (nn.Linear, nn.Convad, nn.LayerNorm) ):
                     if param.requires_grad:
                         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(reason="""Retain_grad is tested in individual model tests""" )
     def       a_							(							self ):
         pass
  
  
  
  
  
  
  
  def 					A_			(		):
  
  
  
  
  
  
  
      '''simple docstring'''
      UpperCamelCase				:   Tuple          =							"""https://i.postimg.cc/ZKwLg2Gw/367-14.png"""
      UpperCamelCase				:   List[Any]          =							Image.open(requests.get(snake_case_						,stream=snake_case_    ).raw    ).convert("""RGB"""    )
      return im
  
  
  @require_vision
  @require_torch
  class 							lowerCamelCase		( unittest.TestCase				):
  
  
  
  
  
  
  
     @slow
     def       a_							(							self ):
         UpperCamelCase				:   Tuple          =							"""alibaba-damo/mgp-str-base"""
         UpperCamelCase				:   Optional[int]          =							MgpstrForSceneTextRecognition.from_pretrained(SCREAMING_SNAKE_CASE_ ).to(SCREAMING_SNAKE_CASE_ )
         UpperCamelCase				:   Optional[int]          =							MgpstrProcessor.from_pretrained(SCREAMING_SNAKE_CASE_ )
  
         UpperCamelCase				:   Optional[int]          =							prepare_img()
         UpperCamelCase				:   int          =							processor(images=SCREAMING_SNAKE_CASE_    ,      return_tensors="""pt""" ).pixel_values.to(SCREAMING_SNAKE_CASE_ )
  
         # forward pass
         with torch.no_grad():
             UpperCamelCase				:   List[str]          =							model(SCREAMING_SNAKE_CASE_ )
  
         # verify the logits
         self.assertEqual(outputs.logits[0].shape    ,      torch.Size((1, 27, 38) ) )
  
         UpperCamelCase				:   int          =							processor.batch_decode(outputs.logits )
         UpperCamelCase				:   Union[str, Any]          =							"""ticket"""
  
         self.assertEqual(out_strs["""generated_text"""][0]    ,      SCREAMING_SNAKE_CASE_ )
  
         UpperCamelCase				:   Optional[int]          =							torch.tensor(
             [[[-39.5397, -44.4024, -36.1844], [-61.4709, -63.8639, -58.3454], [-74.0225, -68.5494, -71.2164]]]    ,      device=SCREAMING_SNAKE_CASE_    ,      )
  
         self.assertTrue(torch.allclose(outputs.logits[0][:, 1:4, 1:4]    ,      SCREAMING_SNAKE_CASE_    ,      atol=1e-4 ) )
  
  
  
  
  
style_context: 
  
  
  
  
  """simple docstring"""
  
  
  
  
  def 					A_			(		snake_case_     :       Tuple						,snake_case_     :       Optional[Any]						,snake_case_     :       Optional[Any]    ):
  
  
  
  
  
  
  
      '''simple docstring'''
      assert b != 0, "This cannot accept modulo that is == 0"
      if n == 0:
          return 1
  
      if n % 2 == 1:
          return (bin_exp_mod(snake_case_						,n - 1						,snake_case_    ) * a) % b
  
      UpperCamelCase				:   List[Any]          =							bin_exp_mod(snake_case_						,n / 2						,snake_case_    )
      return (r * r) % b
  
  
  if __name__ == "__main__":
    try:
      __A :		Any      							=    int(input('''Enter Base : ''').strip())
      __A :		Any      							=    int(input('''Enter Power : ''').strip())
      __A :		List[Any]      							=    int(input('''Enter Modulo : ''').strip())
    except ValueError:
      print('''Invalid literal for integer''')
  
    print(bin_exp_mod(BASE, POWER, MODULO))
  
  
  
  
  