import copy
import inspect
import unittest

from transformers import PretrainedConfig, SwiftFormerConfig
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, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch
							from torch import nn

							from transformers import SwiftFormerForImageClassification, SwiftFormerModel
							from transformers.models.swiftformer.modeling_swiftformer import SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import ViTImageProcessor


class 						lowercase    :




							def __init__(						self   :					int	,							_UpperCamelCase   :					List[Any]	,							_UpperCamelCase   :					Optional[int]=13	,							_UpperCamelCase   :					Dict=3	,							_UpperCamelCase   :					Optional[int]=True	,							_UpperCamelCase   :					Optional[int]=True	,							_UpperCamelCase   :					Union[str, Any]=0.1	,							_UpperCamelCase   :					str=0.1	,							_UpperCamelCase   :					Dict=224	,							_UpperCamelCase   :					Optional[Any]=1_000	,							_UpperCamelCase   :					Optional[Any]=[3, 3, 6, 4]	,							_UpperCamelCase   :					Union[str, Any]=[48, 56, 112, 220]	,							)					->				str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       parent
												SCREAMING_SNAKE_CASE    			=       batch_size
												SCREAMING_SNAKE_CASE    			=       num_channels
												SCREAMING_SNAKE_CASE    			=       is_training
												SCREAMING_SNAKE_CASE    			=       use_labels
												SCREAMING_SNAKE_CASE    			=       hidden_dropout_prob
												SCREAMING_SNAKE_CASE    			=       attention_probs_dropout_prob
												SCREAMING_SNAKE_CASE    			=       num_labels
												SCREAMING_SNAKE_CASE    			=       image_size
												SCREAMING_SNAKE_CASE    			=       layer_depths
												SCREAMING_SNAKE_CASE    			=       embed_dims




							def 	__snake_case(						self   :					Dict      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

												SCREAMING_SNAKE_CASE    			=       None
												if self.use_labels:
																	SCREAMING_SNAKE_CASE    			=       ids_tensor([self.batch_size]	,							self.num_labels      )

												SCREAMING_SNAKE_CASE    			=       self.get_config()

												return config, pixel_values, labels




							def 	__snake_case(						self   :					List[str]      )					->				Tuple:



												'''simple docstring'''

												return SwiftFormerConfig(
												    depths=self.layer_depths	,							embed_dims=self.embed_dims	,							mlp_ratio=4	,							downsamples=[True, True, True, True]	,							hidden_act="gelu"	,							num_labels=self.num_labels	,							down_patch_size=3	,							down_stride=2	,							down_pad=1	,							drop_rate=0.0	,							drop_path_rate=0.0	,							use_layer_scale=_UpperCamelCase	,							layer_scale_init_value=1e-5	,							)




							def 	__snake_case(						self   :					Union[str, Any]	,							_UpperCamelCase   :					int	,							_UpperCamelCase   :					int	,							_UpperCamelCase   :					str      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SwiftFormerModel(config=_UpperCamelCase      )
												model.to(_UpperCamelCase      )
												model.eval()
												SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )
												self.parent.assertEqual(result.last_hidden_state.shape	,							(self.batch_size, self.embed_dims[-1], 7, 7)      )




							def 	__snake_case(						self   :					int	,							_UpperCamelCase   :					int	,							_UpperCamelCase   :					str	,							_UpperCamelCase   :					str      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.num_labels
												SCREAMING_SNAKE_CASE    			=       SwiftFormerForImageClassification(_UpperCamelCase      )
												model.to(_UpperCamelCase      )
												model.eval()
												SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase	,							labels=_UpperCamelCase      )
												self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.num_labels)      )

												SCREAMING_SNAKE_CASE    			=       SwiftFormerForImageClassification(_UpperCamelCase      )
												model.to(_UpperCamelCase      )
												model.eval()

												SCREAMING_SNAKE_CASE    			=       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )
												SCREAMING_SNAKE_CASE    			=       model(_UpperCamelCase      )
												self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.num_labels)      )





							def 	__snake_case(						self   :					Any      )					->				Tuple:



												'''simple docstring'''

												((SCREAMING_SNAKE_CASE)			,   (SCREAMING_SNAKE_CASE)			,   (SCREAMING_SNAKE_CASE))    			=       self.prepare_config_and_inputs()
												SCREAMING_SNAKE_CASE    			=       {"pixel_values": pixel_values}
												return config, inputs_dict



