code: 
  
  import inspect
  import unittest
  
  from transformers import SwinaSRConfig
  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, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
  					import torch
  					from torch import nn
  
  					from transformers import SwinaSRForImageSuperResolution, SwinaSRModel
  					from transformers.models.swinasr.modeling_swinasr import SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST
  
  if is_vision_available():
  					from PIL import Image
  
  					from transformers import SwinaSRImageProcessor
  
  class __UpperCamelCase    :
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def __init__(							self							,			lowerCamelCase__							,			lowerCamelCase__=1_3							,			lowerCamelCase__=3_2							,			lowerCamelCase__=1							,			lowerCamelCase__=3							,			lowerCamelCase__=1_6							,			lowerCamelCase__=[1, 2, 1]							,			lowerCamelCase__=[2, 2, 4]							,			lowerCamelCase__=2							,			lowerCamelCase__=2.0							,			lowerCamelCase__=True							,			lowerCamelCase__=0.0							,			lowerCamelCase__=0.0							,			lowerCamelCase__=0.1							,			lowerCamelCase__="gelu"							,			lowerCamelCase__=False							,			lowerCamelCase__=True							,			lowerCamelCase__=0.02							,			lowerCamelCase__=1e-5							,			lowerCamelCase__=True							,			lowerCamelCase__=None							,			lowerCamelCase__=False							,			lowerCamelCase__=2							,			):
  						UpperCAmelCase__:  List[str]		       =   parent
  						UpperCAmelCase__:  Optional[Any]		       =   batch_size
  						UpperCAmelCase__:  Dict		       =   image_size
  						UpperCAmelCase__:  List[str]		       =   patch_size
  						UpperCAmelCase__:  Dict		       =   num_channels
  						UpperCAmelCase__:  Any		       =   embed_dim
  						UpperCAmelCase__:  Tuple		       =   depths
  						UpperCAmelCase__:  Any		       =   num_heads
  						UpperCAmelCase__:  Any		       =   window_size
  						UpperCAmelCase__:  str		       =   mlp_ratio
  						UpperCAmelCase__:  int		       =   qkv_bias
  						UpperCAmelCase__:  List[str]		       =   hidden_dropout_prob
  						UpperCAmelCase__:  Any		       =   attention_probs_dropout_prob
  						UpperCAmelCase__:  Any		       =   drop_path_rate
  						UpperCAmelCase__:  Any		       =   hidden_act
  						UpperCAmelCase__:  Union[str, Any]		       =   use_absolute_embeddings
  						UpperCAmelCase__:  Tuple		       =   patch_norm
  						UpperCAmelCase__:  str		       =   layer_norm_eps
  						UpperCAmelCase__:  str		       =   initializer_range
  						UpperCAmelCase__:  Any		       =   is_training
  						UpperCAmelCase__:  Union[str, Any]		       =   scope
  						UpperCAmelCase__:  Optional[Any]		       =   use_labels
  						UpperCAmelCase__:  List[Any]		       =   upscale
  
  						# here we set some attributes to make tests pass
  						UpperCAmelCase__:  Tuple		       =   len(A_	)
  						UpperCAmelCase__:  Optional[Any]		       =   embed_dim
  						UpperCAmelCase__:  str		       =   (image_size // patch_size) ** 2
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[Any]		       =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)
  
  						UpperCAmelCase__:  int		       =   None
  						if self.use_labels:
  							UpperCAmelCase__:  List[Any]		       =   ids_tensor([self.batch_size]							,			self.type_sequence_label_size	)
  
  						UpperCAmelCase__:  Optional[int]		       =   self.get_config()
  
  						return config, pixel_values, labels
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return SwinaSRConfig(
  						    image_size=self.image_size							,			patch_size=self.patch_size							,			num_channels=self.num_channels							,			embed_dim=self.embed_dim							,			depths=self.depths							,			num_heads=self.num_heads							,			window_size=self.window_size							,			mlp_ratio=self.mlp_ratio							,			qkv_bias=self.qkv_bias							,			hidden_dropout_prob=self.hidden_dropout_prob							,			attention_probs_dropout_prob=self.attention_probs_dropout_prob							,			drop_path_rate=self.drop_path_rate							,			hidden_act=self.hidden_act							,			use_absolute_embeddings=self.use_absolute_embeddings							,			path_norm=self.patch_norm							,			layer_norm_eps=self.layer_norm_eps							,			initializer_range=self.initializer_range							,			upscale=self.upscale							,			)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
  						UpperCAmelCase__:  Any		       =   SwinaSRModel(config=A_	)
  						model.to(A_	)
  						model.eval()
  						UpperCAmelCase__:  Optional[Any]		       =   model(A_	)
  
  						self.parent.assertEqual(
  						    result.last_hidden_state.shape							,			(self.batch_size, self.embed_dim, self.image_size, self.image_size)	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
  						UpperCAmelCase__:  Optional[Any]		       =   SwinaSRForImageSuperResolution(A_	)
  						model.to(A_	)
  						model.eval()
  						UpperCAmelCase__:  Optional[int]		       =   model(A_	)
  
  						UpperCAmelCase__:  int		       =   self.image_size * self.upscale
  						self.parent.assertEqual(
  						    result.reconstruction.shape							,			(self.batch_size, self.num_channels, expected_image_size, expected_image_size)	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[int]		       =   self.prepare_config_and_inputs()
  						UpperCAmelCase__       ,	UpperCAmelCase__       ,	UpperCAmelCase__:  List[str]		       =   config_and_inputs
  						UpperCAmelCase__:  Union[str, Any]		       =   {"pixel_values": pixel_values}
  						return config, inputs_dict
  
  @require_torch
  class __UpperCamelCase    (							_a				,_a				,unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					__magic_name__     			=      (SwinaSRModel, SwinaSRForImageSuperResolution) if is_torch_available() else ()
  					__magic_name__     			=      {"feature-extraction": SwinaSRModel} if is_torch_available() else {}
  
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Tuple		       =   SwinaSRModelTester(self	)
  						UpperCAmelCase__:  List[str]		       =   ConfigTester(self							,			config_class=A_							,			embed_dim=3_7	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						self.config_tester.create_and_test_config_to_json_string()
  						self.config_tester.create_and_test_config_to_json_file()
  						self.config_tester.create_and_test_config_from_and_save_pretrained()
  						self.config_tester.create_and_test_config_with_num_labels()
  						self.config_tester.check_config_can_be_init_without_params()
  						self.config_tester.check_config_arguments_init()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[str]		       =   self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_model(*A_	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  int		       =   self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_for_image_super_resolution(*A_	)
  
  
  
  
  
  					@unittest.skip(reason="Got `CUDA error: misaligned address` with PyTorch 2.0.0."	)
  					def       _UpperCAmelCase						(							self	):
  						pass
  
  
  
  
  
  					@unittest.skip(reason="Swin2SR does not use inputs_embeds"	)
  					def       _UpperCAmelCase						(							self	):
  						pass
  
  
  
  
  
  					@unittest.skip(reason="Swin2SR does not support training yet"	)
  					def       _UpperCAmelCase						(							self	):
  						pass
  
  
  
  
  
  					@unittest.skip(reason="Swin2SR does not support training yet"	)
  					def       _UpperCAmelCase						(							self	):
  						pass
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__       ,	UpperCAmelCase__:  int		       =   self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  							UpperCAmelCase__:  Optional[int]		       =   model_class(A_	)
  							self.assertIsInstance(model.get_input_embeddings()							,			(nn.Module)	)
  							UpperCAmelCase__:  Optional[Any]		       =   model.get_output_embeddings()
  							self.assertTrue(x is None or isinstance(A_							,			nn.Linear	)	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Union[str, Any]		       =   self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  							UpperCAmelCase__:  Optional[int]		       =   model_class(A_	)
  							UpperCAmelCase__:  Any		       =   inspect.signature(model.forward	)
  							# signature.parameters is an OrderedDict => so arg_names order is deterministic
  							UpperCAmelCase__:  Any		       =   [*signature.parameters.keys()]
  
  							UpperCAmelCase__:  List[Any]		       =   ["pixel_values"]
  							self.assertListEqual(arg_names[:1]							,			A_	)
  
  
  
  
  
  					@slow
  					def       _UpperCAmelCase						(							self	):
  						for model_name in SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  							UpperCAmelCase__:  List[Any]		       =   SwinaSRModel.from_pretrained(A_	)
  							self.assertIsNotNone(A_	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__       ,	UpperCAmelCase__:  List[str]		       =   self.model_tester.prepare_config_and_inputs_for_common()
  
  						UpperCAmelCase__:  int		       =   _config_zero_init(A_	)
  						for model_class in self.all_model_classes:
  							UpperCAmelCase__:  Any		       =   model_class(config=A_	)
  							for name, param in model.named_parameters():
  								if "logit_scale" in name:
  									continue
  								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"							,			)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Any		       =   self.model_tester.prepare_config_and_inputs_for_common()
  						UpperCAmelCase__:  List[str]		       =   True
  
  						for model_class in self.all_model_classes:
  							UpperCAmelCase__:  int		       =   True
  							UpperCAmelCase__:  Dict		       =   False
  							UpperCAmelCase__:  Optional[Any]		       =   True
  							UpperCAmelCase__:  Tuple		       =   model_class(A_	)
  							model.to(A_	)
  							model.eval()
  							with torch.no_grad():
  								UpperCAmelCase__:  Optional[Any]		       =   model(**self._prepare_for_class(A_							,			A_	)	)
  							UpperCAmelCase__:  List[Any]		       =   outputs.attentions
  							UpperCAmelCase__:  List[str]		       =   len(self.model_tester.depths	)
  							self.assertEqual(len(A_	)							,			A_	)
  
  							# check that output_attentions also work using config
  							del inputs_dict["output_attentions"]
  							UpperCAmelCase__:  Dict		       =   True
  							UpperCAmelCase__:  Optional[int]		       =   config.window_size**2
  							UpperCAmelCase__:  int		       =   model_class(A_	)
  							model.to(A_	)
  							model.eval()
  							with torch.no_grad():
  								UpperCAmelCase__:  Optional[Any]		       =   model(**self._prepare_for_class(A_							,			A_	)	)
  							UpperCAmelCase__:  Optional[int]		       =   outputs.attentions
  							self.assertEqual(len(A_	)							,			A_	)
  
  							self.assertListEqual(
  							    list(attentions[0].shape[-3:]	)							,			[self.model_tester.num_heads[0], window_size_squared, window_size_squared]							,			)
  							UpperCAmelCase__:  Tuple		       =   len(A_	)
  
  							# Check attention is always last and order is fine
  							UpperCAmelCase__:  Tuple		       =   True
  							UpperCAmelCase__:  List[str]		       =   True
  							UpperCAmelCase__:  List[str]		       =   model_class(A_	)
  							model.to(A_	)
  							model.eval()
  							with torch.no_grad():
  								UpperCAmelCase__:  int		       =   model(**self._prepare_for_class(A_							,			A_	)	)
  
  							self.assertEqual(out_len + 1							,			len(A_	)	)
  
  							UpperCAmelCase__:  List[Any]		       =   outputs.attentions
  
  							self.assertEqual(len(A_	)							,			A_	)
  
  							self.assertListEqual(
  							    list(self_attentions[0].shape[-3:]	)							,			[self.model_tester.num_heads[0], window_size_squared, window_size_squared]							,			)
  
  @require_vision
  @require_torch
  @slow
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   SwinaSRImageProcessor()
  						UpperCAmelCase__:  List[str]		       =   SwinaSRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64"	).to(A_	)
  
  						UpperCAmelCase__:  Any		       =   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
  						UpperCAmelCase__:  int		       =   processor(images=A_							,			return_tensors="pt"	).to(A_	)
  
  						# forward pass
  						with torch.no_grad():
  							UpperCAmelCase__:  Union[str, Any]		       =   model(**A_	)
  
  						# verify the logits
  						UpperCAmelCase__:  Any		       =   torch.Size([1, 3, 9_7_6, 1_2_9_6]	)
  						self.assertEqual(outputs.reconstruction.shape							,			A_	)
  						UpperCAmelCase__:  Union[str, Any]		       =   torch.tensor(
  						    [[0.5_458, 0.5_546, 0.5_638], [0.5_526, 0.5_565, 0.5_651], [0.5_396, 0.5_426, 0.5_621]]	).to(A_	)
  						self.assertTrue(torch.allclose(outputs.reconstruction[0, 0, :3, :3]							,			A_							,			atol=1e-4	)	)
  
  
  
  
style_context: 
  
  _lowerCAmelCase     :			Optional[int]    ={
      """+""": lambda x, y: x + y,
      """-""": lambda x, y: x - y,
      """*""": lambda x, y: x * y,
      """/""": lambda x, y: x / y,
  }
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE			):
  	return c.isdigit()
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  str		       =   []
  
  	# iterate over the string in reverse order
  	for c in expression.split()[::-1]:
  		# push operand to stack
  		if is_operand(SCREAMING_SNAKE_CASE			):
  			stack.append(int(SCREAMING_SNAKE_CASE			)			)
  
  		else:
  			# pop values from stack can calculate the result
  			# push the result onto the stack again
  			UpperCAmelCase__:  Any		       =   stack.pop()
  			UpperCAmelCase__:  int		       =   stack.pop()
  			stack.append(calc[c](SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)			)
  
  	return stack.pop()
  
  
  # Driver code
  if __name__ == "__main__":
  					_lowerCAmelCase     :			Optional[int]    ="""+ 9 * 2 6"""
  					print(evaluate(test_expression))
  
  					_lowerCAmelCase     :			Optional[Any]    ="""/ * 10 2 + 4 1 """
  					print(evaluate(test_expression))