


"""simple docstring"""



from manim import *
class 					__magic_name__		(			_UpperCAmelCase     ):






       def  __snake_case						(   self  :    List[str]				):

              '''simple docstring'''






              lowercase		:Any       							=				Rectangle(height=0.5  ,     width=0.5				)
              lowercase		:int       							=				Rectangle(height=0.46  ,     width=0.46				).set_stroke(width=0				)

              lowercase		:Union[str, Any]       							=				Rectangle(height=0.25  ,     width=0.25				)

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

              lowercase		:Dict       							=				[mem.copy() for i in range(4				)]
              lowercase		:Union[str, Any]       							=				VGroup(*lowercase__				).arrange(lowercase__  ,     buff=0				)
              lowercase		:Union[str, Any]       							=				Text('''GPU'''  ,     font_size=2_4				)
              lowercase		:Any       							=				Group(lowercase__  ,     lowercase__				).arrange(lowercase__  ,     buff=0.5  ,     aligned_edge=lowercase__				)
              gpu.move_to([-1, -1, 0]				)
              self.add(lowercase__				)

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

              lowercase		:Any       							=				Text('''Model'''  ,     font_size=2_4				)
              lowercase		:str       							=				Group(lowercase__  ,     lowercase__				).arrange(lowercase__  ,     buff=0.5  ,     aligned_edge=lowercase__				)
              model.move_to([3, -1.0, 0]				)
              self.add(lowercase__				)

              lowercase		:List[str]       							=				[]
              lowercase		:List[str]       							=				[]

              for i, rect in enumerate(lowercase__				):
                     lowercase		:Any       							=				fill.copy().set_fill(lowercase__  ,     opacity=0.8				)
                     target.move_to(lowercase__				)
                     model_arr.append(lowercase__				)

                     lowercase		:int       							=				Rectangle(height=0.46  ,     width=0.46				).set_stroke(width=0.0				).set_fill(lowercase__  ,     opacity=0.8				)
                     cpu_target.move_to(cpu_left_col_base[i]				)
                     model_cpu_arr.append(lowercase__				)

              self.add(*lowercase__  ,     *lowercase__				)

              lowercase		:Optional[int]       							=				[meta_mem.copy() for i in range(6				)]
              lowercase		:Optional[int]       							=				[meta_mem.copy() for i in range(6				)]
              lowercase		:List[str]       							=				VGroup(*lowercase__				).arrange(lowercase__  ,     buff=0				)
              lowercase		:Dict       							=				VGroup(*lowercase__				).arrange(lowercase__  ,     buff=0				)
              lowercase		:Dict       							=				VGroup(lowercase__  ,     lowercase__				).arrange(lowercase__  ,     buff=0				)
              lowercase		:int       							=				Text('''Disk'''  ,     font_size=2_4				)
              lowercase		:Union[str, Any]       							=				Group(lowercase__  ,     lowercase__				).arrange(lowercase__  ,     buff=0.5  ,     aligned_edge=lowercase__				)
              disk.move_to([-4, -1.25, 0]				)
              self.add(lowercase__  ,     lowercase__				)

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

              lowercase		:List[Any]       							=				MarkupText(
                  f"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"""  ,     font_size=1_8  ,     )

              key_text.move_to([-5, 2.4, 0]				)

              self.add(lowercase__  ,     lowercase__				)

              lowercase		:List[str]       							=				MarkupText(
                  f"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""  ,     font_size=1_8  ,     )

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

              lowercase		:Dict       							=				MarkupText(
                  f"""Now watch as an input is passed through the model\nand how the memory is utilized and handled."""  ,     font_size=2_4  ,     )
              step_a.move_to([2, 2, 0]				)

              self.play(Write(lowercase__				)				)

              lowercase		:Optional[int]       							=				Square(0.3				)
              input.set_fill(lowercase__  ,     opacity=1.0				)
              input.set_stroke(width=0.0				)
              input.next_to(model_base[0]  ,     lowercase__  ,     buff=0.5				)

              self.play(Write(lowercase__				)				)

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

              self.play(FadeOut(lowercase__				)				)

              lowercase		:Union[str, Any]       							=				Arrow(start=lowercase__  ,     end=lowercase__  ,     color=lowercase__  ,     buff=0.5				)
              a.next_to(model_arr[0].get_left()  ,     lowercase__  ,     buff=0.2				)

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

              lowercase		:Optional[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=2_4  ,     )
              step_a.move_to([2, 2, 0]				)

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

              lowercase		:int       							=				{"run_time": 1, "fade_in": True, "fade_out": True, "buff": 0.02}

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

              lowercase		:List[Any]       							=				a.copy()
              for i in range(6				):
                     a_c.next_to(model_arr[i].get_right() + 0.02  ,     lowercase__  ,     buff=0.2				)

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

                     lowercase		:Optional[int]       							=				AnimationGroup(
                         FadeOut(lowercase__  ,     run_time=0.5				)  ,     MoveToTarget(lowercase__  ,     run_time=0.5				)  ,     FadeIn(lowercase__  ,     run_time=0.5				)  ,     lag_ratio=0.2				)

                     self.play(lowercase__				)

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

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

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

                     lowercase		:Dict       							=				a_c
                     lowercase		:List[str]       							=				a_c.copy()

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

              lowercase		:Tuple       							=				MarkupText(f"""Inference on a model too large for GPU memory\nis successfully completed."""  ,     font_size=2_4				)
              step_a.move_to([2, 2, 0]				)

              self.play(Write(lowercase__  ,     run_time=3				)  ,     MoveToTarget(lowercase__				)				)

              self.wait()





"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase      		=			{
    '''configuration_xlm_roberta''': [
        '''XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XLMRobertaConfig''',
        '''XLMRobertaOnnxConfig''',
    ],
}

