






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


__UpperCamelCase   :   Tuple      =    logging.get_logger(__name__)

__UpperCamelCase   :   List[Any]      =    {
    """EleutherAI/gpt-neox-20b""": """https://huggingface.co/EleutherAI/gpt-neox-20b/resolve/main/config.json""",
    # See all GPTNeoX models at https://huggingface.co/models?filter=gpt_neox
}


class 							__UpperCamelCase     (  _lowerCAmelCase ):
	__snake_case						:Dict =							'gpt_neox'







	def __init__(	self   :				Optional[int]							,					_lowerCAmelCase   :				str=5_0432							,					_lowerCAmelCase   :				Optional[Any]=6144							,					_lowerCAmelCase   :				List[Any]=44							,					_lowerCAmelCase   :				Union[str, Any]=64							,					_lowerCAmelCase   :				List[str]=2_4576							,					_lowerCAmelCase   :				List[Any]="gelu"							,					_lowerCAmelCase   :				str=0.25							,					_lowerCAmelCase   :				List[Any]=1_0000							,					_lowerCAmelCase   :				str=0.0							,					_lowerCAmelCase   :				Any=0.0							,					_lowerCAmelCase   :				int=0.1							,					_lowerCAmelCase   :				List[str]=2048							,					_lowerCAmelCase   :				Union[str, Any]=0.02							,					_lowerCAmelCase   :				List[str]=1e-5							,					_lowerCAmelCase   :				List[Any]=True							,					_lowerCAmelCase   :				List[str]=0							,					_lowerCAmelCase   :				Dict=2							,					_lowerCAmelCase   :				List[str]=False							,					_lowerCAmelCase   :				List[Any]=True							,					_lowerCAmelCase   :				Dict=None							,					**_lowerCAmelCase   :				str							,					)		->			Optional[Any]:
		"""simple docstring"""







		super().__init__(bos_token_id=_lowerCAmelCase							,					eos_token_id=_lowerCAmelCase							,					**_lowerCAmelCase      )
		__lowercase   							=	vocab_size
		__lowercase   							=	max_position_embeddings
		__lowercase   							=	hidden_size
		__lowercase   							=	num_hidden_layers
		__lowercase   							=	num_attention_heads
		__lowercase   							=	intermediate_size
		__lowercase   							=	hidden_act
		__lowercase   							=	rotary_pct
		__lowercase   							=	rotary_emb_base
		__lowercase   							=	attention_dropout
		__lowercase   							=	hidden_dropout
		__lowercase   							=	classifier_dropout
		__lowercase   							=	initializer_range
		__lowercase   							=	layer_norm_eps
		__lowercase   							=	use_cache
		__lowercase   							=	tie_word_embeddings
		__lowercase   							=	use_parallel_residual
		__lowercase   							=	rope_scaling
		self._rope_scaling_validation()

		if self.hidden_size % self.num_attention_heads != 0:
			raise ValueError(
			    """The hidden size is not divisble by the number of attention heads! Make sure to update them!"""      )







	def 			_a (	self   :				Any      )		->			int:
		"""simple docstring"""







		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}'      )
		__lowercase   							=	self.rope_scaling.get("""type"""							,					_lowerCAmelCase      )
		__lowercase   							=	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"""




from manim import *






class       UpperCAmelCase_    (							_UpperCamelCase		):



      def 		snake_case_   (	self	:      Tuple		):
           _UpperCAmelCase     :      str														=       Rectangle(height=0.5	,      width=0.5		)
           _UpperCAmelCase     :      List[Any]														=       Rectangle(height=0.25	,      width=0.25		)
           _UpperCAmelCase     :      Tuple														=       Rectangle(height=0.46	,      width=0.46		).set_stroke(width=0		)

           _UpperCAmelCase     :      List[Any]														=       [mem.copy() for i in range(6		)]
           _UpperCAmelCase     :      List[str]														=       [mem.copy() for i in range(6		)]
           _UpperCAmelCase     :      int														=       VGroup(*A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      Dict														=       VGroup(*A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      int														=       VGroup(A	,      A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      str														=       Text("CPU"	,      font_size=2_4		)
           _UpperCAmelCase     :      Union[str, Any]														=       Group(A	,      A		).arrange(A	,      buff=0.5	,      aligned_edge=A		)
           cpu.move_to([-2.5, -0.5, 0]		)
           self.add(A		)

           _UpperCAmelCase     :      Union[str, Any]														=       [mem.copy() for i in range(4		)]
           _UpperCAmelCase     :      Optional[int]														=       VGroup(*A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      Any														=       Text("GPU"	,      font_size=2_4		)
           _UpperCAmelCase     :      Dict														=       Group(A	,      A		).arrange(A	,      buff=0.5	,      aligned_edge=A		)
           gpu.move_to([-1, -1, 0]		)
           self.add(A		)

           _UpperCAmelCase     :      Tuple														=       [mem.copy() for i in range(6		)]
           _UpperCAmelCase     :      str														=       VGroup(*A		).arrange(A	,      buff=0		)

           _UpperCAmelCase     :      Any														=       Text("Model"	,      font_size=2_4		)
           _UpperCAmelCase     :      Any														=       Group(A	,      A		).arrange(A	,      buff=0.5	,      aligned_edge=A		)
           model.move_to([3, -1.0, 0]		)
           self.add(A		)

           _UpperCAmelCase     :      List[str]														=       []
           _UpperCAmelCase     :      Optional[int]														=       []
           _UpperCAmelCase     :      str														=       []

           for i, rect in enumerate(A		):
                rect.set_stroke(A		)

                _UpperCAmelCase     :      Dict														=       Rectangle(height=0.46 / 4	,      width=0.46 / 3		).set_stroke(width=0.0		).set_fill(A	,      opacity=0.7		)

                if i == 0:
                     cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT		)	,      buff=0.02	,      direction=A		)
                     cpu_target.set_x(cpu_target.get_x() + 0.1		)
                elif i == 3:
                     cpu_target.next_to(model_cpu_arr[0]	,      direction=A	,      buff=0.0		)
                else:
                     cpu_target.next_to(model_cpu_arr[i - 1]	,      direction=A	,      buff=0.0		)
                self.add(A		)
                model_cpu_arr.append(A		)

           self.add(*A	,      *A	,      *A		)

           _UpperCAmelCase     :      Dict														=       [mem.copy() for i in range(6		)]
           _UpperCAmelCase     :      List[str]														=       VGroup(*A		).arrange(A	,      buff=0		)

           _UpperCAmelCase     :      List[str]														=       Text("Loaded Checkpoint"	,      font_size=2_4		)
           _UpperCAmelCase     :      Optional[int]														=       Group(A	,      A		).arrange(A	,      buff=0.5	,      aligned_edge=A		)
           checkpoint.move_to([3, 0.5, 0]		)

           self.add(A		)

           _UpperCAmelCase     :      Union[str, Any]														=       []
           _UpperCAmelCase     :      Union[str, Any]														=       []

           for i, rect in enumerate(A		):
                _UpperCAmelCase     :      str														=       fill.copy().set_fill(A	,      opacity=0.7		)
                target.move_to(A		)
                ckpt_arr.append(A		)

                _UpperCAmelCase     :      Dict														=       target.copy()
                if i < 5:
                     cpu_target.move_to(cpu_left_col_base[i + 1]		)
                else:
                     cpu_target.move_to(cpu_right_col_base[i - 5]		)
                ckpt_cpu_arr.append(A		)
           self.add(*A	,      *A		)

           _UpperCAmelCase     :      List[str]														=       Square(side_length=2.2		)
           key.move_to([-5, 2, 0]		)

           _UpperCAmelCase     :      List[Any]														=       MarkupText(
               f'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'	,      font_size=1_8	,      )

           key_text.move_to([-5, 2.4, 0]		)

           self.add(A	,      A		)

           _UpperCAmelCase     :      Tuple														=       MarkupText(
               f'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'	,      font_size=1_8	,      )

           blue_text.next_to(A	,      DOWN * 2.4	,      aligned_edge=key_text.get_left()		)
           self.add(A		)

           _UpperCAmelCase     :      Any														=       MarkupText(
               f'Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device.'	,      font_size=2_4	,      )
           step_a.move_to([2, 2, 0]		)

           _UpperCAmelCase     :      int														=       [meta_mem.copy() for i in range(6		)]
           _UpperCAmelCase     :      Optional[int]														=       [meta_mem.copy() for i in range(6		)]
           _UpperCAmelCase     :      List[str]														=       VGroup(*A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      Optional[int]														=       VGroup(*A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      List[Any]														=       VGroup(A	,      A		).arrange(A	,      buff=0		)
           _UpperCAmelCase     :      Union[str, Any]														=       Text("Disk"	,      font_size=2_4		)
           _UpperCAmelCase     :      int														=       Group(A	,      A		).arrange(A	,      buff=0.5	,      aligned_edge=A		)
           disk.move_to([-4.0, -1.25, 0]		)
           self.play(Write(A	,      run_time=3		)	,      Write(A	,      run_time=1		)	,      Create(A	,      run_time=1		)		)

           _UpperCAmelCase     :      List[Any]														=       []
           for i, rect in enumerate(A		):
                _UpperCAmelCase     :      Any														=       rect.copy()
                target.generate_target()
                target.target.move_to(disk_left_col_base[i]		).scale(0.5		)
                animations.append(MoveToTarget(A	,      run_time=1.5		)		)
           self.play(*A		)

           self.play(FadeOut(A		)		)

           _UpperCAmelCase     :      int														=       MarkupText(f'Then, the checkpoint is removed from memory\nthrough garbage collection.'	,      font_size=2_4		)
           step_a.move_to([2, 2, 0]		)

           self.play(Write(A	,      run_time=3		)		)

           self.play(
               FadeOut(A	,      A	,      *A	,      *A		)	,      )

           self.wait()
