


import functools
import operator

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


_UpperCAmelCase			:  str     =logging.get_logger(__name__)

_UpperCAmelCase			:  Optional[int]     ={
    """asapp/sew-tiny-100k""": """https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json""",
    # See all SEW models at https://huggingface.co/models?filter=sew
}







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Optional[Any]					=							"""sew"""




						def __init__(				self   ,						__lowercase=3_2   ,						__lowercase=7_6_8   ,						__lowercase=1_2   ,						__lowercase=1_2   ,						__lowercase=3_0_7_2   ,						__lowercase=2   ,						__lowercase="gelu"   ,						__lowercase=0.1   ,						__lowercase=0.1   ,						__lowercase=0.1   ,						__lowercase=0.0   ,						__lowercase=0.1   ,						__lowercase=0.1   ,						__lowercase=0.02   ,						__lowercase=1e-5   ,						__lowercase="group"   ,						__lowercase="gelu"   ,						__lowercase=(6_4, 1_2_8, 1_2_8, 1_2_8, 1_2_8, 2_5_6, 2_5_6, 2_5_6, 2_5_6, 5_1_2, 5_1_2, 5_1_2, 5_1_2)   ,						__lowercase=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)   ,						__lowercase=(1_0, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)   ,						__lowercase=False   ,						__lowercase=1_2_8   ,						__lowercase=1_6   ,						__lowercase=True   ,						__lowercase=0.05   ,						__lowercase=1_0   ,						__lowercase=2   ,						__lowercase=0.0   ,						__lowercase=1_0   ,						__lowercase=0   ,						__lowercase="mean"   ,						__lowercase=False   ,						__lowercase=False   ,						__lowercase=2_5_6   ,						__lowercase=0   ,						__lowercase=1   ,						__lowercase=2   ,						**__lowercase   ,						)					->    int:
										super().__init__(**__lowercase   ,						pad_token_id=__lowercase   ,						bos_token_id=__lowercase   ,						eos_token_id=__lowercase							)
										lowerCAmelCase_ :      Dict    				=				hidden_size
										lowerCAmelCase_ :      Tuple    				=				feat_extract_norm
										lowerCAmelCase_ :      Tuple    				=				feat_extract_activation
										lowerCAmelCase_ :      List[str]    				=				list(__lowercase							)
										lowerCAmelCase_ :      Optional[int]    				=				list(__lowercase							)
										lowerCAmelCase_ :      Tuple    				=				list(__lowercase							)
										lowerCAmelCase_ :      Optional[int]    				=				conv_bias
										lowerCAmelCase_ :      List[str]    				=				num_conv_pos_embeddings
										lowerCAmelCase_ :      Tuple    				=				num_conv_pos_embedding_groups
										lowerCAmelCase_ :      List[Any]    				=				len(self.conv_dim							)
										lowerCAmelCase_ :      List[str]    				=				num_hidden_layers
										lowerCAmelCase_ :      Any    				=				intermediate_size
										lowerCAmelCase_ :      Union[str, Any]    				=				squeeze_factor
										lowerCAmelCase_ :      Optional[int]    				=				hidden_act
										lowerCAmelCase_ :      Any    				=				num_attention_heads
										lowerCAmelCase_ :      Optional[int]    				=				hidden_dropout
										lowerCAmelCase_ :      Optional[Any]    				=				attention_dropout
										lowerCAmelCase_ :      Tuple    				=				activation_dropout
										lowerCAmelCase_ :      List[str]    				=				feat_proj_dropout
										lowerCAmelCase_ :      Any    				=				final_dropout
										lowerCAmelCase_ :      int    				=				layerdrop
										lowerCAmelCase_ :      Tuple    				=				layer_norm_eps
										lowerCAmelCase_ :      Any    				=				initializer_range
										lowerCAmelCase_ :      Union[str, Any]    				=				vocab_size

										if (
										    (len(self.conv_stride							) != self.num_feat_extract_layers)
										    or (len(self.conv_kernel							) != self.num_feat_extract_layers)
										    or (len(self.conv_dim							) != self.num_feat_extract_layers)
										):
														raise ValueError(
														    '''Configuration for convolutional layers is incorrect.'''
														    '''It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,'''
														    f"""but is `len(config.conv_dim) = {len(self.conv_dim							)}`, `len(config.conv_stride)"""
														    f"""= {len(self.conv_stride							)}`, `len(config.conv_kernel) = {len(self.conv_kernel							)}`."""							)

										# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
										lowerCAmelCase_ :      str    				=				apply_spec_augment
										lowerCAmelCase_ :      Tuple    				=				mask_time_prob
										lowerCAmelCase_ :      Dict    				=				mask_time_length
										lowerCAmelCase_ :      Optional[int]    				=				mask_time_min_masks
										lowerCAmelCase_ :      Optional[int]    				=				mask_feature_prob
										lowerCAmelCase_ :      Tuple    				=				mask_feature_length
										lowerCAmelCase_ :      Dict    				=				mask_feature_min_masks

										# ctc loss
										lowerCAmelCase_ :      List[str]    				=				ctc_loss_reduction
										lowerCAmelCase_ :      int    				=				ctc_zero_infinity

										# sequence classification
										lowerCAmelCase_ :      List[Any]    				=				use_weighted_layer_sum
										lowerCAmelCase_ :      List[Any]    				=				classifier_proj_size




						@property
						def 						lowercase_ (				self							)					->    str:
										return functools.reduce(operator.mul   ,						self.conv_stride   ,						1							)



