


from manim import *


class 	a__						(    lowerCAmelCase_     ):

       def     UpperCAmelCase( self   :  Optional[int]     ):
            a_     :  str				      =     Rectangle(height=0.5   ,				width=0.5     )
            a_     :  Optional[int]				      =     Rectangle(height=0.4_6   ,				width=0.4_6     ).set_stroke(width=0     )
            a_     :  str				      =     Rectangle(height=0.2_5   ,				width=0.2_5     )

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

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

            a_     :  Tuple				      =     [mem.copy() for i in range(6     )]
            a_     :  Optional[int]				      =     VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_   ,				buff=0     )

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

            a_     :  Optional[Any]				      =     []
            a_     :  Dict				      =     []

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

                 a_     :  Tuple				      =     Rectangle(height=0.4_6 / 4   ,				width=0.4_6 / 3     ).set_stroke(width=0.0     ).set_fill(lowerCamelCase_   ,				opacity=0.7     )

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

            self.add(*lowerCamelCase_   ,				*lowerCamelCase_     )

            a_     :  List[Any]				      =     [meta_mem.copy() for i in range(6     )]
            a_     :  List[str]				      =     [meta_mem.copy() for i in range(6     )]
            a_     :  int				      =     VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_   ,				buff=0     )
            a_     :  Tuple				      =     VGroup(*lowerCamelCase_     ).arrange(lowerCamelCase_   ,				buff=0     )
            a_     :  List[Any]				      =     VGroup(lowerCamelCase_   ,				lowerCamelCase_     ).arrange(lowerCamelCase_   ,				buff=0     )
            a_     :  Dict				      =     Text("""Disk"""   ,				font_size=2_4     )
            a_     :  Optional[int]				      =     Group(lowerCamelCase_   ,				lowerCamelCase_     ).arrange(lowerCamelCase_   ,				buff=0.5   ,				aligned_edge=lowerCamelCase_     )
            disk.move_to([-4.0, -1.2_5, 0]     )
            self.add(lowerCamelCase_   ,				lowerCamelCase_     )

            a_     :  List[Any]				      =     []

            for i in range(6     ):
                 a_     :  Optional[Any]				      =     fill.copy().set_fill(lowerCamelCase_   ,				opacity=0.8     )
                 target.move_to(disk_left_col_base[i]     ).scale(0.5     )
                 cpu_disk_arr.append(lowerCamelCase_     )

            self.add(*lowerCamelCase_     )

            a_     :  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(lowerCamelCase_   ,				lowerCamelCase_     )

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

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

            a_     :  Dict				      =     MarkupText(F'''The offloaded weights are all sent to the CPU.'''   ,				font_size=2_4     )
            step_a.move_to([2, 2, 0]     )

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

            for i in range(6     ):
                 a_     :  List[str]				      =     cpu_disk_arr[i]
                 a_     :  List[str]				      =     rect.copy().set_fill(lowerCamelCase_   ,				opacity=0.8     ).scale(2.0     )
                 cpa.generate_target()
                 cpa.target.move_to(model_base[i]     )

                 if i == 0:
                      rect.set_fill(lowerCamelCase_   ,				opacity=0.8     )
                      rect.generate_target()
                      rect.target.move_to(cpu_left_col_base[0]     ).scale(2.0     )

                      self.remove(
                          *lowerCamelCase_   ,				*lowerCamelCase_   ,				)

                 else:
                      rect.generate_target()
                      rect.target.move_to(cpu_left_col_base[i]     ).scale(2.0     )
                 self.play(MoveToTarget(lowerCamelCase_     )   ,				MoveToTarget(lowerCamelCase_     )   ,				model_base[i].animate.set_stroke(lowerCamelCase_     )     )
            self.play(FadeOut(lowerCamelCase_     )     )

            a_     :  int				      =     MarkupText(
                F'''Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed.'''   ,				font_size=2_4   ,				)
            step_a.move_to([2, 2, 0]     )

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

            a_     :  List[Any]				      =     []
            a_     :  List[str]				      =     []
            for i in range(6     ):
                 a_     :  str				      =     Arrow(start=lowerCamelCase_   ,				end=lowerCamelCase_   ,				color=lowerCamelCase_   ,				buff=0.5     )
                 a.next_to(model_base[i].get_left()   ,				lowerCamelCase_   ,				buff=0.2     )
                 arrows.append(lowerCamelCase_     )
                 animations.append(Write(lowerCamelCase_     )     )
            self.play(*lowerCamelCase_     )
            self.wait()





'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A							     = {
    "configuration_marian": ["MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP", "MarianConfig", "MarianOnnxConfig"],
}

try:
     if not is_sentencepiece_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A							     = ["MarianTokenizer"]

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A							     = [
         "MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST",
         "MarianForCausalLM",
         "MarianModel",
         "MarianMTModel",
         "MarianPreTrainedModel",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A							     = ["TFMarianModel", "TFMarianMTModel", "TFMarianPreTrainedModel"]

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A							     = ["FlaxMarianModel", "FlaxMarianMTModel", "FlaxMarianPreTrainedModel"]

if TYPE_CHECKING:
     from .configuration_marian import MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP, MarianConfig, MarianOnnxConfig

     try:
          if not is_sentencepiece_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_marian import MarianTokenizer

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_marian import (
              MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST,
              MarianForCausalLM,
              MarianModel,
              MarianMTModel,
              MarianPreTrainedModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_marian import TFMarianModel, TFMarianMTModel, TFMarianPreTrainedModel

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, FlaxMarianPreTrainedModel

else:
     import sys

     A							     = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

