


'''simple docstring'''

from manim import *







class 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__):

 def 		lowercase_    (			self			:						Any       ):





    """simple docstring"""



    UpperCamelCase__			    =    Rectangle(height=0.5,       width=0.5       )
    UpperCamelCase__			    =    Rectangle(height=0.46,       width=0.46       ).set_stroke(width=0       )
    UpperCamelCase__			    =    Rectangle(height=0.25,       width=0.25       )

    UpperCamelCase__			    =    [mem.copy() for i in range(6       )]
    UpperCamelCase__			    =    [mem.copy() for i in range(6       )]
    UpperCamelCase__			    =    VGroup(*a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    VGroup(*a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    VGroup(a_,       a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    Text("CPU",       font_size=24       )
    UpperCamelCase__			    =    Group(a_,       a_       ).arrange(a_,       buff=0.5,       aligned_edge=a_       )
    cpu.move_to([-2.5, -0.5, 0]       )
    self.add(a_       )

    UpperCamelCase__			    =    [mem.copy() for i in range(4       )]
    UpperCamelCase__			    =    VGroup(*a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    Text("GPU",       font_size=24       )
    UpperCamelCase__			    =    Group(a_,       a_       ).arrange(a_,       buff=0.5,       aligned_edge=a_       )
    gpu.move_to([-1, -1, 0]       )
    self.add(a_       )

    UpperCamelCase__			    =    [mem.copy() for i in range(6       )]
    UpperCamelCase__			    =    VGroup(*a_       ).arrange(a_,       buff=0       )

    UpperCamelCase__			    =    Text("Model",       font_size=24       )
    UpperCamelCase__			    =    Group(a_,       a_       ).arrange(a_,       buff=0.5,       aligned_edge=a_       )
    model.move_to([3, -1.0, 0]       )
    self.add(a_       )

    UpperCamelCase__			    =    []
    UpperCamelCase__			    =    []

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

       UpperCamelCase__			    =    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_       )

    UpperCamelCase__			    =    [meta_mem.copy() for i in range(6       )]
    UpperCamelCase__			    =    [meta_mem.copy() for i in range(6       )]
    UpperCamelCase__			    =    VGroup(*a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    VGroup(*a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    VGroup(a_,       a_       ).arrange(a_,       buff=0       )
    UpperCamelCase__			    =    Text("Disk",       font_size=24       )
    UpperCamelCase__			    =    Group(a_,       a_       ).arrange(a_,       buff=0.5,       aligned_edge=a_       )
    disk.move_to([-4.0, -1.25, 0]       )
    self.add(a_,       a_       )

    UpperCamelCase__			    =    []

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

    self.add(*a_       )

    UpperCamelCase__			    =    Square(side_length=2.2       )
    key.move_to([-5, 2, 0]       )

    UpperCamelCase__			    =    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(a_,       a_       )

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

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

    UpperCamelCase__			    =    MarkupText(f'The offloaded weights are all sent to the CPU.',       font_size=24       )
    step_a.move_to([2, 2, 0]       )

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

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

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

          self.remove(
              *a_,       *a_,       )

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

    UpperCamelCase__			    =    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=24,       )
    step_a.move_to([2, 2, 0]       )

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

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



'''simple docstring'''

from typing import TYPE_CHECKING

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


__lowercase:		Tuple    						=  {
    "configuration_imagegpt": ["IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ImageGPTConfig", "ImageGPTOnnxConfig"]
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase:		List[str]    						=  ["ImageGPTFeatureExtractor"]
       __lowercase:		Tuple    						=  ["ImageGPTImageProcessor"]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase:		str    						=  [
           "IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST",
           "ImageGPTForCausalImageModeling",
           "ImageGPTForImageClassification",
           "ImageGPTModel",
           "ImageGPTPreTrainedModel",
           "load_tf_weights_in_imagegpt",
       ]


if TYPE_CHECKING:
       from .configuration_imagegpt import IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, ImageGPTConfig, ImageGPTOnnxConfig

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .feature_extraction_imagegpt import ImageGPTFeatureExtractor
              from .image_processing_imagegpt import ImageGPTImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_imagegpt import (
                  IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  ImageGPTForCausalImageModeling,
                  ImageGPTForImageClassification,
                  ImageGPTModel,
                  ImageGPTPreTrainedModel,
                  load_tf_weights_in_imagegpt,
              )

else:
       import sys

       __lowercase:		List[str]    						=  _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)