

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_     ):



     '''simple docstring'''

     __snake_case					:			torch.FloatTensor

class 	UpperCamelCase__				(   lowerCAmelCase_							,   lowerCAmelCase_     ):



     '''simple docstring'''

     @register_to_config
     def __init__(							self		:					str		,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.18215		,lowerCamelCase__		:					str = "group"		,)  ->	Union[str, Any]:




           '''simple docstring'''


           super().__init__()

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

           SCREAMING_SNAKE_CASE	=		vq_embed_dim if vq_embed_dim is not None else latent_channels

           SCREAMING_SNAKE_CASE	=		nn.Convad(lowerCamelCase__		,lowerCamelCase__		,1 )
           SCREAMING_SNAKE_CASE	=		VectorQuantizer(lowerCamelCase__		,lowerCamelCase__		,beta=0.25		,remap=lowerCamelCase__		,sane_index_shape=lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		nn.Convad(lowerCamelCase__		,lowerCamelCase__		,1 )

           # pass init params to Decoder
           SCREAMING_SNAKE_CASE	=		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        SCREAMING_SNAKE_CASE__						(							self		:					Optional[Any]		,lowerCamelCase__		:					torch.FloatTensor		,lowerCamelCase__		:					bool = True )  ->	VQEncoderOutput:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.encoder(lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		self.quant_conv(lowerCamelCase__ )

           if not return_dict:
                 return (h,)

           return VQEncoderOutput(latents=lowerCamelCase__ )






     @apply_forward_hook
     def        SCREAMING_SNAKE_CASE__						(							self		:					List[Any]		,lowerCamelCase__		:					torch.FloatTensor		,lowerCamelCase__		:					bool = False		,lowerCamelCase__		:					bool = True )  ->	Union[DecoderOutput, torch.FloatTensor]:




           '''simple docstring'''


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

           if not return_dict:
                 return (dec,)

           return DecoderOutput(sample=lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Dict		,lowerCamelCase__		:					torch.FloatTensor		,lowerCamelCase__		:					bool = True )  ->	Union[DecoderOutput, torch.FloatTensor]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		sample
           SCREAMING_SNAKE_CASE	=		self.encode(lowerCamelCase__ ).latents
           SCREAMING_SNAKE_CASE	=		self.decode(lowerCamelCase__ ).sample

           if not return_dict:
                 return (dec,)

           return DecoderOutput(sample=lowerCamelCase__ )









from ..utils import DummyObject, requires_backends

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					Any )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					Any		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					List[Any] )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					Union[str, Any]		,**lowerCamelCase__		:					Optional[int] )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					Tuple		,*lowerCamelCase__		:					Dict		,**lowerCamelCase__		:					Any )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					Optional[int]		,*lowerCamelCase__		:					List[Any]		,**lowerCamelCase__		:					Optional[int] )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[str]				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					Union[str, Any]		,**lowerCamelCase__		:					Optional[Any] )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[str]				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					List[str]		,**lowerCamelCase__		:					str )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			int				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					List[Any]		,**lowerCamelCase__		:					Optional[Any] )  ->	int:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[Any]				=    ["sentencepiece"]






     def __init__(							self		:					List[str]		,*lowerCamelCase__		:					List[str]		,**lowerCamelCase__		:					int )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					str		,*lowerCamelCase__		:					Union[str, Any]		,**lowerCamelCase__		:					List[str] )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Any				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					Dict		,**lowerCamelCase__		:					List[Any] )  ->	List[str]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Any				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					Optional[int] )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					int		,**lowerCamelCase__		:					Optional[int] )  ->	Optional[Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[Any]				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					int )  ->	Any:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					Dict )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[Any]				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					Optional[Any] )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			int				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					str )  ->	List[Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					Dict )  ->	List[Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			int				=    ["sentencepiece"]






     def __init__(							self		:					List[Any]		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					Any )  ->	int:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					str )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					int		,**lowerCamelCase__		:					Any )  ->	List[str]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Any				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					str )  ->	int:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[str]				=    ["sentencepiece"]






     def __init__(							self		:					Optional[int]		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					Union[str, Any] )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					List[Any] )  ->	Any:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Optional[Any]				=    ["sentencepiece"]






     def __init__(							self		:					List[str]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					str )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Optional[int]				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					str )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    ["sentencepiece"]






     def __init__(							self		:					Any		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					Any )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					List[str]		,**lowerCamelCase__		:					List[Any] )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					str )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					List[Any]		,**lowerCamelCase__		:					Optional[int] )  ->	List[str]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					List[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					Dict )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )


