





from manim import *






class 	UpperCamelCase_     (     lowerCamelCase__       ):



     def      __a    (		self    :    str	):
       lowerCamelCase_  :    List[Any]   	=			Rectangle(height=0.5					,			width=0.5	)
       lowerCamelCase_  :    List[Any]   	=			Rectangle(height=0.46					,			width=0.46	).set_stroke(width=0	)
       lowerCamelCase_  :    Optional[Any]   	=			Rectangle(height=0.25					,			width=0.25	)

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

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

       lowerCamelCase_  :    Union[str, Any]   	=			[mem.copy() for i in range(6	)]
       lowerCamelCase_  :    Any   	=			VGroup(*lowercase_	).arrange(lowercase_					,			buff=0	)

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

       lowerCamelCase_  :    Optional[Any]   	=			[]
       lowerCamelCase_  :    Optional[int]   	=			[]

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

         lowerCamelCase_  :    Union[str, Any]   	=			Rectangle(height=0.46 / 4					,			width=0.46 / 3	).set_stroke(width=0.0	).set_fill(lowercase_					,			opacity=0.7	)

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

       self.add(*lowercase_					,			*lowercase_	)

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

       lowerCamelCase_  :    str   	=			[]

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

       self.add(*lowercase_	)

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

       lowerCamelCase_  :    str   	=			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(lowercase_					,			lowercase_	)

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

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

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

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

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

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

           self.remove(
               *lowercase_					,			*lowercase_					,			)

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

       lowerCamelCase_  :    List[str]   	=			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(lowercase_					,			run_time=3	)	)

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







import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

_lowercase		:     Optional[Any] 					=[(1,)]


def 		_SCREAMING_SNAKE_CASE    (   ):
		lowerCamelCase_  :    Union[str, Any]   	=			bool(os.getenv('RUN_SLOW'       ,0	)	)
		if run_slow:
				assert True
		else:
				assert False, "should have been skipped"


def 		_SCREAMING_SNAKE_CASE    (   ):
		lowerCamelCase_  :    List[str]   	=			bool(os.getenv('RUN_SLOW'       ,0	)	)
		if run_slow and torch_device == "cuda":
				assert True
		else:
				assert False, "should have been skipped"






@require_torch
class 	UpperCamelCase_     (     unittest.TestCase       ):



					@slow
					@require_torch_gpu
					def      __a    (		self    :    Tuple	):
							check_slow_torch_cuda()



					@require_torch_gpu
					@slow
					def      __a    (		self    :    Optional[int]	):
							check_slow_torch_cuda()





					@parameterized.expand(lowerCamelCase	)
					@slow
					def      __a    (		self    :    List[str]					,			lowerCamelCase    :    Optional[Any]=None	):
							check_slow()


@slow
@require_torch_gpu
def 		_SCREAMING_SNAKE_CASE    (   ):
		check_slow_torch_cuda()


@require_torch_gpu
@slow
def 		_SCREAMING_SNAKE_CASE    (   ):
		check_slow_torch_cuda()


@slow
@pytest.mark.parametrize('param'       ,[1]	)
def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__	):
		check_slow()





@pytest.mark.parametrize('param'       ,[1]	)
@slow
def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__	):
		check_slow()
