






from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer


@dataclass
class        __UpperCamelCase    (     _lowerCAmelCase   ):
	__snake_case	:torch.FloatTensor


class        __UpperCamelCase    (     _lowerCAmelCase   ,			_lowerCAmelCase   ):







	@register_to_config
	def __init__(  self      :							Tuple       ,				_lowerCAmelCase      :							int = 3       ,				_lowerCAmelCase      :							int = 3       ,				_lowerCAmelCase      :							Tuple[str] = ("DownEncoderBlock2D",)       ,				_lowerCAmelCase      :							Tuple[str] = ("UpDecoderBlock2D",)       ,				_lowerCAmelCase      :							Tuple[int] = (64,)       ,				_lowerCAmelCase      :							int = 1       ,				_lowerCAmelCase      :							str = "silu"       ,				_lowerCAmelCase      :							int = 3       ,				_lowerCAmelCase      :							int = 32       ,				_lowerCAmelCase      :							int = 256       ,				_lowerCAmelCase      :							int = 32       ,				_lowerCAmelCase      :							Optional[int] = None       ,				_lowerCAmelCase      :							float = 0.18_215       ,				_lowerCAmelCase      :							str = "group"       ,				)		-> Dict:
		"""simple docstring"""







		super().__init__()

		# pass init params to Encoder
		__lowercase             =  Encoder(
		    in_channels=_lowerCAmelCase       ,				out_channels=_lowerCAmelCase       ,				down_block_types=_lowerCAmelCase       ,				block_out_channels=_lowerCAmelCase       ,				layers_per_block=_lowerCAmelCase       ,				act_fn=_lowerCAmelCase       ,				norm_num_groups=_lowerCAmelCase       ,				double_z=_lowerCAmelCase       ,				)

		__lowercase             =  vq_embed_dim if vq_embed_dim is not None else latent_channels

		__lowercase             =  nn.Convad(_lowerCAmelCase       ,				_lowerCAmelCase       ,				1			)
		__lowercase             =  VectorQuantizer(_lowerCAmelCase       ,				_lowerCAmelCase       ,				beta=0.25       ,				remap=_lowerCAmelCase       ,				sane_index_shape=_lowerCAmelCase			)
		__lowercase             =  nn.Convad(_lowerCAmelCase       ,				_lowerCAmelCase       ,				1			)

		# pass init params to Decoder
		__lowercase             =  Decoder(
		    in_channels=_lowerCAmelCase       ,				out_channels=_lowerCAmelCase       ,				up_block_types=_lowerCAmelCase       ,				block_out_channels=_lowerCAmelCase       ,				layers_per_block=_lowerCAmelCase       ,				act_fn=_lowerCAmelCase       ,				norm_num_groups=_lowerCAmelCase       ,				norm_type=_lowerCAmelCase       ,				)







	@apply_forward_hook
	def  _a   (  self      :							List[str]       ,				_lowerCAmelCase      :							torch.FloatTensor       ,				_lowerCAmelCase      :							bool = True			)		-> VQEncoderOutput:
		"""simple docstring"""







		__lowercase             =  self.encoder(_lowerCAmelCase			)
		__lowercase             =  self.quant_conv(_lowerCAmelCase			)

		if not return_dict:
			return (h,)

		return VQEncoderOutput(latents=_lowerCAmelCase			)







	@apply_forward_hook
	def  _a   (  self      :							Any       ,				_lowerCAmelCase      :							torch.FloatTensor       ,				_lowerCAmelCase      :							bool = False       ,				_lowerCAmelCase      :							bool = True			)		-> Union[DecoderOutput, torch.FloatTensor]:
		"""simple docstring"""







		if not force_not_quantize:
			__lowercase       ,						__lowercase       ,						__lowercase             =  self.quantize(_lowerCAmelCase			)
		else:
			__lowercase             =  h
		__lowercase             =  self.post_quant_conv(_lowerCAmelCase			)
		__lowercase             =  self.decoder(_lowerCAmelCase       ,				quant if self.config.norm_type == """spatial""" else None			)

		if not return_dict:
			return (dec,)

		return DecoderOutput(sample=_lowerCAmelCase			)







	def  _a   (  self      :							List[Any]       ,				_lowerCAmelCase      :							torch.FloatTensor       ,				_lowerCAmelCase      :							bool = True			)		-> Union[DecoderOutput, torch.FloatTensor]:
		"""simple docstring"""







		__lowercase             =  sample
		__lowercase             =  self.encode(_lowerCAmelCase			).latents
		__lowercase             =  self.decode(_lowerCAmelCase			).sample

		if not return_dict:
			return (dec,)

		return DecoderOutput(sample=_lowerCAmelCase			)









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__UpperCamelCase      :      Tuple     						=						{
    """configuration_swiftformer""": [
        """SWIFTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """SwiftFormerConfig""",
        """SwiftFormerOnnxConfig""",
    ]
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__UpperCamelCase      :      Optional[Any]     						=						[
						    """SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """SwiftFormerForImageClassification""",
						    """SwiftFormerModel""",
						    """SwiftFormerPreTrainedModel""",
						]

if TYPE_CHECKING:
						from .configuration_swiftformer import (
						    SWIFTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    SwiftFormerConfig,
						    SwiftFormerOnnxConfig,
						)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_swiftformer import (
												    SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    SwiftFormerForImageClassification,
												    SwiftFormerModel,
												    SwiftFormerPreTrainedModel,
												)

else:
						import sys

						__UpperCamelCase      :      List[Any]     						=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

