



"""simple docstring"""






import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()



class 			A__   (  __SCREAMING_SNAKE_CASE  ,		__SCREAMING_SNAKE_CASE  ,		unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	VQModel
	SCREAMING_SNAKE_CASE          =	'sample'

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=(32, 32))				->       Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       4
				__lowerCAmelCase      :  Dict												=       3

				__lowerCAmelCase      :  int												=       floats_tensor((batch_size, num_channels) + sizes).to(_SCREAMING_SNAKE_CASE)

				return {"sample": image}

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       Optional[int]:

				"""simple docstring"""

				return (3, 32, 32)

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Any:

				"""simple docstring"""

				return (3, 32, 32)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       {
				    "block_out_channels": [32, 64],
				    "in_channels": 3,
				    "out_channels": 3,
				    "down_block_types": ["DownEncoderBlock2D", "DownEncoderBlock2D"],
				    "up_block_types": ["UpDecoderBlock2D", "UpDecoderBlock2D"],
				    "latent_channels": 3,
				}
				__lowerCAmelCase      :  Tuple												=       self.dummy_input
				return init_dict, inputs_dict

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				pass

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

				"""simple docstring"""

				pass

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase						,	__lowerCAmelCase      :  str												=       VQModel.from_pretrained("fusing/vqgan-dummy"       ,			output_loading_info=_SCREAMING_SNAKE_CASE)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE)
				self.assertEqual(len(loading_info["missing_keys"])       ,			0)

				model.to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       model(**self.dummy_input)

				assert image is not None, "Make sure output is not None"







	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       VQModel.from_pretrained("fusing/vqgan-dummy")
				model.to(_SCREAMING_SNAKE_CASE).eval()

				torch.manual_seed(0)
				if torch.cuda.is_available():
							torch.cuda.manual_seed_all(0)

				__lowerCAmelCase      :  Optional[Any]												=       torch.randn(1       ,			model.config.in_channels       ,			model.config.sample_size       ,			model.config.sample_size)
				__lowerCAmelCase      :  int												=       image.to(_SCREAMING_SNAKE_CASE)
				with torch.no_grad():
							__lowerCAmelCase      :  Union[str, Any]												=       model(_SCREAMING_SNAKE_CASE).sample

				__lowerCAmelCase      :  Optional[int]												=       output[0, -1, -3:, -3:].flatten().cpu()
				# fmt: off
				__lowerCAmelCase      :  Tuple												=       torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143])
				# fmt: on
				self.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ,			atol=1e-3))




"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__snake_case							:   Optional[int]      =    logging.get_logger(__name__)



class 			A__   (  __SCREAMING_SNAKE_CASE  ,		__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	'maskformer-swin'

	SCREAMING_SNAKE_CASE          =	{
	    'num_attention_heads': 'num_heads',
	    'num_hidden_layers': 'num_layers',
	}

	def __init__(     self:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		int=224       ,			_SCREAMING_SNAKE_CASE:		Tuple=4       ,			_SCREAMING_SNAKE_CASE:		int=3       ,			_SCREAMING_SNAKE_CASE:		List[Any]=96       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=[2, 2, 6, 2]       ,			_SCREAMING_SNAKE_CASE:		Any=[3, 6, 12, 24]       ,			_SCREAMING_SNAKE_CASE:		List[str]=7       ,			_SCREAMING_SNAKE_CASE:		List[str]=4.0       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=True       ,			_SCREAMING_SNAKE_CASE:		Tuple=0.0       ,			_SCREAMING_SNAKE_CASE:		Any=0.0       ,			_SCREAMING_SNAKE_CASE:		Any=0.1       ,			_SCREAMING_SNAKE_CASE:		str="gelu"       ,			_SCREAMING_SNAKE_CASE:		Tuple=False       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=0.02       ,			_SCREAMING_SNAKE_CASE:		str=1e-5       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=None       ,			_SCREAMING_SNAKE_CASE:		str=None       ,			**_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			)				->       List[str]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  int												=       image_size
				__lowerCAmelCase      :  Any												=       patch_size
				__lowerCAmelCase      :  Tuple												=       num_channels
				__lowerCAmelCase      :  Any												=       embed_dim
				__lowerCAmelCase      :  Any												=       depths
				__lowerCAmelCase      :  Dict												=       len(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       num_heads
				__lowerCAmelCase      :  Tuple												=       window_size
				__lowerCAmelCase      :  Dict												=       mlp_ratio
				__lowerCAmelCase      :  Any												=       qkv_bias
				__lowerCAmelCase      :  Union[str, Any]												=       hidden_dropout_prob
				__lowerCAmelCase      :  int												=       attention_probs_dropout_prob
				__lowerCAmelCase      :  Tuple												=       drop_path_rate
				__lowerCAmelCase      :  int												=       hidden_act
				__lowerCAmelCase      :  Optional[int]												=       use_absolute_embeddings
				__lowerCAmelCase      :  List[str]												=       layer_norm_eps
				__lowerCAmelCase      :  Any												=       initializer_range
				# we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
				# this indicates the channel dimension after the last stage of the model
				__lowerCAmelCase      :  Optional[Any]												=       int(embed_dim * 2 ** (len(_SCREAMING_SNAKE_CASE) - 1))
				__lowerCAmelCase      :  Any												=       ["stem"] + [F"""stage{idx}""" for idx in range(1       ,			len(_SCREAMING_SNAKE_CASE) + 1)]
				__lowerCAmelCase						,	__lowerCAmelCase      :  List[str]												=       get_aligned_output_features_output_indices(
				    out_features=_SCREAMING_SNAKE_CASE       ,			out_indices=_SCREAMING_SNAKE_CASE       ,			stage_names=self.stage_names)