



'''simple docstring'''






from manim import *

class 							a__( lowercase__     ):







    def       lowercase_	(				self			:  List[Any]     ):
      a						: List[str]					       =					Rectangle(height=0.5						,      width=0.5     )
      a						: str					       =					Rectangle(height=0.46						,      width=0.46     ).set_stroke(width=0     )

      a						: List[str]					       =					Rectangle(height=0.25						,      width=0.25     )

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

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

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

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

      a						: Dict					       =					[]
      a						: Any					       =					[]

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

        a						: str					       =					Rectangle(height=0.46						,      width=0.46     ).set_stroke(width=0.0     ).set_fill(_a						,      opacity=0.8     )
        cpu_target.move_to(cpu_left_col_base[i]     )
        model_cpu_arr.append(_a     )

      self.add(*_a						,      *_a     )

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

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

      a						: 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(_a						,      _a     )

      a						: List[Any]					       =					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     )

      a						: Dict					       =					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(_a     )     )

      a						: Optional[Any]					       =					Square(0.3     )
      input.set_fill(_a						,      opacity=1.0     )
      input.set_stroke(width=0.0     )
      input.next_to(model_base[0]						,      _a						,      buff=0.5     )

      self.play(Write(_a     )     )

      input.generate_target()
      input.target.next_to(model_arr[0]						,      direction=_a						,      buff=0.02     )
      self.play(MoveToTarget(_a     )     )

      self.play(FadeOut(_a     )     )

      a						: List[Any]					       =					Arrow(start=_a						,      end=_a						,      color=_a						,      buff=0.5     )
      a.next_to(model_arr[0].get_left()						,      _a						,      buff=0.2     )

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

      a						: 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(_a						,      run_time=3     )     )

      a						: List[Any]					       =					{'run_time': 1, 'fade_in': True, 'fade_out': True, 'buff': 0.02}

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

      a						: str					       =					a.copy()
      for i in range(6     ):
        a_c.next_to(model_arr[i].get_right() + 0.02						,      _a						,      buff=0.2     )

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

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

        self.play(_a     )

        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:
            a						: Any					       =					0.7

          self.play(
              Circumscribe(model_arr[i]						,      **_a     )						,      Circumscribe(cpu_left_col_base[i]						,      **_a     )						,      Circumscribe(cpu_left_col_base[i + 1]						,      color=_a						,      **_a     )						,      Circumscribe(gpu_rect[0]						,      color=_a						,      **_a     )						,      Circumscribe(model_arr[i + 1]						,      color=_a						,      **_a     )						,      )
          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.02						,      buff=0.2     )

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

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

        a						: Optional[Any]					       =					a_c
        a						: Union[str, Any]					       =					a_c.copy()

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

      a						: Optional[int]					       =					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(_a						,      run_time=3     )						,      MoveToTarget(_a     )     )

      self.wait()







'''simple docstring'''






import math

class 							a__:







    def __init__(				self			:  int						,      __snake_case			:  Any=0     ):  # a graph with Node 0,1,...,N-1
      a						: List[Any]					       =					n
      a						: Optional[Any]					       =					[
          [math.inf for j in range(0						,      __snake_case     )] for i in range(0						,      __snake_case     )
      ]  # adjacency matrix for weight
      a						: Dict					       =					[
          [math.inf for j in range(0						,      __snake_case     )] for i in range(0						,      __snake_case     )
      ]  # dp[i][j] stores minimum distance from i to j







    def       lowercase_	(				self			:  int						,      __snake_case			:  str						,      __snake_case			:  Tuple						,      __snake_case			:  int     ):
      a						: str					       =					w







    def       lowercase_	(				self			:  int     ):
      for k in range(0						,      self.n     ):
        for i in range(0						,      self.n     ):
          for j in range(0						,      self.n     ):
            a						: str					       =					min(self.dp[i][j]						,      self.dp[i][k] + self.dp[k][j]     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Any						,      __snake_case			:  List[str]     ):
      return self.dp[u][v]


if __name__ == "__main__":
     lowerCAmelCase: Any							=						Graph(5)
     graph.add_edge(0, 2, 9)
     graph.add_edge(0, 4, 1_0)
     graph.add_edge(1, 3, 5)
     graph.add_edge(2, 3, 7)
     graph.add_edge(3, 0, 1_0)
     graph.add_edge(3, 1, 2)
     graph.add_edge(3, 2, 1)
     graph.add_edge(3, 4, 6)
     graph.add_edge(4, 1, 3)
     graph.add_edge(4, 2, 4)
     graph.add_edge(4, 3, 9)
     graph.floyd_warshall()
     graph.show_min(1, 4)
     graph.show_min(0, 3)