



from manim import *

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			def  snake_case__     (   self							: Optional[Any] ):
					'''simple docstring'''





					__UpperCAmelCase    :     Dict													=	Rectangle(height=0.5       ,       width=0.5 )
					__UpperCAmelCase    :     Optional[Any]													=	Rectangle(height=0.4_6       ,       width=0.4_6 ).set_stroke(width=0 )

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

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

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

					__UpperCAmelCase    :     str													=	[mem.copy() for i in range(6 )]
					__UpperCAmelCase    :     List[Any]													=	VGroup(*a_ ).arrange(a_       ,       buff=0 )

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

					__UpperCAmelCase    :     Optional[int]													=	[]
					__UpperCAmelCase    :     Optional[Any]													=	[]

					for i, rect in enumerate(a_ ):
							__UpperCAmelCase    :     Union[str, Any]													=	fill.copy().set_fill(a_       ,       opacity=0.8 )
							target.move_to(a_ )
							model_arr.append(a_ )

							__UpperCAmelCase    :     Optional[int]													=	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_ )

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

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

					__UpperCAmelCase    :     Optional[int]													=	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_ )

					__UpperCAmelCase    :     List[Any]													=	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_ )

					__UpperCAmelCase    :     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_ ) )

					__UpperCAmelCase    :     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_ ) )

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

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

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

					__UpperCAmelCase    :     Tuple													=	{'''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] ) )

					__UpperCAmelCase    :     Tuple													=	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 )

							__UpperCAmelCase    :     Optional[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:
											__UpperCAmelCase    :     Dict													=	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] ) )

							__UpperCAmelCase    :     Optional[Any]													=	a_c
							__UpperCAmelCase    :     Optional[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 )       ,       )

					__UpperCAmelCase    :     Tuple													=	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()










from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
				from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


__A   			=logging.get_logger(__name__)

__A   			={
    "microsoft/deberta-v2-xlarge": "https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/config.json",
    "microsoft/deberta-v2-xxlarge": "https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/config.json",
    "microsoft/deberta-v2-xlarge-mnli": (
        "https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/config.json"
    ),
    "microsoft/deberta-v2-xxlarge-mnli": (
        "https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/config.json"
    ),
}

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			UpperCamelCase									=       """deberta-v2"""




			def __init__(   self							: Optional[int]       ,       a_							: List[str]=12_81_00       ,       a_							: Optional[Any]=15_36       ,       a_							: Optional[Any]=24       ,       a_							: List[Any]=24       ,       a_							: Optional[int]=61_44       ,       a_							: List[Any]="gelu"       ,       a_							: Any=0.1       ,       a_							: Tuple=0.1       ,       a_							: Optional[Any]=5_12       ,       a_							: Tuple=0       ,       a_							: Dict=0.0_2       ,       a_							: Optional[Any]=1e-7       ,       a_							: List[str]=False       ,       a_							: List[Any]=-1       ,       a_							: List[str]=0       ,       a_							: Optional[Any]=True       ,       a_							: List[Any]=None       ,       a_							: Optional[int]=0       ,       a_							: Tuple="gelu"       ,       **a_							: List[str]       ,       ):
					'''simple docstring'''





					super().__init__(**a_ )

					__UpperCAmelCase    :     Any													=	hidden_size
					__UpperCAmelCase    :     Any													=	num_hidden_layers
					__UpperCAmelCase    :     List[Any]													=	num_attention_heads
					__UpperCAmelCase    :     Union[str, Any]													=	intermediate_size
					__UpperCAmelCase    :     List[str]													=	hidden_act
					__UpperCAmelCase    :     int													=	hidden_dropout_prob
					__UpperCAmelCase    :     List[str]													=	attention_probs_dropout_prob
					__UpperCAmelCase    :     str													=	max_position_embeddings
					__UpperCAmelCase    :     int													=	type_vocab_size
					__UpperCAmelCase    :     Tuple													=	initializer_range
					__UpperCAmelCase    :     Optional[int]													=	relative_attention
					__UpperCAmelCase    :     int													=	max_relative_positions
					__UpperCAmelCase    :     Any													=	pad_token_id
					__UpperCAmelCase    :     int													=	position_biased_input

					# Backwards compatibility
					if type(a_ ) == str:
							__UpperCAmelCase    :     Optional[Any]													=	[x.strip() for x in pos_att_type.lower().split('''|''' )]

					__UpperCAmelCase    :     Tuple													=	pos_att_type
					__UpperCAmelCase    :     int													=	vocab_size
					__UpperCAmelCase    :     Optional[Any]													=	layer_norm_eps

					__UpperCAmelCase    :     str													=	kwargs.get('''pooler_hidden_size'''       ,       a_ )
					__UpperCAmelCase    :     Union[str, Any]													=	pooler_dropout
					__UpperCAmelCase    :     Tuple													=	pooler_hidden_act

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			@property
			def  snake_case__     (   self							: Optional[Any] ):
					'''simple docstring'''





					if self.task == "multiple-choice":
							__UpperCAmelCase    :     List[Any]													=	{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
					else:
							__UpperCAmelCase    :     int													=	{0: '''batch''', 1: '''sequence'''}
					if self._config.type_vocab_size > 0:
							return OrderedDict(
							    [('''input_ids''', dynamic_axis), ('''attention_mask''', dynamic_axis), ('''token_type_ids''', dynamic_axis)] )
					else:
							return OrderedDict([('''input_ids''', dynamic_axis), ('''attention_mask''', dynamic_axis)] )




			@property
			def  snake_case__     (   self							: Union[str, Any] ):
					'''simple docstring'''





					return 12




			def  snake_case__     (   self							: Any       ,       a_							: Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]       ,       a_							: int = -1       ,       a_							: int = -1       ,       a_							: int = -1       ,       a_							: bool = False       ,       a_							: Optional["TensorType"] = None       ,       a_							: int = 3       ,       a_							: int = 40       ,       a_							: int = 40       ,       a_							: "PreTrainedTokenizerBase" = None       ,       ):
					'''simple docstring'''





					__UpperCAmelCase    :     List[Any]													=	super().generate_dummy_inputs(preprocessor=a_       ,       framework=a_ )
					if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
							del dummy_inputs["token_type_ids"]
					return dummy_inputs





