






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     _lowerCAmelCase(	UpperCAmelCase_ ):





       """simple docstring"""







       a    :		torch.FloatTensor







class     _lowerCAmelCase(	UpperCAmelCase_							,     UpperCAmelCase_ ):





       """simple docstring"""







       @register_to_config
       def __init__( self  ,      _lowerCamelCase = 3  ,      _lowerCamelCase = 3  ,      _lowerCamelCase = ("DownEncoderBlock2D",)  ,      _lowerCamelCase = ("UpDecoderBlock2D",)  ,      _lowerCamelCase = (6_4,)  ,      _lowerCamelCase = 1  ,      _lowerCamelCase = "silu"  ,      _lowerCamelCase = 3  ,      _lowerCamelCase = 3_2  ,      _lowerCamelCase = 2_5_6  ,      _lowerCamelCase = 3_2  ,      _lowerCamelCase = None  ,      _lowerCamelCase = 0.1_8_2_1_5  ,      _lowerCamelCase = "group"  ,      ):
         super().__init__()

         # pass init params to Encoder
         UpperCamelCase_: int   				=    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  ,      )

         UpperCamelCase_: Any   				=    vq_embed_dim if vq_embed_dim is not None else latent_channels

         UpperCamelCase_: List[str]   				=    nn.Convad(_lowerCamelCase  ,      _lowerCamelCase  ,      1							)
         UpperCamelCase_: Union[str, Any]   				=    VectorQuantizer(_lowerCamelCase  ,      _lowerCamelCase  ,      beta=0.2_5  ,      remap=_lowerCamelCase  ,      sane_index_shape=_lowerCamelCase							)
         UpperCamelCase_: List[Any]   				=    nn.Convad(_lowerCamelCase  ,      _lowerCamelCase  ,      1							)

         # pass init params to Decoder
         UpperCamelCase_: str   				=    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  ,      _lowerCamelCase  ,      _lowerCamelCase = True							):
         UpperCamelCase_: int   				=    self.encoder(_lowerCamelCase							)
         UpperCamelCase_: Tuple   				=    self.quant_conv(_lowerCamelCase							)

         if not return_dict:
           return (h,)

         return VQEncoderOutput(latents=_lowerCamelCase							)





       @apply_forward_hook
       def       _a   ( self  ,      _lowerCamelCase  ,      _lowerCamelCase = False  ,      _lowerCamelCase = True							):
         # also go through quantization layer
         if not force_not_quantize:
           UpperCamelCase_: Optional[int]   				=    self.quantize(_lowerCamelCase							)
         else:
           UpperCamelCase_: str   				=    h
         UpperCamelCase_: List[str]   				=    self.post_quant_conv(_lowerCamelCase							)
         UpperCamelCase_: Tuple   				=    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  ,      _lowerCamelCase  ,      _lowerCamelCase = True							):
         UpperCamelCase_: int   				=    sample
         UpperCamelCase_: int   				=    self.encode(_lowerCamelCase							).latents
         UpperCamelCase_: Dict   				=    self.decode(_lowerCamelCase							).sample

         if not return_dict:
           return (dec,)

         return DecoderOutput(sample=_lowerCamelCase							)







import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
A_		:		List[str]		     =			'.'


if __name__ == "__main__":
   A_		:		Dict		     =			os.path.join(REPO_PATH, 'utils/documentation_tests.txt')
   A_		:		Dict		     =			[]
   A_		:		Optional[Any]		     =			[]
   with open(doctest_file_path) as fp:
      for line in fp:
         A_		:		Tuple		     =			line.strip()
         A_		:		Any		     =			os.path.join(REPO_PATH, line)
         if not (os.path.isfile(path) or os.path.isdir(path)):
            non_existent_paths.append(line)
         all_paths.append(path)
   if len(non_existent_paths) > 0:
      A_		:		str		     =			'\n'.join(non_existent_paths)
      raise ValueError(F'''`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}''')
   if all_paths != sorted(all_paths):
      raise ValueError('Files in `utils/documentation_tests.txt` are not in alphabetical order.')