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 							__snake_case    :
  
  
  
  
  
  	def __init__(		self			,					UpperCamelCase_			,					UpperCamelCase_=False			,					UpperCamelCase_=13			,					UpperCamelCase_=(32, 128)			,					UpperCamelCase_=4			,					UpperCamelCase_=3			,					UpperCamelCase_=27			,					UpperCamelCase_=38			,					UpperCamelCase_=99			,					UpperCamelCase_=99			,					UpperCamelCase_=32			,					UpperCamelCase_=5			,					UpperCamelCase_=4			,					UpperCamelCase_=4.0			,					UpperCamelCase_=257			,					UpperCamelCase_=None			,					)			->		Union[str, Any]:
  		snake_case__  					=      parent
  		snake_case__  					=      is_training
  		snake_case__  					=      batch_size
  		snake_case__  					=      image_size
  		snake_case__  					=      patch_size
  		snake_case__  					=      num_channels
  		snake_case__  					=      max_token_length
  		snake_case__  					=      num_character_labels
  		snake_case__  					=      num_bpe_labels
  		snake_case__  					=      num_wordpiece_labels
  		snake_case__  					=      hidden_size
  		snake_case__  					=      num_hidden_layers
  		snake_case__  					=      num_attention_heads
  		snake_case__  					=      mlp_ratio
  		snake_case__  					=      patch_embeds_hidden_size
  		snake_case__  					=      output_hidden_states
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Any:
  		snake_case__  					=      floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]]		)
  		snake_case__  					=      self.get_config()
  		return config, pixel_values
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Dict:
  		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      _snake_case      (		self			,					UpperCamelCase_			,					UpperCamelCase_		)			->		List[Any]:
  		snake_case__  					=      MgpstrForSceneTextRecognition(UpperCamelCase_		)
  		model.to(UpperCamelCase_		)
  		model.eval()
  		with torch.no_grad():
  			snake_case__  					=      model(UpperCamelCase_		)
  		self.parent.assertEqual(
  		    generated_ids[0][0].shape			,					(self.batch_size, self.max_token_length, self.num_character_labels)		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		int:
  		snake_case__  					=      self.prepare_config_and_inputs()
  		snake_case__					,     snake_case__  					=      config_and_inputs
  		snake_case__  					=      {'pixel_values': pixel_values}
  		return config, inputs_dict
  
  
  
  
  
  
  @require_torch
  class 							__snake_case    (				__magic_name__					,					__magic_name__					,					unittest.TestCase       ):
  	__lowerCAmelCase						=     (MgpstrForSceneTextRecognition,) if is_torch_available() else ()
  	__lowerCAmelCase						=     {'''feature-extraction''': MgpstrForSceneTextRecognition} if is_torch_available() else {}
  	__lowerCAmelCase						=     False
  
  	__lowerCAmelCase						=     False
  	__lowerCAmelCase						=     False
  	__lowerCAmelCase						=     False
  	__lowerCAmelCase						=     False
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Optional[Any]:
  		snake_case__  					=      MgpstrModelTester(self		)
  		snake_case__  					=      ConfigTester(self			,					config_class=UpperCamelCase_			,					has_text_modality=UpperCamelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Dict:
  		self.config_tester.run_common_tests()
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Optional[Any]:
  		snake_case__  					=      self.model_tester.prepare_config_and_inputs()
  		self.model_tester.create_and_check_model(*UpperCamelCase_		)
  
  
  
  
  
  	@unittest.skip(reason='MgpstrModel does not use inputs_embeds'		)
  	def      _snake_case      (		self		)			->		int:
  		pass
  
  
  
  
  
  	def      _snake_case      (		self		)			->		int:
  		snake_case__					,     snake_case__  					=      self.model_tester.prepare_config_and_inputs_for_common()
  
  		for model_class in self.all_model_classes:
  			snake_case__  					=      model_class(UpperCamelCase_		)
  			self.assertIsInstance(model.get_input_embeddings()			,					(nn.Module)		)
  			snake_case__  					=      model.get_output_embeddings()
  			self.assertTrue(x is None or isinstance(UpperCamelCase_			,					nn.Linear		)		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		int:
  		snake_case__					,     snake_case__  					=      self.model_tester.prepare_config_and_inputs_for_common()
  
  		for model_class in self.all_model_classes:
  			snake_case__  					=      model_class(UpperCamelCase_		)
  			snake_case__  					=      inspect.signature(model.forward		)
  			# signature.parameters is an OrderedDict => so arg_names order is deterministic
  			snake_case__  					=      [*signature.parameters.keys()]
  
  			snake_case__  					=      ['pixel_values']
  			self.assertListEqual(arg_names[:1]			,					UpperCamelCase_		)
  
  
  
  
  
  	@unittest.skip(reason='MgpstrModel does not support feedforward chunking'		)
  	def      _snake_case      (		self		)			->		Union[str, Any]:
  		pass
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Any:
  		snake_case__					,     snake_case__  					=      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
  
  			snake_case__  					=      True
  			snake_case__  					=      model_class(UpperCamelCase_		)
  			self.assertTrue(model.is_gradient_checkpointing		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Tuple:
  		def check_hidden_states_output(UpperCamelCase_			,					UpperCamelCase_			,					UpperCamelCase_		):
  			snake_case__  					=      model_class(UpperCamelCase_		)
  			model.to(UpperCamelCase_		)
  			model.eval()
  
  			with torch.no_grad():
  				snake_case__  					=      model(**self._prepare_for_class(UpperCamelCase_			,					UpperCamelCase_		)		)
  
  			snake_case__  					=      outputs.hidden_states
  
  			snake_case__  					=      getattr(
  			    self.model_tester			,					'expected_num_hidden_layers'			,					self.model_tester.num_hidden_layers + 1		)
  			self.assertEqual(len(UpperCamelCase_		)			,					UpperCamelCase_		)
  
  			self.assertListEqual(
  			    list(hidden_states[0].shape[-2:]		)			,					[self.model_tester.patch_embeds_hidden_size, self.model_tester.hidden_size]			,					)
  
  		snake_case__					,     snake_case__  					=      self.model_tester.prepare_config_and_inputs_for_common()
  
  		for model_class in self.all_model_classes:
  			snake_case__  					=      True
  			check_hidden_states_output(UpperCamelCase_			,					UpperCamelCase_			,					UpperCamelCase_		)
  
  			# check that output_hidden_states also work using config
  			del inputs_dict["output_hidden_states"]
  			snake_case__  					=      True
  
  			check_hidden_states_output(UpperCamelCase_			,					UpperCamelCase_			,					UpperCamelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Any:
  		snake_case__					,     snake_case__  					=      self.model_tester.prepare_config_and_inputs_for_common()
  
  		snake_case__  					=      _config_zero_init(UpperCamelCase_		)
  		for model_class in self.all_model_classes:
  			snake_case__  					=      model_class(config=UpperCamelCase_		)
  			for name, param in model.named_parameters():
  				if isinstance(UpperCamelCase_			,					(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      _snake_case      (		self		)			->		Tuple:
  		pass
  
  
  
  
  
  def 	__lowerCamelCase (  )      ->str:
  	snake_case__  					=      'https://i.postimg.cc/ZKwLg2Gw/367-14.png'
  	snake_case__  					=      Image.open(requests.get(UpperCAmelCase_				,							stream=UpperCAmelCase_       ).raw       ).convert('RGB'       )
  	return im
  
  
  
  
  
  
  
  @require_vision
  @require_torch
  class 							__snake_case    (				unittest.TestCase       ):
  
  
  
  
  
  	@slow
  	def      _snake_case      (		self		)			->		Optional[Any]:
  		snake_case__  					=      'alibaba-damo/mgp-str-base'
  		snake_case__  					=      MgpstrForSceneTextRecognition.from_pretrained(UpperCamelCase_		).to(UpperCamelCase_		)
  		snake_case__  					=      MgpstrProcessor.from_pretrained(UpperCamelCase_		)
  
  		snake_case__  					=      prepare_img()
  		snake_case__  					=      processor(images=UpperCamelCase_			,					return_tensors='pt'		).pixel_values.to(UpperCamelCase_		)
  
  		# forward pass
  		with torch.no_grad():
  			snake_case__  					=      model(UpperCamelCase_		)
  
  		# verify the logits
  		self.assertEqual(outputs.logits[0].shape			,					torch.Size((1, 27, 38)		)		)
  
  		snake_case__  					=      processor.batch_decode(outputs.logits		)
  		snake_case__  					=      'ticket'
  
  		self.assertEqual(out_strs['generated_text'][0]			,					UpperCamelCase_		)
  
  		snake_case__  					=      torch.tensor(
  		    [[[-39.5397, -44.4024, -36.1844], [-61.4709, -63.8639, -58.3454], [-74.0225, -68.5494, -71.2164]]]			,					device=UpperCamelCase_			,					)
  
  		self.assertTrue(torch.allclose(outputs.logits[0][:, 1:4, 1:4]			,					UpperCamelCase_			,					atol=1E-4		)		)
  
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  def 	__lowerCamelCase (  UpperCAmelCase_       )      ->str:
  	snake_case__  					=      len(UpperCAmelCase_       )
  	for i in range(length - 1       ):
  		snake_case__  					=      False
  		for j in range(length - 1 - i       ):
  			if collection[j] > collection[j + 1]:
  				snake_case__  					=      True
  				snake_case__					,     snake_case__  					=      collection[j + 1], collection[j]
  		if not swapped:
  			break  # Stop iteration if the collection is sorted.
  	return collection
  
  
  if __name__ == "__main__":
  			import doctest
  			import time
  
  			doctest.testmod()
  
  			a__				: Dict									=    input('''Enter numbers separated by a comma:''').strip()
  			a__				: Dict									=    [int(item) for item in user_input.split(''',''')]
  			a__				: Tuple									=    time.process_time()
  			print(*bubble_sort(unsorted), sep=''',''')
  			print(f"""Processing time: {(time.process_time() - start)%1e9 + 7}""")
  
  
  
  