
'''simple docstring'''






import copy
import os
from typing import Union

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


A			      =      logging.get_logger(__name__)

A			      =      {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}



class     __snake_case		(   _UpperCamelCase):
					_lowerCAmelCase			     =	'''altclip_text_model'''
					def __init__(     self,    A=25_0002,    A=1024,    A=24,    A=16,    A=4096,    A="gelu",    A=0.1,    A=0.1,    A=514,    A=1,    A=0.02,    A=0.02,    A=1e-05,    A=1,    A=0,    A=2,    A="absolute",    A=True,    A=768,    **A,    ):

									"""simple docstring"""


									super().__init__(pad_token_id=_UpperCAmelCase,    bos_token_id=_UpperCAmelCase,    eos_token_id=_UpperCAmelCase,    **_UpperCAmelCase      )

									lowerCamelCase					:			Optional[int]									= vocab_size
									lowerCamelCase					:			Optional[Any]									= hidden_size
									lowerCamelCase					:			Dict									= num_hidden_layers
									lowerCamelCase					:			Tuple									= num_attention_heads
									lowerCamelCase					:			Union[str, Any]									= hidden_act
									lowerCamelCase					:			Union[str, Any]									= intermediate_size
									lowerCamelCase					:			Optional[Any]									= hidden_dropout_prob
									lowerCamelCase					:			Tuple									= attention_probs_dropout_prob
									lowerCamelCase					:			List[str]									= max_position_embeddings
									lowerCamelCase					:			Tuple									= type_vocab_size
									lowerCamelCase					:			Any									= initializer_range
									lowerCamelCase					:			Optional[int]									= initializer_factor
									lowerCamelCase					:			Any									= layer_norm_eps
									lowerCamelCase					:			int									= position_embedding_type
									lowerCamelCase					:			List[Any]									= use_cache
									lowerCamelCase					:			Tuple									= project_dim





class     __snake_case		(   _UpperCamelCase):
					_lowerCAmelCase			     =	'''altclip_vision_model'''
					def __init__(     self,    A=768,    A=3072,    A=512,    A=12,    A=12,    A=3,    A=224,    A=32,    A="quick_gelu",    A=1e-5,    A=0.0,    A=0.02,    A=1.0,    **A,    ):

									"""simple docstring"""


									super().__init__(**_UpperCAmelCase      )

									lowerCamelCase					:			Union[str, Any]									= hidden_size
									lowerCamelCase					:			int									= intermediate_size
									lowerCamelCase					:			Optional[int]									= projection_dim
									lowerCamelCase					:			List[Any]									= num_hidden_layers
									lowerCamelCase					:			Optional[Any]									= num_attention_heads
									lowerCamelCase					:			int									= num_channels
									lowerCamelCase					:			List[Any]									= patch_size
									lowerCamelCase					:			Union[str, Any]									= image_size
									lowerCamelCase					:			Dict									= initializer_range
									lowerCamelCase					:			Any									= initializer_factor
									lowerCamelCase					:			Union[str, Any]									= attention_dropout
									lowerCamelCase					:			List[str]									= layer_norm_eps
									lowerCamelCase					:			Optional[int]									= hidden_act




					@classmethod
					def     UpperCAmelCase_							(     cls,    A,    **A      ):

									"""simple docstring"""


									cls._set_token_in_kwargs(_UpperCAmelCase      )

									lowerCamelCase					:			Any									= cls.get_config_dict(_UpperCAmelCase,    **_UpperCAmelCase      )

									# get the vision config dict if we are loading from AltCLIPConfig
									if config_dict.get('model_type'      ) == "altclip":
													lowerCamelCase					:			Any									= config_dict['''vision_config''']

									if "model_type" in config_dict and hasattr(cls,    'model_type'      ) and config_dict["model_type"] != cls.model_type:
													logger.warning(
													    F'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
													    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''      )

									return cls.from_dict(_UpperCAmelCase,    **_UpperCAmelCase      )





