
"""simple docstring"""




from manim import *







class 	_lowercase    (							lowerCAmelCase_					):


     '''simple docstring'''





     def 			lowerCAmelCase__							(   self	)->       Any:
          UpperCAmelCase__				:			List[str]							=    Rectangle(height=0.5			,      width=0.5	)
          UpperCAmelCase__				:			Any							=    Rectangle(height=0.46			,      width=0.46	).set_stroke(width=0	)
          UpperCAmelCase__				:			int							=    Rectangle(height=0.25			,      width=0.25	)

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

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

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

          UpperCAmelCase__				:			Tuple							=    Text("Model"			,      font_size=24	)
          UpperCAmelCase__				:			Dict							=    Group(__UpperCamelCase			,      __UpperCamelCase	).arrange(__UpperCamelCase			,      buff=0.5			,      aligned_edge=__UpperCamelCase	)
          model.move_to([3, -1.0, 0]	)
          self.add(__UpperCamelCase	)

          UpperCAmelCase__				:			Optional[Any]							=    []
          UpperCAmelCase__				:			Union[str, Any]							=    []

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

               UpperCAmelCase__				:			List[str]							=    Rectangle(height=0.46 / 4			,      width=0.46 / 3	).set_stroke(width=0.0	).set_fill(__UpperCamelCase			,      opacity=0.7	)

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

          self.add(*__UpperCamelCase			,      *__UpperCamelCase	)

          UpperCAmelCase__				:			Union[str, Any]							=    [meta_mem.copy() for i in range(6	)]
          UpperCAmelCase__				:			Union[str, Any]							=    [meta_mem.copy() for i in range(6	)]
          UpperCAmelCase__				:			Union[str, Any]							=    VGroup(*__UpperCamelCase	).arrange(__UpperCamelCase			,      buff=0	)
          UpperCAmelCase__				:			List[Any]							=    VGroup(*__UpperCamelCase	).arrange(__UpperCamelCase			,      buff=0	)
          UpperCAmelCase__				:			str							=    VGroup(__UpperCamelCase			,      __UpperCamelCase	).arrange(__UpperCamelCase			,      buff=0	)
          UpperCAmelCase__				:			Tuple							=    Text("Disk"			,      font_size=24	)
          UpperCAmelCase__				:			Any							=    Group(__UpperCamelCase			,      __UpperCamelCase	).arrange(__UpperCamelCase			,      buff=0.5			,      aligned_edge=__UpperCamelCase	)
          disk.move_to([-4.0, -1.25, 0]	)
          self.add(__UpperCamelCase			,      __UpperCamelCase	)

          UpperCAmelCase__				:			List[Any]							=    []

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

          self.add(*__UpperCamelCase	)

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

          UpperCAmelCase__				:			int							=    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	)

          UpperCAmelCase__				:			Optional[int]							=    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	)

          UpperCAmelCase__				:			int							=    MarkupText(F"The offloaded weights are all sent to the CPU."			,      font_size=24	)
          step_a.move_to([2, 2, 0]	)

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

          for i in range(6	):
               UpperCAmelCase__				:			Union[str, Any]							=    cpu_disk_arr[i]
               UpperCAmelCase__				:			Dict							=    rect.copy().set_fill(__UpperCamelCase			,      opacity=0.8	).scale(2.0	)
               cpa.generate_target()
               cpa.target.move_to(model_base[i]	)

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

                    self.remove(
                        *__UpperCamelCase			,      *__UpperCamelCase			,      )

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

          UpperCAmelCase__				:			Union[str, Any]							=    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(__UpperCamelCase			,      run_time=3	)	)

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





"""simple docstring"""




import argparse
import os


A__   :						Any 							=     {
    """pytorch""": {
        """1.13""": {
            """torch""": """1.13.1""",
            """torchvision""": """0.14.1""",
            """torchaudio""": """0.13.1""",
            """python""": 3.9,
            """cuda""": """cu116""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu116"""
            ),
            """base_image""": """nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.12""": {
            """torch""": """1.12.1""",
            """torchvision""": """0.13.1""",
            """torchaudio""": """0.12.1""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.11""": {
            """torch""": """1.11.0""",
            """torchvision""": """0.12.0""",
            """torchaudio""": """0.11.0""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.10""": {
            """torch""": """1.10.2""",
            """torchvision""": """0.11.3""",
            """torchaudio""": """0.10.2""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.10.2 torchvision==0.11.3 torchaudio==0.10.2"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        # torchaudio < 0.10 has no CUDA-enabled binary distributions
        """1.9""": {
            """torch""": """1.9.1""",
            """torchvision""": """0.10.1""",
            """torchaudio""": """0.9.1""",
            """python""": 3.9,
            """cuda""": """cu111""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu111"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
    },
    """tensorflow""": {
        """2.11""": {
            """tensorflow""": """2.11.1""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.11.1""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.10""": {
            """tensorflow""": """2.10.1""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.10.1""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.9""": {
            """tensorflow""": """2.9.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.9.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.8""": {
            """tensorflow""": """2.8.2""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.8.2""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.7""": {
            """tensorflow""": """2.7.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.7.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.6""": {
            """tensorflow""": """2.6.5""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.6.5""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.5""": {
            """tensorflow""": """2.5.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.5.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
    },
}


if __name__ == "__main__":
    A__   :						str 							=     argparse.ArgumentParser("""Choose the framework and version to install""")
    parser.add_argument(
        """--framework""", help="""The framework to install. Should be `torch` or `tensorflow`""", type=str, required=True
    )
    parser.add_argument("""--version""", help="""The version of the framework to install.""", type=str, required=True)
    A__   :						Any 							=     parser.parse_args()

    A__   :						List[Any] 							=     past_versions_testing[args.framework][args.version]

    os.system(f"""echo \"export INSTALL_CMD=\'{info["install"]}\'\" >> ~/.profile""")
    print(f"""echo \"export INSTALL_CMD=\'{info["install"]}\'\" >> ~/.profile""")

    A__   :						Any 							=     """"""
    if args.framework == "pytorch":
        A__   :						str 							=     info["""cuda"""]
    os.system(f"""echo \"export CUDA='{cuda}'\" >> ~/.profile""")
    print(f"""echo \"export CUDA='{cuda}'\" >> ~/.profile""")



