





"""simple docstring"""
from ..utils import DummyObject, requires_backends







class       a							(   metaclass=a__  ):
 snake_case__             =       ['''flax''', '''transformers''']



 def __init__(     self				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(self				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )







class       a							(   metaclass=a__  ):
 snake_case__             =       ['''flax''', '''transformers''']



 def __init__(     self				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(self				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )







class       a							(   metaclass=a__  ):
 snake_case__             =       ['''flax''', '''transformers''']



 def __init__(     self				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(self				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )







class       a							(   metaclass=a__  ):
 snake_case__             =       ['''flax''', '''transformers''']



 def __init__(     self				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(self				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )



 @classmethod
 def    UpperCamelCase__  (     cls				,       *_snake_case				,       **_snake_case     ):







  """simple docstring"""






  requires_backends(cls				,       ['flax', 'transformers']     )












"""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       a							(   a__  ):
 snake_case__             =       42







class       a							(   a__   , a__  ):



 @register_to_config
 def __init__(     self				,       _snake_case = 3				,       _snake_case = 3				,       _snake_case = ("DownEncoderBlock2D",)				,       _snake_case = ("UpDecoderBlock2D",)				,       _snake_case = (64,)				,       _snake_case = 1				,       _snake_case = "silu"				,       _snake_case = 3				,       _snake_case = 32				,       _snake_case = 2_56				,       _snake_case = 32				,       _snake_case = None				,       _snake_case = 0.18_215				,       _snake_case = "group"				,       ):







  """simple docstring"""






  super().__init__()

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

  lowerCAmelCase    				= vq_embed_dim if vq_embed_dim is not None else latent_channels

  lowerCAmelCase    				= nn.Convad(_snake_case				,       _snake_case				,       1     )
  lowerCAmelCase    				= VectorQuantizer(_snake_case				,       _snake_case				,       beta=0.25				,       remap=_snake_case				,       sane_index_shape=_snake_case     )
  lowerCAmelCase    				= nn.Convad(_snake_case				,       _snake_case				,       1     )

  # pass init params to Decoder
  lowerCAmelCase    				= 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				,       _snake_case				,       _snake_case = True     ):







  """simple docstring"""






  lowerCAmelCase    				= self.encoder(_snake_case     )
  lowerCAmelCase    				= self.quant_conv(_snake_case     )

  if not return_dict:
   return (h,)

  return VQEncoderOutput(latents=_snake_case     )



 @apply_forward_hook
 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = False				,       _snake_case = True     ):







  """simple docstring"""






  if not force_not_quantize:
   lowerCAmelCase				,lowerCAmelCase				,lowerCAmelCase    				= self.quantize(_snake_case     )
  else:
   lowerCAmelCase    				= h
  lowerCAmelCase    				= self.post_quant_conv(_snake_case     )
  lowerCAmelCase    				= 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				,       _snake_case				,       _snake_case = True     ):







  """simple docstring"""






  lowerCAmelCase    				= sample
  lowerCAmelCase    				= self.encode(_snake_case     ).latents
  lowerCAmelCase    				= self.decode(_snake_case     ).sample

  if not return_dict:
   return (dec,)

  return DecoderOutput(sample=_snake_case     )





