
from manim import *






class   a_    (       a__				):



       """simple docstring"""






       def      __lowerCAmelCase			(						self					) ->List[str]:
           SCREAMING_SNAKE_CASE							:							Any								=      Rectangle(height=0.5							,    width=0.5					)
           SCREAMING_SNAKE_CASE							:							str								=      Rectangle(height=0.4_6							,    width=0.4_6					).set_stroke(width=0					)

           SCREAMING_SNAKE_CASE							:							Tuple								=      Rectangle(height=0.2_5							,    width=0.2_5					)

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

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

           SCREAMING_SNAKE_CASE							:							Dict								=      [mem.copy() for i in range(6					)]
           SCREAMING_SNAKE_CASE							:							Dict								=      VGroup(*_lowerCamelCase					).arrange(_lowerCamelCase							,    buff=0					)

           SCREAMING_SNAKE_CASE							:							Tuple								=      Text('''Model'''							,    font_size=24					)
           SCREAMING_SNAKE_CASE							:							List[Any]								=      Group(_lowerCamelCase							,    _lowerCamelCase					).arrange(_lowerCamelCase							,    buff=0.5							,    aligned_edge=_lowerCamelCase					)
           model.move_to([3, -1.0, 0]					)
           self.add(_lowerCamelCase					)

           SCREAMING_SNAKE_CASE							:							int								=      []
           SCREAMING_SNAKE_CASE							:							Optional[Any]								=      []

           for i, rect in enumerate(_lowerCamelCase					):
               SCREAMING_SNAKE_CASE							:							int								=      fill.copy().set_fill(_lowerCamelCase							,    opacity=0.8					)
               target.move_to(_lowerCamelCase					)
               model_arr.append(_lowerCamelCase					)

               SCREAMING_SNAKE_CASE							:							List[Any]								=      Rectangle(height=0.4_6							,    width=0.4_6					).set_stroke(width=0.0					).set_fill(_lowerCamelCase							,    opacity=0.8					)
               cpu_target.move_to(cpu_left_col_base[i]					)
               model_cpu_arr.append(_lowerCamelCase					)

           self.add(*_lowerCamelCase							,    *_lowerCamelCase					)

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

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

           SCREAMING_SNAKE_CASE							:							List[Any]								=      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(_lowerCamelCase							,    _lowerCamelCase					)

           SCREAMING_SNAKE_CASE							:							Union[str, Any]								=      MarkupText(
               F"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""							,    font_size=18							,    )

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

           SCREAMING_SNAKE_CASE							:							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(_lowerCamelCase					)					)

           SCREAMING_SNAKE_CASE							:							Tuple								=      Square(0.3					)
           input.set_fill(_lowerCamelCase							,    opacity=1.0					)
           input.set_stroke(width=0.0					)
           input.next_to(model_base[0]							,    _lowerCamelCase							,    buff=0.5					)

           self.play(Write(_lowerCamelCase					)					)

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

           self.play(FadeOut(_lowerCamelCase					)					)

           SCREAMING_SNAKE_CASE							:							Optional[int]								=      Arrow(start=_lowerCamelCase							,    end=_lowerCamelCase							,    color=_lowerCamelCase							,    buff=0.5					)
           a.next_to(model_arr[0].get_left()							,    _lowerCamelCase							,    buff=0.2					)

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

           SCREAMING_SNAKE_CASE							:							Dict								=      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(_lowerCamelCase							,    run_time=3					)					)

           SCREAMING_SNAKE_CASE							:							str								=      {'''run_time''': 1, '''fade_in''': True, '''fade_out''': True, '''buff''': 0.0_2}

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

           SCREAMING_SNAKE_CASE							:							List[str]								=      a.copy()
           for i in range(6					):
               a_c.next_to(model_arr[i].get_right() + 0.0_2							,    _lowerCamelCase							,    buff=0.2					)

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

               SCREAMING_SNAKE_CASE							:							str								=      AnimationGroup(
                   FadeOut(_lowerCamelCase							,    run_time=0.5					)							,    MoveToTarget(_lowerCamelCase							,    run_time=0.5					)							,    FadeIn(_lowerCamelCase							,    run_time=0.5					)							,    lag_ratio=0.2					)

               self.play(_lowerCamelCase					)

               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:
                       SCREAMING_SNAKE_CASE							:							List[Any]								=      0.7

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

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

               SCREAMING_SNAKE_CASE							:							Tuple								=      a_c
               SCREAMING_SNAKE_CASE							:							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(_lowerCamelCase					)							,    FadeOut(_lowerCamelCase							,    run_time=0.5					)							,    )

           SCREAMING_SNAKE_CASE							:							str								=      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(_lowerCamelCase							,    run_time=3					)							,    MoveToTarget(_lowerCamelCase					)					)

           self.wait()




def 				UpperCAmelCase_					(							__snake_case						)     ->			str:







 """simple docstring"""


 _lowercase							      =0

 # if input_string is "aba" than new_input_string become "a|b|a"
 _lowercase							      =''''''
 _lowercase							      =''''''

 # append each character + "|" in new_string for range(0, length-1)
 for i in input_string[: len(__snake_case						) - 1]:
  new_input_string += i + "|"
 # append last character
 new_input_string += input_string[-1]

 # we will store the starting and ending of previous furthest ending palindromic
 # substring
 _lowercase      ,    _lowercase							      =0, 0

 # length[i] shows the length of palindromic substring with center i
 _lowercase							      =[1 for i in range(len(__snake_case						)						)]

 # for each character in new_string find corresponding palindromic string
 _lowercase							      =0
 for j in range(len(__snake_case						)						):
  _lowercase							      =1 if j > r else min(length[l + r - j] // 2     ,						r - j + 1						)
  while (
      j - k >= 0
      and j + k < len(__snake_case						)
      and new_input_string[k + j] == new_input_string[j - k]
  ):
   k += 1

  _lowercase							      =2 * k - 1

  # does this string is ending after the previously explored end (that is r) ?
  # if yes the update the new r to the last index of this
  if j + k - 1 > r:
   _lowercase							      =j - k + 1  # noqa: E741
   _lowercase							      =j + k - 1

  # update max_length and start position
  if max_length < length[j]:
   _lowercase							      =length[j]
   _lowercase							      =j

    # create that string
 _lowercase							      =new_input_string[start - max_length // 2 : start + max_length // 2 + 1]
 for i in s:
  if i != "|":
   output_string += i

 return output_string


if __name__ == "__main__":
  import doctest

  doctest.testmod()

