


'''simple docstring'''

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


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

_UpperCAmelCase :       Union[str, Any]										= {
    """s-JoL/Open-Llama-V1""": """https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json""",
}


class 					a__ (       __A					):







				"""simple docstring"""



				__UpperCamelCase			:						Union[str, Any]		=		'open-llama'




				def __init__(self				,	__lowercase=10_00_00				,	__lowercase=40_96				,	__lowercase=1_10_08				,	__lowercase=32				,	__lowercase=32				,	__lowercase="silu"				,	__lowercase=20_48				,	__lowercase=0.0_2				,	__lowercase=1e-6				,	__lowercase=True				,	__lowercase=0				,	__lowercase=1				,	__lowercase=2				,	__lowercase=False				,	__lowercase=True				,	__lowercase=0.1				,	__lowercase=0.1				,	__lowercase=True				,	__lowercase=True				,	__lowercase=None				,	**__lowercase				,	):
										__lowerCAmelCase											= vocab_size
										__lowerCAmelCase											= max_position_embeddings
										__lowerCAmelCase											= hidden_size
										__lowerCAmelCase											= intermediate_size
										__lowerCAmelCase											= num_hidden_layers
										__lowerCAmelCase											= num_attention_heads
										__lowerCAmelCase											= hidden_act
										__lowerCAmelCase											= initializer_range
										__lowerCAmelCase											= rms_norm_eps
										__lowerCAmelCase											= use_cache
										__lowerCAmelCase											= kwargs.pop(
										    '''use_memorry_efficient_attention'''				,	__lowerCAmelCase						)
										__lowerCAmelCase											= hidden_dropout_prob
										__lowerCAmelCase											= attention_dropout_prob
										__lowerCAmelCase											= use_stable_embedding
										__lowerCAmelCase											= shared_input_output_embedding
										__lowerCAmelCase											= rope_scaling
										self._rope_scaling_validation()

										super().__init__(
										    pad_token_id=__lowerCAmelCase				,	bos_token_id=__lowerCAmelCase				,	eos_token_id=__lowerCAmelCase				,	tie_word_embeddings=__lowerCAmelCase				,	**__lowerCAmelCase				,	)




				def     _snake_case     (self						):



										if self.rope_scaling is None:
																return

										if not isinstance(self.rope_scaling				,	__lowerCAmelCase						) or len(self.rope_scaling						) != 2:
																raise ValueError(
																    '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
																    F"""got {self.rope_scaling}"""						)
										__lowerCAmelCase											= self.rope_scaling.get('''type'''				,	__lowerCAmelCase						)
										__lowerCAmelCase											= self.rope_scaling.get('''factor'''				,	__lowerCAmelCase						)
										if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
																raise ValueError(
																    F"""`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}"""						)
										if rope_scaling_factor is None or not isinstance(__lowerCAmelCase				,	__lowerCAmelCase						) or rope_scaling_factor <= 1.0:
																raise ValueError(F"""`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}"""						)


"""simple docstring"""






import math
from typing import List, Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from .scheduling_utils import SchedulerMixin, SchedulerOutput





class  _A						(       lowerCAmelCase  ,    lowerCAmelCase	):
      snake_case__			:   Tuple							  =	1

      @register_to_config
      def __init__(						self		,       __lowerCAmelCase = 1000		,       __lowerCAmelCase = None						):







            """simple docstring"""



            self.set_timesteps(__lowerCAmelCase						)

            # standard deviation of the initial noise distribution
            lowercase														=	1.0

            # For now we only support F-PNDM, i.e. the runge-kutta method
            # For more information on the algorithm please take a look at the paper: https://arxiv.org/pdf/2202.09778.pdf
            # mainly at formula (9), (12), (13) and the Algorithm 2.
            lowercase														=	4

            # running values
            lowercase														=	[]

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase = None						):







            """simple docstring"""



            lowercase														=	num_inference_steps
            lowercase														=	torch.linspace(1		,       0		,       num_inference_steps + 1						)[:-1]
            lowercase														=	torch.cat([steps, torch.tensor([0.0]						)]						)

            if self.config.trained_betas is not None:
                  lowercase														=	torch.tensor(self.config.trained_betas		,       dtype=torch.floataa						)
            else:
                  lowercase														=	torch.sin(steps * math.pi / 2						) ** 2

            lowercase														=	(1.0 - self.betas**2) ** 0.5

            lowercase														=	(torch.atana(self.betas		,       self.alphas						) / math.pi * 2)[:-1]
            lowercase														=	timesteps.to(__lowerCAmelCase						)

            lowercase														=	[]

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase = True		,       ):







            """simple docstring"""



            if self.num_inference_steps is None:
                  raise ValueError(
                      """Number of inference steps is 'None', you need to run 'set_timesteps' after creating the scheduler"""						)

            lowercase														=	(self.timesteps == timestep).nonzero().item()
            lowercase														=	timestep_index + 1

            lowercase														=	sample * self.betas[timestep_index] + model_output * self.alphas[timestep_index]
            self.ets.append(__lowerCAmelCase						)

            if len(self.ets						) == 1:
                  lowercase														=	self.ets[-1]
            elif len(self.ets						) == 2:
                  lowercase														=	(3 * self.ets[-1] - self.ets[-2]) / 2
            elif len(self.ets						) == 3:
                  lowercase														=	(23 * self.ets[-1] - 16 * self.ets[-2] + 5 * self.ets[-3]) / 12
            else:
                  lowercase														=	(1 / 24) * (55 * self.ets[-1] - 59 * self.ets[-2] + 37 * self.ets[-3] - 9 * self.ets[-4])

            lowercase														=	self._get_prev_sample(__lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						)

            if not return_dict:
                  return (prev_sample,)

            return SchedulerOutput(prev_sample=__lowerCAmelCase						)

      def 				A__       (						self		,       __lowerCAmelCase		,       *__lowerCAmelCase		,       **__lowerCAmelCase						):







            """simple docstring"""



            return sample

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







            """simple docstring"""



            lowercase														=	self.alphas[timestep_index]
            lowercase														=	self.betas[timestep_index]

            lowercase														=	self.alphas[prev_timestep_index]
            lowercase														=	self.betas[prev_timestep_index]

            lowercase														=	(sample - sigma * ets) / max(__lowerCAmelCase		,       1E-8						)
            lowercase														=	next_alpha * pred + ets * next_sigma

            return prev_sample







      def __len__(						self						):







            """simple docstring"""



            return self.config.num_train_timesteps



