






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 					SCREAMING_SNAKE_CASE_  (       _a ):
       """simple docstring"""


       __lowerCAmelCase    :		torch.FloatTensor






class 					SCREAMING_SNAKE_CASE_  (       _a  ,						_a ):
       """simple docstring"""


       @register_to_config
       def __init__(				self	:Tuple,      snake_case	:int = 3,      snake_case	:int = 3,      snake_case	:Tuple[str] = ("DownEncoderBlock2D",),      snake_case	:Tuple[str] = ("UpDecoderBlock2D",),      snake_case	:Tuple[int] = (64,),      snake_case	:int = 1,      snake_case	:str = "silu",      snake_case	:int = 3,      snake_case	:int = 32,      snake_case	:int = 256,      snake_case	:int = 32,      snake_case	:Optional[int] = None,      snake_case	:float = 0.1_8_2_1_5,      snake_case	:str = "group",      ):



          """simple docstring"""

          super().__init__()

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

          _lowercase              =vq_embed_dim if vq_embed_dim is not None else latent_channels

          _lowercase              =nn.Convad(snake_case,      snake_case,      1)
          _lowercase              =VectorQuantizer(snake_case,      snake_case,      beta=0.2_5,      remap=snake_case,      sane_index_shape=snake_case)
          _lowercase              =nn.Convad(snake_case,      snake_case,      1)

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





       @apply_forward_hook
       def 				UpperCamelCase__						(				self	:Optional[int],      snake_case	:torch.FloatTensor,      snake_case	:bool = True):



          """simple docstring"""

          _lowercase              =self.encoder(snake_case)
          _lowercase              =self.quant_conv(snake_case)

          if not return_dict:
             return (h,)

          return VQEncoderOutput(latents=snake_case)





       @apply_forward_hook
       def 				UpperCamelCase__						(				self	:Optional[Any],      snake_case	:torch.FloatTensor,      snake_case	:bool = False,      snake_case	:bool = True):



          """simple docstring"""

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

          if not return_dict:
             return (dec,)

          return DecoderOutput(sample=snake_case)





       def 				UpperCamelCase__						(				self	:Optional[int],      snake_case	:torch.FloatTensor,      snake_case	:bool = True):



          """simple docstring"""

          _lowercase              =sample
          _lowercase              =self.encode(snake_case).latents
          _lowercase              =self.decode(snake_case).sample

          if not return_dict:
             return (dec,)

          return DecoderOutput(sample=snake_case)










from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available






@dataclass
class 					SCREAMING_SNAKE_CASE_  (       _a ):
       """simple docstring"""


       __lowerCAmelCase    :		Union[List[PIL.Image.Image], np.ndarray]
       __lowerCAmelCase    :		Optional[List[bool]]


if is_transformers_available() and is_torch_available():
    from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline


