






'''simple docstring'''



from manim import *
class UpperCAmelCase_					(    __A				):




      """simple docstring"""




      def 				A__      ( self			:		List[Any]		)  ->  int:


       '''simple docstring'''

       lowercase					:   Tuple				  =Rectangle(height=0.5     ,      width=0.5		)
       lowercase					:   str				  =Rectangle(height=0.4_6     ,      width=0.4_6		).set_stroke(width=0		)

       lowercase					:   Any				  =Rectangle(height=0.2_5     ,      width=0.2_5		)

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

       lowercase					:   Tuple				  =[mem.copy() for i in range(4		)]
       lowercase					:   Dict				  =VGroup(*UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0		)
       lowercase					:   List[Any]				  =Text('''GPU'''     ,      font_size=24		)
       lowercase					:   Union[str, Any]				  =Group(UpperCAmelCase     ,      UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0.5     ,      aligned_edge=UpperCAmelCase		)
       gpu.move_to([-1, -1, 0]		)
       self.add(UpperCAmelCase		)

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

       lowercase					:   Any				  =Text('''Model'''     ,      font_size=24		)
       lowercase					:   Dict				  =Group(UpperCAmelCase     ,      UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0.5     ,      aligned_edge=UpperCAmelCase		)
       model.move_to([3, -1.0, 0]		)
       self.add(UpperCAmelCase		)

       lowercase					:   List[str]				  =[]
       lowercase					:   int				  =[]

       for i, rect in enumerate(UpperCAmelCase		):
        lowercase					:   List[Any]				  =fill.copy().set_fill(UpperCAmelCase     ,      opacity=0.8		)
        target.move_to(UpperCAmelCase		)
        model_arr.append(UpperCAmelCase		)

        lowercase					:   Union[str, Any]				  =Rectangle(height=0.4_6     ,      width=0.4_6		).set_stroke(width=0.0		).set_fill(UpperCAmelCase     ,      opacity=0.8		)
        cpu_target.move_to(cpu_left_col_base[i]		)
        model_cpu_arr.append(UpperCAmelCase		)

       self.add(*UpperCAmelCase     ,      *UpperCAmelCase		)

       lowercase					:   List[Any]				  =[meta_mem.copy() for i in range(6		)]
       lowercase					:   Any				  =[meta_mem.copy() for i in range(6		)]
       lowercase					:   Optional[int]				  =VGroup(*UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0		)
       lowercase					:   str				  =VGroup(*UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0		)
       lowercase					:   Optional[Any]				  =VGroup(UpperCAmelCase     ,      UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0		)
       lowercase					:   List[str]				  =Text('''Disk'''     ,      font_size=24		)
       lowercase					:   Optional[int]				  =Group(UpperCAmelCase     ,      UpperCAmelCase		).arrange(UpperCAmelCase     ,      buff=0.5     ,      aligned_edge=UpperCAmelCase		)
       disk.move_to([-4, -1.2_5, 0]		)
       self.add(UpperCAmelCase     ,      UpperCAmelCase		)

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

       lowercase					:   List[str]				  =MarkupText(
           f'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'     ,      font_size=18     ,      )

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

       self.add(UpperCAmelCase     ,      UpperCAmelCase		)

       lowercase					:   str				  =MarkupText(
           f'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'     ,      font_size=18     ,      )

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

       lowercase					:   List[Any]				  =MarkupText(
           f'Now watch as an input is passed through the model\nand how the memory is utilized and handled.'     ,      font_size=24     ,      )
       step_a.move_to([2, 2, 0]		)

       self.play(Write(UpperCAmelCase		)		)

       lowercase					:   Optional[int]				  =Square(0.3		)
       input.set_fill(UpperCAmelCase     ,      opacity=1.0		)
       input.set_stroke(width=0.0		)
       input.next_to(model_base[0]     ,      UpperCAmelCase     ,      buff=0.5		)

       self.play(Write(UpperCAmelCase		)		)

       input.generate_target()
       input.target.next_to(model_arr[0]     ,      direction=UpperCAmelCase     ,      buff=0.0_2		)
       self.play(MoveToTarget(UpperCAmelCase		)		)

       self.play(FadeOut(UpperCAmelCase		)		)

       lowercase					:   str				  =Arrow(start=UpperCAmelCase     ,      end=UpperCAmelCase     ,      color=UpperCAmelCase     ,      buff=0.5		)
       a.next_to(model_arr[0].get_left()     ,      UpperCAmelCase     ,      buff=0.2		)

       model_cpu_arr[0].generate_target()
       model_cpu_arr[0].target.move_to(gpu_rect[0]		)

       lowercase					:   Optional[int]				  =MarkupText(
           f'As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back.'     ,      font_size=24     ,      )
       step_a.move_to([2, 2, 0]		)

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

       lowercase					:   int				  ={'''run_time''': 1, '''fade_in''': True, '''fade_out''': True, '''buff''': 0.0_2}

       self.play(
           Write(UpperCAmelCase		)     ,      Circumscribe(model_arr[0]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      Circumscribe(model_cpu_arr[0]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      Circumscribe(gpu_rect[0]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      )
       self.play(MoveToTarget(model_cpu_arr[0]		)		)

       lowercase					:   Union[str, Any]				  =a.copy()
       for i in range(6		):
        a_c.next_to(model_arr[i].get_right() + 0.0_2     ,      UpperCAmelCase     ,      buff=0.2		)

        input.generate_target()
        input.target.move_to(model_arr[i].get_right() + 0.0_2		)

        lowercase					:   Union[str, Any]				  =AnimationGroup(
            FadeOut(UpperCAmelCase     ,      run_time=0.5		)     ,      MoveToTarget(UpperCAmelCase     ,      run_time=0.5		)     ,      FadeIn(UpperCAmelCase     ,      run_time=0.5		)     ,      lag_ratio=0.2		)

        self.play(UpperCAmelCase		)

        model_cpu_arr[i].generate_target()
        model_cpu_arr[i].target.move_to(cpu_left_col_base[i]		)

        if i < 5:
         model_cpu_arr[i + 1].generate_target()
         model_cpu_arr[i + 1].target.move_to(gpu_rect[0]		)
         if i >= 1:
          lowercase					:   str				  =0.7

         self.play(
             Circumscribe(model_arr[i]     ,      **UpperCAmelCase		)     ,      Circumscribe(cpu_left_col_base[i]     ,      **UpperCAmelCase		)     ,      Circumscribe(cpu_left_col_base[i + 1]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      Circumscribe(gpu_rect[0]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      Circumscribe(model_arr[i + 1]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      )
         if i < 1:
          self.play(
              MoveToTarget(model_cpu_arr[i]		)     ,      MoveToTarget(model_cpu_arr[i + 1]		)     ,      )
         else:
          self.play(
              MoveToTarget(model_cpu_arr[i]     ,      run_time=0.7		)     ,      MoveToTarget(model_cpu_arr[i + 1]     ,      run_time=0.7		)     ,      )
        else:
         model_cpu_arr[i].generate_target()
         model_cpu_arr[i].target.move_to(cpu_left_col_base[-1]		)
         input.generate_target()
         input.target.next_to(model_arr[-1].get_right()     ,      RIGHT + 0.0_2     ,      buff=0.2		)

         self.play(
             Circumscribe(model_arr[-1]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      Circumscribe(cpu_left_col_base[-1]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      Circumscribe(gpu_rect[0]     ,      color=UpperCAmelCase     ,      **UpperCAmelCase		)     ,      )

         self.play(MoveToTarget(model_cpu_arr[i]		)		)

        lowercase					:   Tuple				  =a_c
        lowercase					:   Union[str, Any]				  =a_c.copy()

       input.generate_target()
       input.target.next_to(model_base[-1]     ,      RIGHT + 0.0_2     ,      buff=0.5		)
       self.play(
           FadeOut(UpperCAmelCase		)     ,      FadeOut(UpperCAmelCase     ,      run_time=0.5		)     ,      )

       lowercase					:   Tuple				  =MarkupText(f'Inference on a model too large for GPU memory\nis successfully completed.'     ,      font_size=24		)
       step_a.move_to([2, 2, 0]		)

       self.play(Write(UpperCAmelCase     ,      run_time=3		)     ,      MoveToTarget(UpperCAmelCase		)		)

       self.wait()











'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


SCREAMING_SNAKE_CASE						=	{
    'configuration_m2m_100': ['M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP', 'M2M100Config', 'M2M100OnnxConfig'],
    'tokenization_m2m_100': ['M2M100Tokenizer'],
}


try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      SCREAMING_SNAKE_CASE						=	[
          'M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST',
          'M2M100ForConditionalGeneration',
          'M2M100Model',
          'M2M100PreTrainedModel',
      ]


if TYPE_CHECKING:
      from .configuration_mam_aaa import M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP, MaMaaaConfig, MaMaaaOnnxConfig
      from .tokenization_mam_aaa import MaMaaaTokenizer

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_mam_aaa import (
                M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST,
                MaMaaaForConditionalGeneration,
                MaMaaaModel,
                MaMaaaPreTrainedModel,
            )


else:
      import sys

      SCREAMING_SNAKE_CASE						=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



