






"""simple docstring"""






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       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							torch.FloatTensor





class       snake_case_       (    _lowerCamelCase    ,							_lowerCamelCase       ):



	"""simple docstring"""

	@register_to_config
	def __init__(      self  ,					__a = 3  ,					__a = 3  ,					__a = ("DownEncoderBlock2D",)  ,					__a = ("UpDecoderBlock2D",)  ,					__a = (64,)  ,					__a = 1  ,					__a = "silu"  ,					__a = 3  ,					__a = 32  ,					__a = 256  ,					__a = 32  ,					__a = None  ,					__a = 0.1_8215  ,					__a = "group"  ,					):


					"""simple docstring"""

					super().__init__()

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

					A__							 =       vq_embed_dim if vq_embed_dim is not None else latent_channels

					A__							 =       nn.Convad(__a  ,					__a  ,					1						)
					A__							 =       VectorQuantizer(__a  ,					__a  ,					beta=0.25  ,					remap=__a  ,					sane_index_shape=__a						)
					A__							 =       nn.Convad(__a  ,					__a  ,					1						)

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


	@apply_forward_hook
	def       _UpperCAmelCase						(      self  ,					__a  ,					__a = True						):


					"""simple docstring"""

					A__							 =       self.encoder(__a						)
					A__							 =       self.quant_conv(__a						)

					if not return_dict:
									return (h,)

					return VQEncoderOutput(latents=__a						)


	@apply_forward_hook
	def       _UpperCAmelCase						(      self  ,					__a  ,					__a = False  ,					__a = True						):


					"""simple docstring"""

					if not force_not_quantize:
									A__ ,			A__ ,			A__							 =       self.quantize(__a						)
					else:
									A__							 =       h
					A__							 =       self.post_quant_conv(__a						)
					A__							 =       self.decoder(__a  ,					quant if self.config.norm_type == 'spatial' else None						)

					if not return_dict:
									return (dec,)

					return DecoderOutput(sample=__a						)






	def       _UpperCAmelCase						(      self  ,					__a  ,					__a = True						):


					"""simple docstring"""

					A__							 =       sample
					A__							 =       self.encode(__a						).latents
					A__							 =       self.decode(__a						).sample

					if not return_dict:
									return (dec,)

					return DecoderOutput(sample=__a						)










"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE						:						Any					   =       logging.get_logger(__name__)





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					"""timm_backbone"""


	def __init__(      self  ,					__a=None  ,					__a=3  ,					__a=True  ,					__a=True  ,					__a=None  ,					**__a  ,					):


					"""simple docstring"""

					super().__init__(**__a						)
					A__							 =       backbone
					A__							 =       num_channels
					A__							 =       features_only
					A__							 =       use_pretrained_backbone
					A__							 =       True
					A__							 =       out_indices if out_indices is not None else (-1,)


