





"""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    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:torch.FloatTensor






class    _lowerCAmelCase  (	a    ,  a			):
       """simple docstring"""




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



         '''simple docstring'''

         super().__init__()

         # pass init params to Encoder
         lowerCAmelCase__     :Optional[Any]											=				Encoder(
             in_channels=__UpperCAmelCase       ,					out_channels=__UpperCAmelCase       ,					down_block_types=__UpperCAmelCase       ,					block_out_channels=__UpperCAmelCase       ,					layers_per_block=__UpperCAmelCase       ,					act_fn=__UpperCAmelCase       ,					norm_num_groups=__UpperCAmelCase       ,					double_z=__UpperCAmelCase       ,					)

         lowerCAmelCase__     :Optional[int]											=				vq_embed_dim if vq_embed_dim is not None else latent_channels

         lowerCAmelCase__     :List[str]											=				nn.Convad(__UpperCAmelCase       ,					__UpperCAmelCase       ,					1 )
         lowerCAmelCase__     :List[str]											=				VectorQuantizer(__UpperCAmelCase       ,					__UpperCAmelCase       ,					beta=0.25       ,					remap=__UpperCAmelCase       ,					sane_index_shape=__UpperCAmelCase )
         lowerCAmelCase__     :Union[str, Any]											=				nn.Convad(__UpperCAmelCase       ,					__UpperCAmelCase       ,					1 )

         # pass init params to Decoder
         lowerCAmelCase__     :Tuple											=				Decoder(
             in_channels=__UpperCAmelCase       ,					out_channels=__UpperCAmelCase       ,					up_block_types=__UpperCAmelCase       ,					block_out_channels=__UpperCAmelCase       ,					layers_per_block=__UpperCAmelCase       ,					act_fn=__UpperCAmelCase       ,					norm_num_groups=__UpperCAmelCase       ,					norm_type=__UpperCAmelCase       ,					)






       @apply_forward_hook
       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = True ):



         '''simple docstring'''

         lowerCAmelCase__     :int											=				self.encoder(__UpperCAmelCase )
         lowerCAmelCase__     :List[Any]											=				self.quant_conv(__UpperCAmelCase )

         if not return_dict:
           return (h,)

         return VQEncoderOutput(latents=__UpperCAmelCase )






       @apply_forward_hook
       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = False       ,					__UpperCAmelCase = True ):



         '''simple docstring'''

         if not force_not_quantize:
           lowerCAmelCase__				,							lowerCAmelCase__				,							lowerCAmelCase__     :Union[str, Any]											=				self.quantize(__UpperCAmelCase )
         else:
           lowerCAmelCase__     :List[str]											=				h
         lowerCAmelCase__     :Dict											=				self.post_quant_conv(__UpperCAmelCase )
         lowerCAmelCase__     :Tuple											=				self.decoder(__UpperCAmelCase       ,					quant if self.config.norm_type == 'spatial' else None )

         if not return_dict:
           return (dec,)

         return DecoderOutput(sample=__UpperCAmelCase )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = True ):



         '''simple docstring'''

         lowerCAmelCase__     :int											=				sample
         lowerCAmelCase__     :Optional[int]											=				self.encode(__UpperCAmelCase ).latents
         lowerCAmelCase__     :Tuple											=				self.decode(__UpperCAmelCase ).sample

         if not return_dict:
           return (dec,)

         return DecoderOutput(sample=__UpperCAmelCase )




'''simple docstring'''


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


UpperCAmelCase_						:  List[Any]				  =						logging.get_logger(__name__)

UpperCAmelCase_						:  Any				  =						{
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}





class        lowercase__    (		_snake_case   ):





							'''simple docstring'''


							A_				: Dict       =    """gpt_bigcode"""
							A_				: str       =    ["""past_key_values"""]
							A_				: Tuple       =    {
							    """hidden_size""": """n_embd""",
							    """max_position_embeddings""": """n_positions""",
							    """num_attention_heads""": """n_head""",
							    """num_hidden_layers""": """n_layer""",
							}






							def __init__(       self       ,   __snake_case=5_0257       ,   __snake_case=1024       ,   __snake_case=768       ,   __snake_case=12       ,   __snake_case=12       ,   __snake_case=None       ,   __snake_case="gelu_pytorch_tanh"       ,   __snake_case=0.1       ,   __snake_case=0.1       ,   __snake_case=0.1       ,   __snake_case=1e-5       ,   __snake_case=0.02       ,   __snake_case=True       ,   __snake_case=True       ,   __snake_case=5_0256       ,   __snake_case=5_0256       ,   __snake_case=True       ,   __snake_case=True       ,   __snake_case=True       ,   **__snake_case       ,   ):
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= vocab_size
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= n_positions
											_SCREAMING_SNAKE_CASE					:			List[Any]							= n_embd
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= n_layer
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= n_head
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= n_inner
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= activation_function
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= resid_pdrop
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= embd_pdrop
											_SCREAMING_SNAKE_CASE					:			List[Any]							= attn_pdrop
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= layer_norm_epsilon
											_SCREAMING_SNAKE_CASE					:			Any							= initializer_range
											_SCREAMING_SNAKE_CASE					:			str							= scale_attn_weights
											_SCREAMING_SNAKE_CASE					:			Tuple							= use_cache
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= attention_softmax_in_fpaa
											_SCREAMING_SNAKE_CASE					:			List[Any]							= scale_attention_softmax_in_fpaa
											_SCREAMING_SNAKE_CASE					:			Any							= multi_query

											_SCREAMING_SNAKE_CASE					:			Optional[int]							= bos_token_id
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= eos_token_id

											super().__init__(bos_token_id=__snake_case       ,   eos_token_id=__snake_case       ,   **__snake_case    )




