





'''simple docstring'''







from typing import Mapping

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


snake_case_  :							Union[str, Any]            =	logging.get_logger(__name__)

snake_case_  :							int            =	{
    "google/long-t5-local-base": "https://huggingface.co/google/long-t5-local-base/blob/main/config.json",
    "google/long-t5-local-large": "https://huggingface.co/google/long-t5-local-large/blob/main/config.json",
    "google/long-t5-tglobal-base": "https://huggingface.co/google/long-t5-tglobal-base/blob/main/config.json",
    "google/long-t5-tglobal-large": "https://huggingface.co/google/long-t5-tglobal-large/blob/main/config.json",
}


class        __a   (lowerCamelCase  ):
							__a       : Any          =							"longt5"
							__a       : Dict          =							["past_key_values"]
							__a       : int          =							{"hidden_size": "d_model", "num_attention_heads": "num_heads", "num_hidden_layers": "num_layers"}

							def __init__(				self				:  Optional[Any]							,  __magic_name__				:  Optional[int]=3_21_28							,  __magic_name__				:  str=5_12							,  __magic_name__				:  Optional[Any]=64							,  __magic_name__				:  List[str]=20_48							,  __magic_name__				:  List[str]=6							,  __magic_name__				:  Tuple=None							,  __magic_name__				:  List[str]=8							,  __magic_name__				:  Union[str, Any]=1_27							,  __magic_name__				:  Any=16							,  __magic_name__				:  Any=32							,  __magic_name__				:  str=1_28							,  __magic_name__				:  Tuple=0.1							,  __magic_name__				:  Union[str, Any]=1E-6							,  __magic_name__				:  str=1.0							,  __magic_name__				:  int="relu"							,  __magic_name__				:  Tuple=True							,  __magic_name__				:  Tuple="local"							,  __magic_name__				:  str=True							,  __magic_name__				:  int=0							,  __magic_name__				:  Any=1							,  **__magic_name__				:  Optional[Any]							,  )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	vocab_size
													UpperCAmelCase_      :   Tuple      =	d_model
													UpperCAmelCase_      :   Any      =	d_kv
													UpperCAmelCase_      :   Dict      =	d_ff
													UpperCAmelCase_      :   int      =	num_layers
													# default = symmetry
													UpperCAmelCase_      :   Optional[int]      =	num_decoder_layers if num_decoder_layers is not None else self.num_layers
													UpperCAmelCase_      :   List[str]      =	num_heads
													UpperCAmelCase_      :   Dict      =	local_radius
													UpperCAmelCase_      :   Union[str, Any]      =	global_block_size
													UpperCAmelCase_      :   Tuple      =	relative_attention_num_buckets
													UpperCAmelCase_      :   Dict      =	relative_attention_max_distance
													UpperCAmelCase_      :   Tuple      =	dropout_rate
													UpperCAmelCase_      :   List[str]      =	layer_norm_epsilon
													UpperCAmelCase_      :   str      =	initializer_factor
													UpperCAmelCase_      :   Dict      =	feed_forward_proj
													UpperCAmelCase_      :   Dict      =	encoder_attention_type
													UpperCAmelCase_      :   List[str]      =	use_cache

													UpperCAmelCase_      :   List[str]      =	self.feed_forward_proj.split('''-''' )
													UpperCAmelCase_      :   Tuple      =	act_info[-1]
													UpperCAmelCase_      :   List[str]      =	act_info[0] == '''gated'''

													if len(__magic_name__ ) > 1 and act_info[0] != "gated" or len(__magic_name__ ) > 2:
																			raise ValueError(
																			    F"""`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."""
																			    '''Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '''
																			    '''\'gated-gelu\' or \'relu\'''' )

													# for backwards compatibility
													if feed_forward_proj == "gated-gelu":
																			UpperCAmelCase_      :   Optional[Any]      =	'''gelu_new'''

													super().__init__(
													    pad_token_id=__magic_name__							,  eos_token_id=__magic_name__							,  is_encoder_decoder=__magic_name__							,  **__magic_name__							,  )





class        __a   (lowerCamelCase  ):

							@property
							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Mapping[str, Mapping[int, str]]:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	{
													    '''input_ids''': {0: '''batch''', 1: '''encoder_sequence'''},
													    '''attention_mask''': {0: '''batch''', 1: '''encoder_sequence'''},
													}
													if self.use_past:
																			UpperCAmelCase_      :   Union[str, Any]      =	'''past_encoder_sequence + sequence'''
																			UpperCAmelCase_      :   int      =	{0: '''batch'''}
																			UpperCAmelCase_      :   Optional[int]      =	{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
													else:
																			UpperCAmelCase_      :   List[str]      =	{0: '''batch''', 1: '''decoder_sequence'''}
																			UpperCAmelCase_      :   int      =	{0: '''batch''', 1: '''decoder_sequence'''}

													if self.use_past:
																			self.fill_with_past_key_values_(__magic_name__							,  direction='''inputs''' )

													return common_inputs



							@property
							def      UpperCAmelCase__						(				self				:  Dict )       ->							int:







													"""simple docstring"""
													return 13












'''simple docstring'''







from manim import *


class        __a   (lowerCamelCase  ):

							def      UpperCAmelCase__						(				self				:  str )       ->							Any:







													"""simple docstring"""
													UpperCAmelCase_      :   List[str]      =	Rectangle(height=0.5							,  width=0.5 )
													UpperCAmelCase_      :   int      =	Rectangle(height=0.4_6							,  width=0.4_6 ).set_stroke(width=0 )
													UpperCAmelCase_      :   str      =	Rectangle(height=0.2_5							,  width=0.2_5 )

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

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

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

													UpperCAmelCase_      :   Dict      =	Text('''Model'''							,  font_size=24 )
													UpperCAmelCase_      :   str      =	Group(__magic_name__							,  __magic_name__ ).arrange(__magic_name__							,  buff=0.5							,  aligned_edge=__magic_name__ )
													model.move_to([3, -1.0, 0] )
													self.add(__magic_name__ )

													UpperCAmelCase_      :   List[str]      =	[]
													UpperCAmelCase_      :   int      =	[]

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

																			UpperCAmelCase_      :   List[Any]      =	Rectangle(height=0.4_6 / 4							,  width=0.4_6 / 3 ).set_stroke(width=0.0 ).set_fill(__magic_name__							,  opacity=0.7 )

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

													self.add(*__magic_name__							,  *__magic_name__ )

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

													UpperCAmelCase_      :   Optional[Any]      =	[]

													for i in range(6 ):
																			UpperCAmelCase_      :   Tuple      =	fill.copy().set_fill(__magic_name__							,  opacity=0.8 )
																			target.move_to(disk_left_col_base[i] ).scale(0.5 )
																			cpu_disk_arr.append(__magic_name__ )

													self.add(*__magic_name__ )

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

													UpperCAmelCase_      :   Union[str, Any]      =	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(__magic_name__							,  __magic_name__ )

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

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

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

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

													for i in range(6 ):
																			UpperCAmelCase_      :   Dict      =	cpu_disk_arr[i]
																			UpperCAmelCase_      :   int      =	rect.copy().set_fill(__magic_name__							,  opacity=0.8 ).scale(2.0 )
																			cpa.generate_target()
																			cpa.target.move_to(model_base[i] )

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

																									self.remove(
																									    *__magic_name__							,  *__magic_name__							,  )

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

													UpperCAmelCase_      :   int      =	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(__magic_name__							,  run_time=3 ) )

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





