"""simple docstring"""




from manim import *
class 						__A							( SCREAMING_SNAKE_CASE_		):






     def     __A  (		self  ):
       _lowerCAmelCase						:       str  			=     Rectangle(height=0.5				,     width=0.5  )
       _lowerCAmelCase						:       List[Any]  			=     Rectangle(height=0.4_6				,     width=0.4_6  ).set_stroke(width=0  )

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

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

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

       _lowerCAmelCase						:       Optional[Any]  			=     [mem.copy() for i in range(6  )]
       _lowerCAmelCase						:       Optional[Any]  			=     VGroup(*a__  ).arrange(a__				,     buff=0  )

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

       _lowerCAmelCase						:       Optional[Any]  			=     []
       _lowerCAmelCase						:       str  			=     []

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

         _lowerCAmelCase						:       Dict  			=     Rectangle(height=0.4_6				,     width=0.4_6  ).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__  )

       _lowerCAmelCase						:       str  			=     [meta_mem.copy() for i in range(6  )]
       _lowerCAmelCase						:       Dict  			=     [meta_mem.copy() for i in range(6  )]
       _lowerCAmelCase						:       Optional[int]  			=     VGroup(*a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       Optional[Any]  			=     VGroup(*a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       int  			=     VGroup(a__				,     a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       Dict  			=     Text("""Disk"""				,     font_size=24  )
       _lowerCAmelCase						:       Optional[int]  			=     Group(a__				,     a__  ).arrange(a__				,     buff=0.5				,     aligned_edge=a__  )
       disk.move_to([-4, -1.2_5, 0]  )
       self.add(a__				,     a__  )

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

       _lowerCAmelCase						:       Dict  			=     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__  )

       _lowerCAmelCase						:       List[str]  			=     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__  )

       _lowerCAmelCase						:       List[str]  			=     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__  )  )

       _lowerCAmelCase						:       Union[str, 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.0_2  )
       self.play(MoveToTarget(a__  )  )

       self.play(FadeOut(a__  )  )

       _lowerCAmelCase						:       Dict  			=     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]  )

       _lowerCAmelCase						:       Optional[Any]  			=     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  )  )

       _lowerCAmelCase						:       Optional[int]  			=     {"""run_time""": 1, """fade_in""": True, """fade_out""": True, """buff""": 0.0_2}

       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]  )  )

       _lowerCAmelCase						:       Any  			=     a.copy()
       for i in range(6  ):
         a_c.next_to(model_arr[i].get_right() + 0.0_2				,     a__				,     buff=0.2  )

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

         _lowerCAmelCase						:       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:
             _lowerCAmelCase						:       int  			=     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.0_2				,     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]  )  )

         _lowerCAmelCase						:       Any  			=     a_c
         _lowerCAmelCase						:       Any  			=     a_c.copy()

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

       _lowerCAmelCase						:       List[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(a__				,     run_time=3  )				,     MoveToTarget(a__  )  )

       self.wait()





"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


_a      :		List[Any]           =   logging.get_logger(__name__)

_a      :		Any           =   {
    'microsoft/swinv2-tiny-patch4-window8-256': (
        'https://huggingface.co/microsoft/swinv2-tiny-patch4-window8-256/resolve/main/config.json'
    ),
}
class 						__A							( SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:			int							=		"swinv2"

     _UpperCamelCase							:			List[str]							=		{
         "num_attention_heads": "num_heads",
         "num_hidden_layers": "num_layers",
     }






     def __init__(		self				,     a__=224				,     a__=4				,     a__=3				,     a__=96				,     a__=[2, 2, 6, 2]				,     a__=[3, 6, 12, 24]				,     a__=7				,     a__=4.0				,     a__=True				,     a__=0.0				,     a__=0.0				,     a__=0.1				,     a__="gelu"				,     a__=False				,     a__=0.0_2				,     a__=1e-5				,     a__=32				,     **a__				,     ):
       super().__init__(**a__  )

       _lowerCAmelCase						:       int  			=     image_size
       _lowerCAmelCase						:       Optional[Any]  			=     patch_size
       _lowerCAmelCase						:       Any  			=     num_channels
       _lowerCAmelCase						:       List[Any]  			=     embed_dim
       _lowerCAmelCase						:       Optional[int]  			=     depths
       _lowerCAmelCase						:       List[Any]  			=     len(a__  )
       _lowerCAmelCase						:       Any  			=     num_heads
       _lowerCAmelCase						:       Tuple  			=     window_size
       _lowerCAmelCase						:       Tuple  			=     mlp_ratio
       _lowerCAmelCase						:       Any  			=     qkv_bias
       _lowerCAmelCase						:       Optional[int]  			=     hidden_dropout_prob
       _lowerCAmelCase						:       Tuple  			=     attention_probs_dropout_prob
       _lowerCAmelCase						:       str  			=     drop_path_rate
       _lowerCAmelCase						:       List[str]  			=     hidden_act
       _lowerCAmelCase						:       List[str]  			=     use_absolute_embeddings
       _lowerCAmelCase						:       Optional[int]  			=     layer_norm_eps
       _lowerCAmelCase						:       List[Any]  			=     initializer_range
       _lowerCAmelCase						:       Any  			=     encoder_stride
       # we set the hidden_size attribute in order to make Swinv2 work with VisionEncoderDecoderModel
       # this indicates the channel dimension after the last stage of the model
       _lowerCAmelCase						:       Tuple  			=     int(embed_dim * 2 ** (len(a__  ) - 1)  )
       _lowerCAmelCase						:       Tuple  			=     (0, 0, 0, 0)