class     __snake_case		(   _UpperCamelCase):
					_lowerCAmelCase			     =	'''altclip'''
					_lowerCAmelCase			     =	True
					def __init__(     self,    A=None,    A=None,    A=768,    A=2.6592,    **A      ):

									"""simple docstring"""


									lowerCamelCase					:			List[Any]									= kwargs.pop('text_config_dict',    _UpperCAmelCase      )
									lowerCamelCase					:			str									= kwargs.pop('vision_config_dict',    _UpperCAmelCase      )

									super().__init__(**_UpperCAmelCase      )

									# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
									# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
									# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
									if text_config_dict is not None:
													if text_config is None:
																	lowerCamelCase					:			int									= {}

													# This is the complete result when using `text_config_dict`.
													lowerCamelCase					:			str									= AltCLIPTextConfig(**_UpperCAmelCase      ).to_dict()

													# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
													for key, value in _text_config_dict.items():
																	if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
																					# If specified in `text_config_dict`
																					if key in text_config_dict:
																									lowerCamelCase					:			Optional[Any]									= (
																									    F'''`{key}` is found in both `text_config_dict` and `text_config` but with different values. '''
																									    F'''The value `text_config_dict[\"{key}\"]` will be used instead.'''
																									)
																					# If inferred from default argument values (just to be super careful)
																					else:
																									lowerCamelCase					:			int									= (
																									    F'''`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '''
																									    F'''value `text_config[\"{key}\"]` will be overriden.'''
																									)
																					logger.warning(_UpperCAmelCase      )

            # Update all values in `text_config` with the ones in `_text_config_dict`.
													text_config.update(_text_config_dict      )

									if vision_config_dict is not None:
													if vision_config is None:
																	lowerCamelCase					:			Tuple									= {}

													# This is the complete result when using `vision_config_dict`.
													lowerCamelCase					:			Optional[Any]									= AltCLIPVisionConfig(**_UpperCAmelCase      ).to_dict()
													# convert keys to string instead of integer
													if "id2label" in _vision_config_dict:
																	lowerCamelCase					:			Optional[int]									= {
																	    str(_UpperCAmelCase      ): value for key, value in _vision_config_dict['''id2label'''].items()
																	}

													# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
													for key, value in _vision_config_dict.items():
																	if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
																					# If specified in `vision_config_dict`
																					if key in vision_config_dict:
																									lowerCamelCase					:			str									= (
																									    F'''`{key}` is found in both `vision_config_dict` and `vision_config` but with different '''
																									    F'''values. The value `vision_config_dict[\"{key}\"]` will be used instead.'''
																									)
																					# If inferred from default argument values (just to be super careful)
																					else:
																									lowerCamelCase					:			Optional[Any]									= (
																									    F'''`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '''
																									    F'''The value `vision_config[\"{key}\"]` will be overriden.'''
																									)
																					logger.warning(_UpperCAmelCase      )

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
													vision_config.update(_vision_config_dict      )

									if text_config is None:
													lowerCamelCase					:			Dict									= {}
													logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'      )

									if vision_config is None:
													lowerCamelCase					:			Any									= {}
													logger.info('`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'      )

									lowerCamelCase					:			Optional[Any]									= AltCLIPTextConfig(**_UpperCAmelCase      )
									lowerCamelCase					:			Dict									= AltCLIPVisionConfig(**_UpperCAmelCase      )

									lowerCamelCase					:			Dict									= projection_dim
									lowerCamelCase					:			int									= logit_scale_init_value
									lowerCamelCase					:			int									= 1.0
					@classmethod
					def     UpperCAmelCase_							(     cls,    A,    A,    **A      ):

									"""simple docstring"""


									return cls(text_config=text_config.to_dict(),    vision_config=vision_config.to_dict(),    **_UpperCAmelCase      )




					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= copy.deepcopy(self.__dict__      )
									lowerCamelCase					:			int									= self.text_config.to_dict()
									lowerCamelCase					:			List[str]									= self.vision_config.to_dict()
									lowerCamelCase					:			List[str]									= self.__class__.model_type
									return output


'''simple docstring'''






from manim import *




class     __snake_case		(   a__):
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[int]									= Rectangle(height=0.5,    width=0.5      )
									lowerCamelCase					:			List[Any]									= Rectangle(height=0.46,    width=0.46      ).set_stroke(width=0      )

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

									lowerCamelCase					:			Optional[int]									= [mem.copy() for i in range(1      )]
									lowerCamelCase					:			Union[str, Any]									= VGroup(*A      ).arrange(A,    buff=0      )
									lowerCamelCase					:			Optional[Any]									= Text('GPU',    font_size=24      )
									lowerCamelCase					:			Tuple									= Group(A,    A      ).arrange(A,    buff=0.5,    aligned_edge=A      )
									gpu.align_to(A,    A      )
									gpu.set_x(gpu.get_x() - 1      )

									self.add(A      )

									lowerCamelCase					:			Optional[int]									= [mem.copy() for i in range(6      )]
									lowerCamelCase					:			Optional[Any]									= VGroup(*A      ).arrange(A,    buff=0      )

									lowerCamelCase					:			Any									= Text('Model',    font_size=24      )
									lowerCamelCase					:			Tuple									= Group(A,    A      ).arrange(A,    buff=0.5,    aligned_edge=A      )
									model.move_to([3, -1.0, 0]      )

									self.play(
									    Create(A,    run_time=1      ),    Create(A,    run_time=1      ),    Create(A,    run_time=1      ),    )

									lowerCamelCase					:			str									= MarkupText(
									    F'''First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.''',    font_size=24,    )

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

									lowerCamelCase					:			Tuple									= MarkupText(
									    F'''<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model''',    font_size=18,    )

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

									step_a.move_to([2, 2, 0]      )
									self.play(Write(A,    run_time=2.5      ),    Write(A      ),    Write(A      )      )

									self.add(A      )

									lowerCamelCase					:			str									= []
									lowerCamelCase					:			Optional[int]									= []
									lowerCamelCase					:			Optional[Any]									= []
									for i, rect in enumerate(A      ):
													lowerCamelCase					:			List[str]									= Rectangle(height=0.46,    width=0.46      ).set_stroke(width=0.0      ).set_fill(A,    opacity=0.7      )
													cpu_target.move_to(A      )
													cpu_target.generate_target()
													lowerCamelCase					:			int									= 0.46 / 4
													lowerCamelCase					:			Optional[int]									= 0.46 / 3

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

													first_animations.append(rect.animate(run_time=0.5      ).set_stroke(A      )      )
													second_animations.append(MoveToTarget(A,    run_time=1.5      )      )

									self.play(*A      )
									self.play(*A      )

									self.wait()
