


from manim import *
class  SCREAMING_SNAKE_CASE__  (				lowercase__			):
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Optional[int]:
             a_					:		Optional[int]							=  Rectangle(height=0.5     ,							width=0.5     )
             a_					:		List[Any]							=  Rectangle(height=0.25     ,							width=0.25     )
             a_					:		Optional[Any]							=  Rectangle(height=0.46     ,							width=0.46     ).set_stroke(width=0     )

             a_					:		str							=  [mem.copy() for i in range(6     )]
             a_					:		Tuple							=  [mem.copy() for i in range(6     )]
             a_					:		Any							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )
             a_					:		int							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )
             a_					:		Optional[Any]							=  VGroup(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )
             a_					:		Optional[Any]							=  Text('CPU'     ,							font_size=2_4     )
             a_					:		Any							=  Group(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0.5     ,							aligned_edge=SCREAMING_SNAKE_CASE__     )
             cpu.move_to([-2.5, -0.5, 0]     )
             self.add(SCREAMING_SNAKE_CASE__     )

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

             a_					:		Optional[Any]							=  [mem.copy() for i in range(6     )]
             a_					:		List[Any]							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )

             a_					:		List[str]							=  Text('Model'     ,							font_size=2_4     )
             a_					:		int							=  Group(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0.5     ,							aligned_edge=SCREAMING_SNAKE_CASE__     )
             model.move_to([3, -1.0, 0]     )
             self.add(SCREAMING_SNAKE_CASE__     )

             a_					:		Dict							=  []
             a_					:		str							=  []
             a_					:		int							=  []

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

                    a_					:		int							=  Rectangle(height=0.46 / 4     ,							width=0.46 / 3     ).set_stroke(width=0.0     ).set_fill(SCREAMING_SNAKE_CASE__     ,							opacity=0.7     )

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

             self.add(*SCREAMING_SNAKE_CASE__     ,							*SCREAMING_SNAKE_CASE__     ,							*SCREAMING_SNAKE_CASE__     )

             a_					:		Tuple							=  [mem.copy() for i in range(6     )]
             a_					:		Union[str, Any]							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )

             a_					:		Dict							=  Text('Loaded Checkpoint'     ,							font_size=2_4     )
             a_					:		str							=  Group(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0.5     ,							aligned_edge=SCREAMING_SNAKE_CASE__     )
             checkpoint.move_to([3, 0.5, 0]     )

             self.add(SCREAMING_SNAKE_CASE__     )

             a_					:		Dict							=  []
             a_					:		Optional[int]							=  []

             for i, rect in enumerate(SCREAMING_SNAKE_CASE__     ):
                    a_					:		Union[str, Any]							=  fill.copy().set_fill(SCREAMING_SNAKE_CASE__     ,							opacity=0.7     )
                    target.move_to(SCREAMING_SNAKE_CASE__     )
                    ckpt_arr.append(SCREAMING_SNAKE_CASE__     )

                    a_					:		List[str]							=  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(SCREAMING_SNAKE_CASE__     )
             self.add(*SCREAMING_SNAKE_CASE__     ,							*SCREAMING_SNAKE_CASE__     )

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

             a_					:		Optional[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(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )

             a_					:		Optional[int]							=  MarkupText(
                 F"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""     ,							font_size=1_8     ,							)

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

             a_					:		str							=  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]     )

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

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

             self.play(FadeOut(SCREAMING_SNAKE_CASE__     )     )

             a_					:		Optional[Any]							=  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(SCREAMING_SNAKE_CASE__     ,							run_time=3     )     )

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

             self.wait()






import math

import flax.linen as nn
import jax.numpy as jnp







def        SCREAMING_SNAKE_CASE_						(			__A :			jnp.ndarray  ,    __A :			int  ,    __A :			float = 1  ,    __A :			float = 1  ,    __A :			float = 1.0e4  ,    __A :			bool = False  ,    __A :			float = 1.0  ,    )	->		jnp.ndarray:

       """simple docstring"""

       assert timesteps.ndim == 1, "Timesteps should be a 1d-array"
       assert embedding_dim % 2 == 0, F"""Embedding dimension {embedding_dim} should be even"""
       a_					:		int							=  float(embedding_dim // 2				)
       a_					:		str							=  math.log(max_timescale / min_timescale				) / (num_timescales - freq_shift)
       a_					:		Optional[int]							=  min_timescale * jnp.exp(jnp.arange(__A  ,    dtype=jnp.floataa				) * -log_timescale_increment				)
       a_					:		Optional[int]							=  jnp.expand_dims(__A  ,    1				) * jnp.expand_dims(__A  ,    0				)

       # scale embeddings
       a_					:		str							=  scale * emb

       if flip_sin_to_cos:
              a_					:		str							=  jnp.concatenate([jnp.cos(__A				), jnp.sin(__A				)]  ,    axis=1				)
       else:
              a_					:		Any							=  jnp.concatenate([jnp.sin(__A				), jnp.cos(__A				)]  ,    axis=1				)
       a_					:		Optional[int]							=  jnp.reshape(__A  ,    [jnp.shape(__A				)[0], embedding_dim]				)
       return signal
class  SCREAMING_SNAKE_CASE__  (				nn.Module			):
      snake_case__				:     int        =						32
      snake_case__				:     jnp.dtype        =						jnp.floataa
      @nn.compact
      def __call__(       self				:       Tuple     ,							SCREAMING_SNAKE_CASE__				:       str     )		->			List[str]:
             a_					:		Optional[Any]							=  nn.Dense(self.time_embed_dim     ,							dtype=self.dtype     ,							name='linear_1'     )(SCREAMING_SNAKE_CASE__     )
             a_					:		Tuple							=  nn.silu(SCREAMING_SNAKE_CASE__     )
             a_					:		str							=  nn.Dense(self.time_embed_dim     ,							dtype=self.dtype     ,							name='linear_2'     )(SCREAMING_SNAKE_CASE__     )
             return temb
class  SCREAMING_SNAKE_CASE__  (				nn.Module			):
      snake_case__				:     int        =						32
      snake_case__				:     bool        =						False
      snake_case__				:     float        =						1
      @nn.compact
      def __call__(       self				:       str     ,							SCREAMING_SNAKE_CASE__				:       int     )		->			Tuple:
             return get_sinusoidal_embeddings(
                 SCREAMING_SNAKE_CASE__     ,							embedding_dim=self.dim     ,							flip_sin_to_cos=self.flip_sin_to_cos     ,							freq_shift=self.freq_shift     )