@require_torch
class 						lowercase    (     a				,       a				,       unittest.TestCase     ):
							lowercase__						:       List[str]								=							(SwiftFormerModel, SwiftFormerForImageClassification) if is_torch_available() else ()
							lowercase__						:       str								=							(
							    {"""feature-extraction""": SwiftFormerModel, """image-classification""": SwiftFormerForImageClassification}
							    if is_torch_available()
							    else {}
							)

							lowercase__						:       Optional[Any]								=							False
							lowercase__						:       Optional[Any]								=							False
							lowercase__						:       Any								=							False
							lowercase__						:       Union[str, Any]								=							False
							lowercase__						:       str								=							False




							def 	__snake_case(						self   :					Optional[int]      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SwiftFormerModelTester(self      )
												SCREAMING_SNAKE_CASE    			=       ConfigTester(
												    self	,							config_class=_UpperCamelCase	,							has_text_modality=_UpperCamelCase	,							hidden_size=37	,							num_attention_heads=12	,							num_hidden_layers=12	,							)




							def 	__snake_case(						self   :					str      )					->				int:



												'''simple docstring'''

												self.config_tester.run_common_tests()




							@unittest.skip(reason="SwiftFormer does not use inputs_embeds"      )
							def 	__snake_case(						self   :					List[str]      )					->				Dict:



												'''simple docstring'''

												pass




							def 	__snake_case(						self   :					Dict      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE			,   SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																	SCREAMING_SNAKE_CASE    			=       model_class(_UpperCamelCase      )
																	SCREAMING_SNAKE_CASE    			=       model.get_output_embeddings()
																	self.assertTrue(x is None or isinstance(_UpperCamelCase	,							nn.Linear      )      )




							def 	__snake_case(						self   :					Tuple      )					->				Dict:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE			,   SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs_for_common()

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

																	SCREAMING_SNAKE_CASE    			=       ["pixel_values"]
																	self.assertListEqual(arg_names[:1]	,							_UpperCamelCase      )




							def 	__snake_case(						self   :					Tuple      )					->				List[Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*_UpperCamelCase      )




							def 	__snake_case(						self   :					Optional[int]      )					->				int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*_UpperCamelCase      )




							@slow
							def 	__snake_case(						self   :					List[str]      )					->				Optional[int]:



												'''simple docstring'''

												for model_name in SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	SCREAMING_SNAKE_CASE    			=       SwiftFormerModel.from_pretrained(_UpperCamelCase      )
																	self.assertIsNotNone(_UpperCamelCase      )




							@unittest.skip(reason="SwiftFormer does not output attentions"      )
							def 	__snake_case(						self   :					Dict      )					->				Union[str, Any]:



												'''simple docstring'''

												pass




							def 	__snake_case(						self   :					Union[str, Any]      )					->				Optional[Any]:



												'''simple docstring'''

												def check_hidden_states_output(_UpperCamelCase   :					List[str]	,							_UpperCamelCase   :					Any	,							_UpperCamelCase   :					Dict      ):
																	SCREAMING_SNAKE_CASE    			=       model_class(_UpperCamelCase      )
																	model.to(_UpperCamelCase      )
																	model.eval()

																	with torch.no_grad():
																						SCREAMING_SNAKE_CASE    			=       model(**self._prepare_for_class(_UpperCamelCase	,							_UpperCamelCase      )      )

																	SCREAMING_SNAKE_CASE    			=       outputs.hidden_states

																	SCREAMING_SNAKE_CASE    			=       8
																	self.assertEqual(len(_UpperCamelCase      )	,							_UpperCamelCase      )  # TODO

																	# SwiftFormer's feature maps are of shape (batch_size, embed_dims, height, width)
																	# with the width and height being successively divided by 2, after every 2 blocks
																	for i in range(len(_UpperCamelCase      )      ):
																						self.assertEqual(
																						    hidden_states[i].shape	,							torch.Size(
																						        [
																						            self.model_tester.batch_size,
																						            self.model_tester.embed_dims[i // 2],
																						            (self.model_tester.image_size // 4) // 2 ** (i // 2),
																						            (self.model_tester.image_size // 4) // 2 ** (i // 2),
																						        ]      )	,							)

												SCREAMING_SNAKE_CASE			,   SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																	SCREAMING_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"]
																	SCREAMING_SNAKE_CASE    			=       True

																	check_hidden_states_output(_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase      )




							def 	__snake_case(						self   :					Optional[int]      )					->				Union[str, Any]:



												'''simple docstring'''

												def _config_zero_init(_UpperCamelCase   :					Union[str, Any]      ):
																	SCREAMING_SNAKE_CASE    			=       copy.deepcopy(_UpperCamelCase      )
																	for key in configs_no_init.__dict__.keys():
																						if "_range" in key or "_std" in key or "initializer_factor" in key or "layer_scale" in key:
																											setattr(_UpperCamelCase	,							_UpperCamelCase	,							1e-10      )
																						if isinstance(getattr(_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase      )	,							_UpperCamelCase      ):
																											SCREAMING_SNAKE_CASE    			=       _config_zero_init(getattr(_UpperCamelCase	,							_UpperCamelCase      )      )
																											setattr(_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase      )
																	return configs_no_init

												SCREAMING_SNAKE_CASE			,   SCREAMING_SNAKE_CASE    			=       self.model_tester.prepare_config_and_inputs_for_common()

												SCREAMING_SNAKE_CASE    			=       _config_zero_init(_UpperCamelCase      )
												for model_class in self.all_model_classes:
																	SCREAMING_SNAKE_CASE    			=       model_class(config=_UpperCamelCase      )
																	for name, param in model.named_parameters():
																						if param.requires_grad:
																											self.assertIn(
																											    ((param.data.mean() * 1e9) / 1e9).round().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 	__snake_case(						self   :					Optional[Any]      )					->				List[str]:



												'''simple docstring'''

												pass





def 	__lowerCamelCase							():
					SCREAMING_SNAKE_CASE    			=       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"  )
					return image


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




							@cached_property
							def 	__snake_case(						self   :					Optional[Any]      )					->				List[str]:



												'''simple docstring'''

												return ViTImageProcessor.from_pretrained("MBZUAI/swiftformer-xs"      ) if is_vision_available() else None





							@slow
							def 	__snake_case(						self   :					Tuple      )					->				Union[str, Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE    			=       SwiftFormerForImageClassification.from_pretrained("MBZUAI/swiftformer-xs"      ).to(_UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       self.default_image_processor
												SCREAMING_SNAKE_CASE    			=       prepare_img()
												SCREAMING_SNAKE_CASE    			=       image_processor(images=_UpperCamelCase	,							return_tensors="pt"      ).to(_UpperCamelCase      )

												# forward pass
												with torch.no_grad():
																	SCREAMING_SNAKE_CASE    			=       model(**_UpperCamelCase      )

												# verify the logits
												SCREAMING_SNAKE_CASE    			=       torch.Size((1, 1_000)      )
												self.assertEqual(outputs.logits.shape	,							_UpperCamelCase      )

												SCREAMING_SNAKE_CASE    			=       torch.tensor([[-2.1_703e00, 2.1_107e00, -2.0_811e00]]      ).to(_UpperCamelCase      )
												self.assertTrue(torch.allclose(outputs.logits[0, :3]	,							_UpperCamelCase	,							atol=1e-4      )      )





from __future__ import annotations

import math





def 	__lowerCamelCase							(UpperCAmelCase__     :							int  ):

					if 1 < number < 4:
										# 2 and 3 are primes
										return True
					elif number < 2 or number % 2 == 0 or number % 3 == 0:
										# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
										return False

					# All primes number are in format of 6k +/- 1
					for i in range(5      , int(math.sqrt(UpperCAmelCase__  ) + 1  )      , 6  ):
										if number % i == 0 or number % (i + 2) == 0:
															return False
					return True


_lowerCamelCase					:   Tuple							=		[num for num in range(3, 10_00_01, 2) if not is_prime(num)]





def 	__lowerCamelCase							(UpperCAmelCase__     :							int  ):
					if not isinstance(UpperCAmelCase__      , UpperCAmelCase__  ):
										raise ValueError("n must be an integer"  )
					if n <= 0:
										raise ValueError("n must be >= 0"  )

					SCREAMING_SNAKE_CASE    			=       []
					for num in range(len(UpperCAmelCase__  )  ):
										SCREAMING_SNAKE_CASE    			=       0
										while 2 * i * i <= odd_composites[num]:
															SCREAMING_SNAKE_CASE    			=       odd_composites[num] - 2 * i * i
															if is_prime(UpperCAmelCase__  ):
																				break
															i += 1
										else:
															list_nums.append(odd_composites[num]  )
															if len(UpperCAmelCase__  ) == n:
																				return list_nums

					return []





def 	__lowerCamelCase							():
					return compute_nums(1  )[0]


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




