"""simple docstring"""



from manim import *






class 				snake_case__     (   snake_case_   ):


 def 		a__ (				self		):
        __a     				=  Rectangle(height=0.5  ,						width=0.5		)
        __a     				=  Rectangle(height=0.46  ,						width=0.46		).set_stroke(width=0		)

        __a     				=  Rectangle(height=0.25  ,						width=0.25		)

        __a     				=  [mem.copy() for i in range(6		)]
        __a     				=  [mem.copy() for i in range(6		)]
        __a     				=  VGroup(*lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)
        __a     				=  VGroup(*lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)
        __a     				=  VGroup(lowerCamelCase  ,						lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)
        __a     				=  Text("CPU"  ,						font_size=24		)
        __a     				=  Group(lowerCamelCase  ,						lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0.5  ,						aligned_edge=lowerCamelCase		)
        cpu.move_to([-2.5, -0.5, 0]		)
        self.add(lowerCamelCase		)

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

        __a     				=  [mem.copy() for i in range(6		)]
        __a     				=  VGroup(*lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)

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

        __a     				=  []
        __a     				=  []

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

               __a     				=  Rectangle(height=0.46  ,						width=0.46		).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		)

        __a     				=  [meta_mem.copy() for i in range(6		)]
        __a     				=  [meta_mem.copy() for i in range(6		)]
        __a     				=  VGroup(*lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)
        __a     				=  VGroup(*lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)
        __a     				=  VGroup(lowerCamelCase  ,						lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0		)
        __a     				=  Text("Disk"  ,						font_size=24		)
        __a     				=  Group(lowerCamelCase  ,						lowerCamelCase		).arrange(lowerCamelCase  ,						buff=0.5  ,						aligned_edge=lowerCamelCase		)
        disk.move_to([-4, -1.25, 0]		)
        self.add(lowerCamelCase  ,						lowerCamelCase		)

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

        __a     				=  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		)

        __a     				=  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		)

        __a     				=  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		)		)

        __a     				=  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.02		)
        self.play(MoveToTarget(lowerCamelCase		)		)

        self.play(FadeOut(lowerCamelCase		)		)

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

        __a     				=  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		)		)

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

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

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

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

               __a     				=  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:
                             __a     				=  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.02  ,						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]		)		)

               __a     				=  a_c
               __a     				=  a_c.copy()

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

        __a     				=  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()

"""simple docstring"""



import json
import os
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


SCREAMING_SNAKE_CASE__:int			=	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__:List[Any]			=	{"""vocab_file""": """vocab.json"""}

SCREAMING_SNAKE_CASE__:Optional[int]			=	{
    """vocab_file""": {
        """mgp-str""": """https://huggingface.co/alibaba-damo/mgp-str-base/blob/main/vocab.json""",
    }
}

SCREAMING_SNAKE_CASE__:Optional[Any]			=	{"""mgp-str""": 27}






class 				snake_case__     (   snake_case_   ):
 _snake_case   :			Tuple           =		VOCAB_FILES_NAMES
 _snake_case   :			Tuple           =		PRETRAINED_VOCAB_FILES_MAP
 _snake_case   :			Optional[Any]           =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES


 def __init__(				self  ,						lowerCamelCase  ,						lowerCamelCase="[GO]"  ,						lowerCamelCase="[GO]"  ,						lowerCamelCase="[s]"  ,						lowerCamelCase="[GO]"  ,						**lowerCamelCase		):
        super().__init__(
            unk_token=lowerCamelCase  ,						bos_token=lowerCamelCase  ,						eos_token=lowerCamelCase  ,						pad_token=lowerCamelCase  ,						**lowerCamelCase  ,						)

        with open(lowerCamelCase  ,						encoding="utf-8"		) as vocab_handle:
               __a     				=  json.load(lowerCamelCase		)
        __a     				=  {v: k for k, v in self.vocab.items()}


 @property
 def 		a__ (				self		):
        return len(self.vocab		)


 def 		a__ (				self		):
        return dict(self.vocab  ,						**self.added_tokens_encoder		)


 def 		a__ (				self  ,						lowerCamelCase		):
        __a     				=  []
        for s in text:
               char_tokens.extend(lowerCamelCase		)
        return char_tokens


 def 		a__ (				self  ,						lowerCamelCase		):
        return self.vocab.get(lowerCamelCase  ,						self.vocab.get(self.unk_token		)		)


 def 		a__ (				self  ,						lowerCamelCase		):
        return self.decoder.get(lowerCamelCase		)






 def 		a__ (				self  ,						lowerCamelCase  ,						lowerCamelCase = None		):
        if not os.path.isdir(lowerCamelCase		):
               logger.error("Vocabulary path ({}) should be a directory".format(lowerCamelCase		)		)
               return
        __a     				=  os.path.join(
            lowerCamelCase  ,						(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]		)

        with open(lowerCamelCase  ,						"w"  ,						encoding="utf-8"		) as f:
               f.write(json.dumps(self.vocab  ,						indent=2  ,						sort_keys=lowerCamelCase  ,						ensure_ascii=lowerCamelCase		) + "\n"		)

        return (vocab_file,)