from manim import *







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						def 						lowercase_ (				self							)					->    Tuple:
										lowerCAmelCase_ :      Dict    				=				Rectangle(height=0.5   ,						width=0.5							)
										lowerCAmelCase_ :      Tuple    				=				Rectangle(height=0.25   ,						width=0.25							)
										lowerCAmelCase_ :      Tuple    				=				Rectangle(height=0.46   ,						width=0.46							).set_stroke(width=0							)

										lowerCAmelCase_ :      Optional[int]    				=				[mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      int    				=				[mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Optional[int]    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      List[str]    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      int    				=				VGroup(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      Tuple    				=				Text('''CPU'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      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							)

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

										lowerCAmelCase_ :      str    				=				[mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Dict    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)

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

										lowerCAmelCase_ :      int    				=				[]
										lowerCAmelCase_ :      int    				=				[]
										lowerCAmelCase_ :      Dict    				=				[]

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

														lowerCAmelCase_ :      Any    				=				Rectangle(height=0.46 / 4   ,						width=0.46 / 3							).set_stroke(width=0.0							).set_fill(__lowercase   ,						opacity=0.7							)

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

										self.add(*__lowercase   ,						*__lowercase   ,						*__lowercase							)

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

										lowerCAmelCase_ :      Union[str, Any]    				=				Text('''Loaded Checkpoint'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      int    				=				Group(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0.5   ,						aligned_edge=__lowercase							)
										checkpoint.move_to([3, 0.5, 0]							)

										self.add(__lowercase							)

										lowerCAmelCase_ :      Optional[Any]    				=				[]
										lowerCAmelCase_ :      Dict    				=				[]

										for i, rect in enumerate(__lowercase							):
														lowerCAmelCase_ :      str    				=				fill.copy().set_fill(__lowercase   ,						opacity=0.7							)
														target.move_to(__lowercase							)
														ckpt_arr.append(__lowercase							)

														lowerCAmelCase_ :      Union[str, Any]    				=				target.copy()
														if i < 5:
																		cpu_target.move_to(cpu_left_col_base[i + 1]							)
														else:
																		cpu_target.move_to(cpu_right_col_base[i - 5]							)
														ckpt_cpu_arr.append(__lowercase							)
										self.add(*__lowercase   ,						*__lowercase							)

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

										lowerCAmelCase_ :      str    				=				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							)

										lowerCAmelCase_ :      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							)

										lowerCAmelCase_ :      str    				=				MarkupText(
										    f"""Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device."""   ,						font_size=2_4   ,						)
										step_a.move_to([2, 2, 0]							)

										lowerCAmelCase_ :      List[Any]    				=				[meta_mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Any    				=				[meta_mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Any    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      Union[str, Any]    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      int    				=				VGroup(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      List[str]    				=				Text('''Disk'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      Optional[int]    				=				Group(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0.5   ,						aligned_edge=__lowercase							)
										disk.move_to([-4.0, -1.25, 0]							)
										self.play(Write(__lowercase   ,						run_time=3							)   ,						Write(__lowercase   ,						run_time=1							)   ,						Create(__lowercase   ,						run_time=1							)							)

										lowerCAmelCase_ :      int    				=				[]
										for i, rect in enumerate(__lowercase							):
														lowerCAmelCase_ :      int    				=				rect.copy()
														target.generate_target()
														target.target.move_to(disk_left_col_base[i]							).scale(0.5							)
														animations.append(MoveToTarget(__lowercase   ,						run_time=1.5							)							)
										self.play(*__lowercase							)

										self.play(FadeOut(__lowercase							)							)

										lowerCAmelCase_ :      Union[str, Any]    				=				MarkupText(f"""Then, the checkpoint is removed from memory\nthrough garbage collection."""   ,						font_size=2_4							)
										step_a.move_to([2, 2, 0]							)

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

										self.play(
										    FadeOut(__lowercase   ,						__lowercase   ,						*__lowercase   ,						*__lowercase							)   ,						)

										self.wait()