try:
 if not is_sentencepiece_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=			['''XLMRobertaTokenizer''']

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=			['''XLMRobertaTokenizerFast''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=			[
     '''XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''XLMRobertaForCausalLM''',
     '''XLMRobertaForMaskedLM''',
     '''XLMRobertaForMultipleChoice''',
     '''XLMRobertaForQuestionAnswering''',
     '''XLMRobertaForSequenceClassification''',
     '''XLMRobertaForTokenClassification''',
     '''XLMRobertaModel''',
     '''XLMRobertaPreTrainedModel''',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=			[
     '''TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''TFXLMRobertaForCausalLM''',
     '''TFXLMRobertaForMaskedLM''',
     '''TFXLMRobertaForMultipleChoice''',
     '''TFXLMRobertaForQuestionAnswering''',
     '''TFXLMRobertaForSequenceClassification''',
     '''TFXLMRobertaForTokenClassification''',
     '''TFXLMRobertaModel''',
     '''TFXLMRobertaPreTrainedModel''',
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase      		=			[
     '''FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''FlaxXLMRobertaForMaskedLM''',
     '''FlaxXLMRobertaForCausalLM''',
     '''FlaxXLMRobertaForMultipleChoice''',
     '''FlaxXLMRobertaForQuestionAnswering''',
     '''FlaxXLMRobertaForSequenceClassification''',
     '''FlaxXLMRobertaForTokenClassification''',
     '''FlaxXLMRobertaModel''',
     '''FlaxXLMRobertaPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_xlm_roberta import (
     XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP,
     XLMRobertaConfig,
     XLMRobertaOnnxConfig,
 )

 try:
  if not is_sentencepiece_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_xlm_roberta import XLMRobertaTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_xlm_roberta_fast import XLMRobertaTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_xlm_roberta import (
      XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
      XLMRobertaForCausalLM,
      XLMRobertaForMaskedLM,
      XLMRobertaForMultipleChoice,
      XLMRobertaForQuestionAnswering,
      XLMRobertaForSequenceClassification,
      XLMRobertaForTokenClassification,
      XLMRobertaModel,
      XLMRobertaPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_xlm_roberta import (
      TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFXLMRobertaForCausalLM,
      TFXLMRobertaForMaskedLM,
      TFXLMRobertaForMultipleChoice,
      TFXLMRobertaForQuestionAnswering,
      TFXLMRobertaForSequenceClassification,
      TFXLMRobertaForTokenClassification,
      TFXLMRobertaModel,
      TFXLMRobertaPreTrainedModel,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_xlm_roberta import (
      FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
      FlaxXLMRobertaForCausalLM,
      FlaxXLMRobertaForMaskedLM,
      FlaxXLMRobertaForMultipleChoice,
      FlaxXLMRobertaForQuestionAnswering,
      FlaxXLMRobertaForSequenceClassification,
      FlaxXLMRobertaForTokenClassification,
      FlaxXLMRobertaModel,
      FlaxXLMRobertaPreTrainedModel,
  )

else:
 import sys

 UpperCAmelCase      		=			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

