

'''simple docstring'''




from __future__ import annotations




def 						UpperCamelCase	(			a			)				->     bool:






     '''simple docstring'''
     __magic_name__						       =    str(a			)
     return len(a			) == 9 and set(a			) == set('''123456789'''			)




def 						UpperCamelCase	(			)				->     int | None:






     '''simple docstring'''
     for base_num in range(9999		,						4999		,						-1			):
          __magic_name__						       =    10_0002 * base_num
          if is_9_pandigital(a			):
               return candidate

     for base_num in range(333		,						99		,						-1			):
          __magic_name__						       =    100_2003 * base_num
          if is_9_pandigital(a			):
               return candidate

     return None


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









'''simple docstring'''




import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, 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 SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
      from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor






class   _SCREAMING_SNAKE_CASE   :



 def __init__(   self		:   str			,				a__		:   Union[str, Any]			,				a__		:   Dict=13			,				a__		:   List[str]=32			,				a__		:   List[Any]=2			,				a__		:   List[str]=3			,				a__		:   Union[str, Any]=16			,				a__		:   Dict=[1, 2, 1]			,				a__		:   Optional[Any]=[2, 2, 4]			,				a__		:   List[str]=2			,				a__		:   Optional[Any]=2.0			,				a__		:   Union[str, Any]=True			,				a__		:   int=0.0			,				a__		:   int=0.0			,				a__		:   Tuple=0.1			,				a__		:   List[str]="gelu"			,				a__		:   str=False			,				a__		:   Optional[int]=True			,				a__		:   List[Any]=0.02			,				a__		:   Any=1E-5			,				a__		:   int=True			,				a__		:   List[Any]=None			,				a__		:   Dict=True			,				a__		:   Optional[int]=10			,				a__		:   Any=8			,				):
      __magic_name__						       =    parent
      __magic_name__						       =    batch_size
      __magic_name__						       =    image_size
      __magic_name__						       =    patch_size
      __magic_name__						       =    num_channels
      __magic_name__						       =    embed_dim
      __magic_name__						       =    depths
      __magic_name__						       =    num_heads
      __magic_name__						       =    window_size
      __magic_name__						       =    mlp_ratio
      __magic_name__						       =    qkv_bias
      __magic_name__						       =    hidden_dropout_prob
      __magic_name__						       =    attention_probs_dropout_prob
      __magic_name__						       =    drop_path_rate
      __magic_name__						       =    hidden_act
      __magic_name__						       =    use_absolute_embeddings
      __magic_name__						       =    patch_norm
      __magic_name__						       =    layer_norm_eps
      __magic_name__						       =    initializer_range
      __magic_name__						       =    is_training
      __magic_name__						       =    scope
      __magic_name__						       =    use_labels
      __magic_name__						       =    type_sequence_label_size
      __magic_name__						       =    encoder_stride



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

      __magic_name__						       =    None
      if self.use_labels:
           __magic_name__						       =    ids_tensor([self.batch_size]			,				self.type_sequence_label_size      )

      __magic_name__						       =    self.get_config()

      return config, pixel_values, labels



 def 			snake_case__  (   self		:   Optional[int]      ):
      return SwinvaConfig(
          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			,				encoder_stride=self.encoder_stride			,				)



 def 			snake_case__  (   self		:   Optional[int]			,				a__		:   Union[str, Any]			,				a__		:   Union[str, Any]			,				a__		:   Optional[int]      ):
      __magic_name__						       =    SwinvaModel(config=a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__      )

      __magic_name__						       =    ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths      ) - 1))
      __magic_name__						       =    int(config.embed_dim * 2 ** (len(config.depths      ) - 1)      )

      self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, expected_seq_len, expected_dim)      )



 def 			snake_case__  (   self		:   Optional[Any]			,				a__		:   Optional[Any]			,				a__		:   str			,				a__		:   int      ):
      __magic_name__						       =    SwinvaForMaskedImageModeling(config=a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(
          result.logits.shape			,				(self.batch_size, self.num_channels, self.image_size, self.image_size)      )

      # test greyscale images
      __magic_name__						       =    1
      __magic_name__						       =    SwinvaForMaskedImageModeling(a__      )
      model.to(a__      )
      model.eval()

      __magic_name__						       =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, 1, self.image_size, self.image_size)      )



 def 			snake_case__  (   self		:   List[str]			,				a__		:   List[str]			,				a__		:   List[Any]			,				a__		:   Any      ):
      __magic_name__						       =    self.type_sequence_label_size
      __magic_name__						       =    SwinvaForImageClassification(a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__			,				labels=a__      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.type_sequence_label_size)      )



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__						       =    self.prepare_config_and_inputs()
      __magic_name__       ,  __magic_name__       ,  __magic_name__						       =    config_and_inputs
      __magic_name__						       =    {'''pixel_values''': pixel_values}
      return config, inputs_dict






