

'''simple docstring'''



from dataclasses import dataclass
from typing import Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, randn_tensor
from .scheduling_utils import SchedulerMixin



@dataclass
class lowerCamelCase			(  lowercase_						):



			'''simple docstring'''






			__snake_case        =	42
			__snake_case        =	42
			__snake_case        =	None



class lowerCamelCase			(  lowercase_	,						lowercase_						):



			'''simple docstring'''






			__snake_case        =	2


			@register_to_config
			def __init__(				self	:						Optional[int]		,      lowerCAmelCase_	:						float = 0.02		,      lowerCAmelCase_	:						float = 1_00		,      lowerCAmelCase_	:						float = 1.007		,      lowerCAmelCase_	:						float = 80		,      lowerCAmelCase_	:						float = 0.05		,      lowerCAmelCase_	:						float = 50		,      )      ->		List[Any]:





									'''simple docstring'''
									# standard deviation of the initial noise distribution
									A__					:       List[Any]     =sigma_max

									# setable values
									A__					:       int     =None
									A__					:       np.IntTensor     =None
									A__					:       torch.FloatTensor     =None  # sigma(t_i)


			def lowercase__						(				self	:						int		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						Optional[int] = None			)      ->		torch.FloatTensor:





									'''simple docstring'''
									return sample


			def lowercase__						(				self	:						Tuple		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						Union[str, torch.device] = None			)      ->		Any:





									'''simple docstring'''
									A__					:       Any     =num_inference_steps
									A__					:       List[str]     =np.arange(0		,      self.num_inference_steps			)[::-1].copy()
									A__					:       Optional[int]     =torch.from_numpy(lowerCAmelCase_			).to(lowerCAmelCase_			)
									A__					:       Tuple     =[
									    (
									        self.config.sigma_max**2
									        * (self.config.sigma_min**2 / self.config.sigma_max**2) ** (i / (num_inference_steps - 1))
									    )
									    for i in self.timesteps
									]
									A__					:       Any     =torch.tensor(lowerCAmelCase_		,      dtype=torch.floataa		,      device=lowerCAmelCase_			)


			def lowercase__						(				self	:						int		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						float		,      lowerCAmelCase_	:						Optional[torch.Generator] = None			)      ->		Tuple[torch.FloatTensor, float]:





									'''simple docstring'''
									if self.config.s_min <= sigma <= self.config.s_max:
															A__					:       Dict     =min(self.config.s_churn / self.num_inference_steps		,      2**0.5 - 1			)
									else:
															A__					:       List[Any]     =0

									# sample eps ~ N(0, S_noise^2 * I)
									A__					:       List[Any]     =self.config.s_noise * randn_tensor(sample.shape		,      generator=lowerCAmelCase_			).to(sample.device			)
									A__					:       List[str]     =sigma + gamma * sigma
									A__					:       Tuple     =sample + ((sigma_hat**2 - sigma**2) ** 0.5 * eps)

									return sample_hat, sigma_hat


			def lowercase__						(				self	:						Union[str, Any]		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						float		,      lowerCAmelCase_	:						float		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						bool = True		,      )      ->		Union[KarrasVeOutput, Tuple]:





									'''simple docstring'''
									A__					:       List[Any]     =sample_hat + sigma_hat * model_output
									A__					:       Tuple     =(sample_hat - pred_original_sample) / sigma_hat
									A__					:       Optional[int]     =sample_hat + (sigma_prev - sigma_hat) * derivative

									if not return_dict:
															return (sample_prev, derivative)

									return KarrasVeOutput(
									    prev_sample=lowerCAmelCase_		,      derivative=lowerCAmelCase_		,      pred_original_sample=lowerCAmelCase_			)


			def lowercase__						(				self	:						Tuple		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						float		,      lowerCAmelCase_	:						float		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						torch.FloatTensor		,      lowerCAmelCase_	:						bool = True		,      )      ->		Union[KarrasVeOutput, Tuple]:





									'''simple docstring'''
									A__					:       List[Any]     =sample_prev + sigma_prev * model_output
									A__					:       Any     =(sample_prev - pred_original_sample) / sigma_prev
									A__					:       List[Any]     =sample_hat + (sigma_prev - sigma_hat) * (0.5 * derivative + 0.5 * derivative_corr)

									if not return_dict:
															return (sample_prev, derivative)

									return KarrasVeOutput(
									    prev_sample=lowerCAmelCase_		,      derivative=lowerCAmelCase_		,      pred_original_sample=lowerCAmelCase_			)



			def lowercase__						(				self	:						Tuple		,      lowerCAmelCase_	:						Any		,      lowerCAmelCase_	:						int		,      lowerCAmelCase_	:						List[str]			)      ->		int:





									'''simple docstring'''
									raise NotImplementedError()




'''simple docstring'''



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


__snake_case			:     Union[str, Any]										=      logging.get_logger(__name__)

__snake_case			:     Optional[int]										=      {
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}



class lowerCamelCase			(  lowercase_						):



			'''simple docstring'''






			__snake_case        =	'gpt_bigcode'
			__snake_case        =	['past_key_values']
			__snake_case        =	{
			    'hidden_size': 'n_embd',
			    'max_position_embeddings': 'n_positions',
			    'num_attention_heads': 'n_head',
			    'num_hidden_layers': 'n_layer',
			}


			def __init__(				self	:						Optional[Any]		,      lowerCAmelCase_	:						List[str]=5_02_57		,      lowerCAmelCase_	:						str=10_24		,      lowerCAmelCase_	:						str=7_68		,      lowerCAmelCase_	:						str=12		,      lowerCAmelCase_	:						int=12		,      lowerCAmelCase_	:						Dict=None		,      lowerCAmelCase_	:						List[Any]="gelu_pytorch_tanh"		,      lowerCAmelCase_	:						Union[str, Any]=0.1		,      lowerCAmelCase_	:						Optional[Any]=0.1		,      lowerCAmelCase_	:						Optional[int]=0.1		,      lowerCAmelCase_	:						Dict=1e-5		,      lowerCAmelCase_	:						str=0.02		,      lowerCAmelCase_	:						List[Any]=True		,      lowerCAmelCase_	:						str=True		,      lowerCAmelCase_	:						str=5_02_56		,      lowerCAmelCase_	:						Dict=5_02_56		,      lowerCAmelCase_	:						Union[str, Any]=True		,      lowerCAmelCase_	:						str=True		,      lowerCAmelCase_	:						Optional[Any]=True		,      **lowerCAmelCase_	:						Optional[Any]		,      )      ->		Tuple:





									'''simple docstring'''
									A__					:       Optional[Any]     =vocab_size
									A__					:       Optional[Any]     =n_positions
									A__					:       List[str]     =n_embd
									A__					:       str     =n_layer
									A__					:       Optional[int]     =n_head
									A__					:       Optional[int]     =n_inner
									A__					:       int     =activation_function
									A__					:       int     =resid_pdrop
									A__					:       int     =embd_pdrop
									A__					:       Dict     =attn_pdrop
									A__					:       Any     =layer_norm_epsilon
									A__					:       List[Any]     =initializer_range
									A__					:       Dict     =scale_attn_weights
									A__					:       Any     =use_cache
									A__					:       List[Any]     =attention_softmax_in_fpaa
									A__					:       Optional[int]     =scale_attention_softmax_in_fpaa
									A__					:       Dict     =multi_query

									A__					:       List[str]     =bos_token_id
									A__					:       Any     =eos_token_id

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