@require_torch
class   _SCREAMING_SNAKE_CASE   (   __a		,__a		,unittest.TestCase     ):
 __SCREAMING_SNAKE_CASE					:int      	=					(
     (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
 )
 __SCREAMING_SNAKE_CASE					:Tuple      	=					(
     {"""feature-extraction""": SwinvaModel, """image-classification""": SwinvaForImageClassification}
     if is_torch_available()
     else {}
 )

 __SCREAMING_SNAKE_CASE					:Union[str, Any]      	=					False
 __SCREAMING_SNAKE_CASE					:List[Any]      	=					False
 __SCREAMING_SNAKE_CASE					:Dict      	=					False
 __SCREAMING_SNAKE_CASE					:Union[str, Any]      	=					False



 def 			snake_case__  (   self		:   str      ):
      __magic_name__						       =    SwinvaModelTester(self      )
      __magic_name__						       =    ConfigTester(self			,				config_class=a__			,				embed_dim=37      )



 def 			snake_case__  (   self		:   Tuple      ):
      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 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*a__      )



 @unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''      )
 def 			snake_case__  (   self		:   str      ):
      pass



 @unittest.skip(reason='''Swinv2 does not use inputs_embeds'''      )
 def 			snake_case__  (   self		:   Union[str, Any]      ):
      pass



 def 			snake_case__  (   self		:   Optional[int]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(a__      )
           self.assertIsInstance(model.get_input_embeddings()			,				(nn.Module)      )
           __magic_name__						       =    model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(a__			,				nn.Linear      )      )



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(a__      )
           __magic_name__						       =    inspect.signature(model.forward      )
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           __magic_name__						       =    [*signature.parameters.keys()]

           __magic_name__						       =    ['''pixel_values''']
           self.assertListEqual(arg_names[:1]			,				a__      )



 def 			snake_case__  (   self		:   int      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__						       =    True

      for model_class in self.all_model_classes:
           __magic_name__						       =    True
           __magic_name__						       =    False
           __magic_name__						       =    True
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.eval()
           with torch.no_grad():
                __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )
           __magic_name__						       =    outputs.attentions
           __magic_name__						       =    len(self.model_tester.depths      )
           self.assertEqual(len(a__      )			,				a__      )

           # check that output_attentions also work using config
           del inputs_dict["output_attentions"]
           __magic_name__						       =    True
           __magic_name__						       =    config.window_size**2
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.eval()
           with torch.no_grad():
                __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )
           __magic_name__						       =    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]			,				)
           __magic_name__						       =    len(a__      )

           # Check attention is always last and order is fine
           __magic_name__						       =    True
           __magic_name__						       =    True
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.eval()
           with torch.no_grad():
                __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )

           if hasattr(self.model_tester			,				'''num_hidden_states_types'''      ):
                __magic_name__						       =    self.model_tester.num_hidden_states_types
           else:
                # also another +1 for reshaped_hidden_states
                __magic_name__						       =    2
           self.assertEqual(out_len + added_hidden_states			,				len(a__      )      )

           __magic_name__						       =    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]			,				)



 def 			snake_case__  (   self		:   Any			,				a__		:   Dict			,				a__		:   str			,				a__		:   str			,				a__		:   List[Any]      ):
      __magic_name__						       =    model_class(a__      )
      model.to(a__      )
      model.eval()

      with torch.no_grad():
           __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )

      __magic_name__						       =    outputs.hidden_states

      __magic_name__						       =    getattr(
          self.model_tester			,				'''expected_num_hidden_layers'''			,				len(self.model_tester.depths      ) + 1      )
      self.assertEqual(len(a__      )			,				a__      )

      # Swinv2 has a different seq_length
      __magic_name__						       =    (
          config.patch_size
          if isinstance(config.patch_size			,				collections.abc.Iterable      )
          else (config.patch_size, config.patch_size)
      )

      __magic_name__						       =    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

      self.assertListEqual(
          list(hidden_states[0].shape[-2:]      )			,				[num_patches, self.model_tester.embed_dim]			,				)

      __magic_name__						       =    outputs.reshaped_hidden_states
      self.assertEqual(len(a__      )			,				a__      )

      __magic_name__       ,  __magic_name__       ,  __magic_name__       ,  __magic_name__						       =    reshaped_hidden_states[0].shape
      __magic_name__						       =    (
          reshaped_hidden_states[0].view(a__			,				a__			,				height * width      ).permute(0			,				2			,				1      )
      )
      self.assertListEqual(
          list(reshaped_hidden_states.shape[-2:]      )			,				[num_patches, self.model_tester.embed_dim]			,				)



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__						       =    (
          self.model_tester.image_size
          if isinstance(self.model_tester.image_size			,				collections.abc.Iterable      )
          else (self.model_tester.image_size, self.model_tester.image_size)
      )

      for model_class in self.all_model_classes:
           __magic_name__						       =    True
           self.check_hidden_states_output(a__			,				a__			,				a__			,				a__      )

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           __magic_name__						       =    True

           self.check_hidden_states_output(a__			,				a__			,				a__			,				a__      )



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__						       =    3

      __magic_name__						       =    (
          self.model_tester.image_size
          if isinstance(self.model_tester.image_size			,				collections.abc.Iterable      )
          else (self.model_tester.image_size, self.model_tester.image_size)
      )
      __magic_name__						       =    (
          config.patch_size
          if isinstance(config.patch_size			,				collections.abc.Iterable      )
          else (config.patch_size, config.patch_size)
      )

      __magic_name__						       =    image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
      __magic_name__						       =    image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

      for model_class in self.all_model_classes:
           __magic_name__						       =    True
           self.check_hidden_states_output(a__			,				a__			,				a__			,				(padded_height, padded_width)      )

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           __magic_name__						       =    True
           self.check_hidden_states_output(a__			,				a__			,				a__			,				(padded_height, padded_width)      )



 def 			snake_case__  (   self		:   str      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_image_modeling(*a__      )



 def 			snake_case__  (   self		:   Dict      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*a__      )



 @slow
 def 			snake_case__  (   self		:   Any      ):
      for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __magic_name__						       =    SwinvaModel.from_pretrained(a__      )
           self.assertIsNotNone(a__      )



 def 			snake_case__  (   self		:   List[str]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__						       =    _config_zero_init(a__      )
      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(config=a__      )
           for name, param in model.named_parameters():
                if "embeddings" not in name and "logit_scale" not in name and 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'''			,				)






@require_vision
@require_torch
class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):



 @cached_property
 def 			snake_case__  (   self		:   Optional[Any]      ):
      return (
          AutoImageProcessor.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''      )
          if is_vision_available()
          else None
      )



 @slow
 def 			snake_case__  (   self		:   Optional[int]      ):
      __magic_name__						       =    SwinvaForImageClassification.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''      ).to(
          a__      )
      __magic_name__						       =    self.default_image_processor

      __magic_name__						       =    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
      __magic_name__						       =    image_processor(images=a__			,				return_tensors='''pt'''      ).to(a__      )

      # forward pass
      with torch.no_grad():
           __magic_name__						       =    model(**a__      )

      # verify the logits
      __magic_name__						       =    torch.Size((1, 1000)      )
      self.assertEqual(outputs.logits.shape			,				a__      )
      __magic_name__						       =    torch.tensor([-0.3_947, -0.4_306, 0.0_026]      ).to(a__      )
      self.assertTrue(torch.allclose(outputs.logits[0, :3]			,				a__			,				atol=1E-4      )      )






