





"""simple docstring"""





import itertools
import json
import os
import unittest

from transformers import AddedToken, LongformerTokenizer, LongformerTokenizerFast
from transformers.models.longformer.tokenization_longformer import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class 		SCREAMING_SNAKE_CASE_				(     snake_case__							,	unittest.TestCase ):
				"""simple docstring"""
				__snake_case :							Optional[int]									=		LongformerTokenizer
				__snake_case :							Any									=		True
				__snake_case :							int									=		LongformerTokenizerFast
				__snake_case :							Union[str, Any]									=		True




				def        __lowercase	(  self	:int      ):
											super().setUp()

											# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
											__lowerCamelCase   :   str       =[
											    '''l''',
											    '''o''',
											    '''w''',
											    '''e''',
											    '''r''',
											    '''s''',
											    '''t''',
											    '''i''',
											    '''d''',
											    '''n''',
											    '''\u0120''',
											    '''\u0120l''',
											    '''\u0120n''',
											    '''\u0120lo''',
											    '''\u0120low''',
											    '''er''',
											    '''\u0120lowest''',
											    '''\u0120newer''',
											    '''\u0120wider''',
											    '''<unk>''',
											]
											__lowerCamelCase   :   Optional[Any]       =dict(zip(__lowercase    ,     range(len(__lowercase      )      )      )      )
											__lowerCamelCase   :   str       =['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
											__lowerCamelCase   :   int       ={'''unk_token''': '''<unk>'''}

											__lowerCamelCase   :   List[Any]       =os.path.join(self.tmpdirname    ,     VOCAB_FILES_NAMES['''vocab_file''']      )
											__lowerCamelCase   :   int       =os.path.join(self.tmpdirname    ,     VOCAB_FILES_NAMES['''merges_file''']      )
											with open(self.vocab_file    ,     '''w'''    ,     encoding='''utf-8'''      ) as fp:
																		fp.write(json.dumps(__lowercase      ) + '''\n'''      )
											with open(self.merges_file    ,     '''w'''    ,     encoding='''utf-8'''      ) as fp:
																		fp.write('''\n'''.join(__lowercase      )      )




				def        __lowercase	(  self	:Optional[int]    ,     **__lowercase	:int      ):
											kwargs.update(self.special_tokens_map      )
											return self.tokenizer_class.from_pretrained(self.tmpdirname    ,     **__lowercase      )




				def        __lowercase	(  self	:int    ,     **__lowercase	:str      ):
											kwargs.update(self.special_tokens_map      )
											return self.rust_tokenizer_class.from_pretrained(self.tmpdirname    ,     **__lowercase      )




				def        __lowercase	(  self	:Union[str, Any]    ,     __lowercase	:List[str]      ):
											__lowerCamelCase   :   List[Any]       ='''lower newer'''
											__lowerCamelCase   :   Tuple       ='''lower newer'''
											return input_text, output_text




				def        __lowercase	(  self	:Any      ):
											__lowerCamelCase   :   Optional[int]       =self.tokenizer_class(self.vocab_file    ,     self.merges_file    ,     **self.special_tokens_map      )
											__lowerCamelCase   :   List[str]       ='''lower newer'''
											__lowerCamelCase   :   Optional[int]       =['''l''', '''o''', '''w''', '''er''', '''\u0120''', '''n''', '''e''', '''w''', '''er''']
											__lowerCamelCase   :   str       =tokenizer.tokenize(__lowercase      )  # , add_prefix_space=True)
											self.assertListEqual(__lowercase    ,     __lowercase      )

											__lowerCamelCase   :   Dict       =tokens + [tokenizer.unk_token]
											__lowerCamelCase   :   str       =[0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
											self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowercase      )    ,     __lowercase      )




				def        __lowercase	(  self	:Any      ):
											__lowerCamelCase   :   Union[str, Any]       =self.get_tokenizer()

											self.assertListEqual(tokenizer.encode('''Hello world!'''    ,     add_special_tokens=__lowercase      )    ,     [0, 3_1414, 232, 328, 2]      )
											self.assertListEqual(
											    tokenizer.encode('''Hello world! cécé herlolip 418'''    ,     add_special_tokens=__lowercase      )    ,     [0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]    ,     )




				@slow
				def        __lowercase	(  self	:Tuple      ):
											__lowerCamelCase   :   List[Any]       =self.tokenizer_class.from_pretrained('''allenai/longformer-base-4096'''      )

											__lowerCamelCase   :   Optional[int]       =tokenizer.encode('''sequence builders'''    ,     add_special_tokens=__lowercase      )
											__lowerCamelCase   :   Tuple       =tokenizer.encode('''multi-sequence build'''    ,     add_special_tokens=__lowercase      )

											__lowerCamelCase   :   Dict       =tokenizer.encode(
											    '''sequence builders'''    ,     add_special_tokens=__lowercase    ,     add_prefix_space=__lowercase      )
											__lowerCamelCase   :   Optional[int]       =tokenizer.encode(
											    '''sequence builders'''    ,     '''multi-sequence build'''    ,     add_special_tokens=__lowercase    ,     add_prefix_space=__lowercase      )

											__lowerCamelCase   :   Any       =tokenizer.build_inputs_with_special_tokens(__lowercase      )
											__lowerCamelCase   :   int       =tokenizer.build_inputs_with_special_tokens(__lowercase    ,     __lowercase      )

											assert encoded_sentence == encoded_text_from_decode
											assert encoded_pair == encoded_pair_from_decode




				def        __lowercase	(  self	:Dict      ):
											__lowerCamelCase   :   str       =self.get_tokenizer()

											__lowerCamelCase   :   Tuple       ='''Encode this sequence.'''
											__lowerCamelCase   :   List[str]       =tokenizer.byte_encoder[''' '''.encode('''utf-8'''      )[0]]

											# Testing encoder arguments
											__lowerCamelCase   :   Tuple       =tokenizer.encode(__lowercase    ,     add_special_tokens=__lowercase    ,     add_prefix_space=__lowercase      )
											__lowerCamelCase   :   List[str]       =tokenizer.convert_ids_to_tokens(encoded[0]      )[0]
											self.assertNotEqual(__lowercase    ,     __lowercase      )

											__lowerCamelCase   :   int       =tokenizer.encode(__lowercase    ,     add_special_tokens=__lowercase    ,     add_prefix_space=__lowercase      )
											__lowerCamelCase   :   List[Any]       =tokenizer.convert_ids_to_tokens(encoded[0]      )[0]
											self.assertEqual(__lowercase    ,     __lowercase      )

											tokenizer.add_special_tokens({'''bos_token''': '''<s>'''}      )
											__lowerCamelCase   :   Dict       =tokenizer.encode(__lowercase    ,     add_special_tokens=__lowercase      )
											__lowerCamelCase   :   Tuple       =tokenizer.convert_ids_to_tokens(encoded[1]      )[0]
											self.assertNotEqual(__lowercase    ,     __lowercase      )

											# Testing spaces after special tokens
											__lowerCamelCase   :   Tuple       ='''<mask>'''
											tokenizer.add_special_tokens(
											    {'''mask_token''': AddedToken(__lowercase    ,     lstrip=__lowercase    ,     rstrip=__lowercase      )}      )  # mask token has a left space
											__lowerCamelCase   :   str       =tokenizer.convert_tokens_to_ids(__lowercase      )

											__lowerCamelCase   :   Dict       ='''Encode <mask> sequence'''
											__lowerCamelCase   :   Dict       ='''Encode <mask>sequence'''

											__lowerCamelCase   :   List[Any]       =tokenizer.encode(__lowercase      )
											__lowerCamelCase   :   Union[str, Any]       =encoded.index(__lowercase      )
											__lowerCamelCase   :   int       =tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]      )[0]
											self.assertEqual(__lowercase    ,     __lowercase      )

											__lowerCamelCase   :   List[str]       =tokenizer.encode(__lowercase      )
											__lowerCamelCase   :   Union[str, Any]       =encoded.index(__lowercase      )
											__lowerCamelCase   :   Optional[int]       =tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]      )[0]
											self.assertNotEqual(__lowercase    ,     __lowercase      )




				def        __lowercase	(  self	:Tuple      ):
											pass




				def        __lowercase	(  self	:Tuple      ):
											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																		with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'      ):
																									__lowerCamelCase   :   Any       =self.rust_tokenizer_class.from_pretrained(__lowercase    ,     **__lowercase      )
																									__lowerCamelCase   :   int       =self.tokenizer_class.from_pretrained(__lowercase    ,     **__lowercase      )
																									__lowerCamelCase   :   List[str]       ='''A, <mask> AllenNLP sentence.'''
																									__lowerCamelCase   :   int       =tokenizer_r.encode_plus(__lowercase    ,     add_special_tokens=__lowercase    ,     return_token_type_ids=__lowercase      )
																									__lowerCamelCase   :   Tuple       =tokenizer_p.encode_plus(__lowercase    ,     add_special_tokens=__lowercase    ,     return_token_type_ids=__lowercase      )

																									# token_type_ids should put 0 everywhere
																									self.assertEqual(sum(tokens_r['''token_type_ids''']      )    ,     sum(tokens_p['''token_type_ids''']      )      )

																									# attention_mask should put 1 everywhere, so sum over length should be 1
																									self.assertEqual(
																									    sum(tokens_r['''attention_mask''']      ) / len(tokens_r['''attention_mask''']      )    ,     sum(tokens_p['''attention_mask''']      ) / len(tokens_p['''attention_mask''']      )    ,     )

																									__lowerCamelCase   :   Tuple       =tokenizer_r.convert_ids_to_tokens(tokens_r['''input_ids''']      )
																									__lowerCamelCase   :   List[Any]       =tokenizer_p.convert_ids_to_tokens(tokens_p['''input_ids''']      )

																									# Rust correctly handles the space before the mask while python doesnt
																									self.assertSequenceEqual(tokens_p['''input_ids''']    ,     [0, 250, 6, 5_0264, 3823, 487, 2_1992, 3645, 4, 2]      )
																									self.assertSequenceEqual(tokens_r['''input_ids''']    ,     [0, 250, 6, 5_0264, 3823, 487, 2_1992, 3645, 4, 2]      )

																									self.assertSequenceEqual(
																									    __lowercase    ,     ['''<s>''', '''A''', ''',''', '''<mask>''', '''ĠAllen''', '''N''', '''LP''', '''Ġsentence''', '''.''', '''</s>''']      )
																									self.assertSequenceEqual(
																									    __lowercase    ,     ['''<s>''', '''A''', ''',''', '''<mask>''', '''ĠAllen''', '''N''', '''LP''', '''Ġsentence''', '''.''', '''</s>''']      )




				def        __lowercase	(  self	:int      ):
											for trim_offsets, add_prefix_space in itertools.product([True, False]    ,     repeat=2      ):
																		__lowerCamelCase   :   Tuple       =self.rust_tokenizer_class.from_pretrained(
																		    self.tmpdirname    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )

																		__lowerCamelCase   :   str       =json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()      )
																		__lowerCamelCase   :   Dict       =json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()      )

																		self.assertEqual(pre_tokenizer_state['''add_prefix_space''']    ,     __lowercase      )

																		self.assertEqual(post_processor_state['''add_prefix_space''']    ,     __lowercase      )
																		self.assertEqual(post_processor_state['''trim_offsets''']    ,     __lowercase      )




				def        __lowercase	(  self	:Optional[Any]      ):
											# Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space` and
											# `trim_offsets`
											for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																		with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'      ):
																									__lowerCamelCase   :   Dict       ='''hello'''  # `hello` is a token in the vocabulary of `pretrained_name`
																									__lowerCamelCase   :   Tuple       =f'{text_of_1_token} {text_of_1_token}'

																									__lowerCamelCase   :   Optional[int]       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   str       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (0, len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (len(__lowercase      ) + 1, len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )

																									__lowerCamelCase   :   int       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   Any       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (0, len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (len(__lowercase      ) + 1, len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )

																									__lowerCamelCase   :   Union[str, Any]       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   Any       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (0, len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (len(__lowercase      ), len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )

																									__lowerCamelCase   :   Optional[Any]       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   Union[str, Any]       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (0, len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (len(__lowercase      ), len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )

																									__lowerCamelCase   :   Optional[int]       =f' {text}'

																									# tokenizer_r = self.rust_tokenizer_class.from_pretrained(
																									#     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
																									# )
																									# encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
																									# self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
																									# self.assertEqual(
																									#     encoding.offset_mapping[1],
																									#     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
																									# )

																									__lowerCamelCase   :   Any       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   List[str]       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (1, 1 + len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (1 + len(__lowercase      ) + 1, 1 + len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )

																									__lowerCamelCase   :   List[str]       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   Tuple       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (0, 1 + len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (1 + len(__lowercase      ), 1 + len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )

																									__lowerCamelCase   :   str       =self.rust_tokenizer_class.from_pretrained(
																									    __lowercase    ,     use_fast=__lowercase    ,     add_prefix_space=__lowercase    ,     trim_offsets=__lowercase      )
																									__lowerCamelCase   :   Optional[int]       =tokenizer_r(__lowercase    ,     return_offsets_mapping=__lowercase    ,     add_special_tokens=__lowercase      )
																									self.assertEqual(encoding.offset_mapping[0]    ,     (0, 1 + len(__lowercase      ))      )
																									self.assertEqual(
																									    encoding.offset_mapping[1]    ,     (1 + len(__lowercase      ), 1 + len(__lowercase      ) + 1 + len(__lowercase      ))    ,     )











"""simple docstring"""





import copy
import os
from typing import Union

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


_UpperCamelCase					      =   logging.get_logger(__name__)

_UpperCamelCase					      =   {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							Optional[int]									=		"""altclip_text_model"""




				def __init__(  self	:Tuple    ,     __lowercase	:Dict=25_0002    ,     __lowercase	:Union[str, Any]=1024    ,     __lowercase	:Optional[int]=24    ,     __lowercase	:List[Any]=16    ,     __lowercase	:int=4096    ,     __lowercase	:Union[str, Any]="gelu"    ,     __lowercase	:Optional[int]=0.1    ,     __lowercase	:Optional[int]=0.1    ,     __lowercase	:Union[str, Any]=514    ,     __lowercase	:Dict=1    ,     __lowercase	:int=0.02    ,     __lowercase	:Optional[int]=0.02    ,     __lowercase	:Optional[Any]=1e-0_5    ,     __lowercase	:str=1    ,     __lowercase	:Tuple=0    ,     __lowercase	:List[str]=2    ,     __lowercase	:str="absolute"    ,     __lowercase	:Tuple=True    ,     __lowercase	:Optional[int]=768    ,     **__lowercase	:Union[str, Any]    ,     ):
											super().__init__(pad_token_id=__lowercase    ,     bos_token_id=__lowercase    ,     eos_token_id=__lowercase    ,     **__lowercase      )

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

class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							List[Any]									=		"""altclip_vision_model"""




				def __init__(  self	:Dict    ,     __lowercase	:Optional[int]=768    ,     __lowercase	:Dict=3072    ,     __lowercase	:Dict=512    ,     __lowercase	:Optional[Any]=12    ,     __lowercase	:Tuple=12    ,     __lowercase	:Optional[int]=3    ,     __lowercase	:Any=224    ,     __lowercase	:List[Any]=32    ,     __lowercase	:Optional[Any]="quick_gelu"    ,     __lowercase	:Optional[int]=1e-5    ,     __lowercase	:List[Any]=0.0    ,     __lowercase	:Dict=0.02    ,     __lowercase	:Optional[int]=1.0    ,     **__lowercase	:Dict    ,     ):
											super().__init__(**__lowercase      )

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




				@classmethod
				def        __lowercase	(  cls	:str    ,     __lowercase	:Union[str, os.PathLike]    ,     **__lowercase	:Dict      ):
											cls._set_token_in_kwargs(__lowercase      )

											__lowerCamelCase     ,    __lowerCamelCase   :   List[Any]       =cls.get_config_dict(__lowercase    ,     **__lowercase      )

											# get the vision config dict if we are loading from AltCLIPConfig
											if config_dict.get('''model_type'''      ) == "altclip":
																		__lowerCamelCase   :   str       =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(__lowercase    ,     **__lowercase      )

class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							Dict									=		"""altclip"""
				__snake_case :							Optional[Any]									=		True




				def __init__(  self	:Any    ,     __lowercase	:Union[str, Any]=None    ,     __lowercase	:str=None    ,     __lowercase	:Tuple=768    ,     __lowercase	:Any=2.6592    ,     **__lowercase	:Any      ):
											# If `_config_dict` exist, we use them for the backward compatibility.
											# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
											# of confusion!).
											__lowerCamelCase   :   Union[str, Any]       =kwargs.pop('''text_config_dict'''    ,     __lowercase      )
											__lowerCamelCase   :   List[str]       =kwargs.pop('''vision_config_dict'''    ,     __lowercase      )

											super().__init__(**__lowercase      )

											# 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   :   Any       ={}

																		# This is the complete result when using `text_config_dict`.
																		__lowerCamelCase   :   Any       =AltCLIPTextConfig(**__lowercase      ).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   :   Dict       =(
																																							    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   :   Dict       =(
																																							    f'`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '
																																							    f'value `text_config["{key}"]` will be overriden.'
																																							)
																																logger.warning(__lowercase      )

            # 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   :   int       ={}

																		# This is the complete result when using `vision_config_dict`.
																		__lowerCamelCase   :   Dict       =AltCLIPVisionConfig(**__lowercase      ).to_dict()
																		# convert keys to string instead of integer
																		if "id2label" in _vision_config_dict:
																									__lowerCamelCase   :   Any       ={
																									    str(__lowercase      ): 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   :   List[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   :   Union[str, 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(__lowercase      )

            # 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   :   Any       ={}
																		logger.info('''`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'''      )

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

											__lowerCamelCase   :   Any       =AltCLIPTextConfig(**__lowercase      )
											__lowerCamelCase   :   Union[str, Any]       =AltCLIPVisionConfig(**__lowercase      )

											__lowerCamelCase   :   Tuple       =projection_dim
											__lowerCamelCase   :   Tuple       =logit_scale_init_value
											__lowerCamelCase   :   Tuple       =1.0




				@classmethod
				def        __lowercase	(  cls	:Union[str, Any]    ,     __lowercase	:AltCLIPTextConfig    ,     __lowercase	:AltCLIPVisionConfig    ,     **__lowercase	:List[str]      ):
											return cls(text_config=text_config.to_dict()    ,     vision_config=vision_config.to_dict()    ,     **__lowercase      )




				def        __lowercase	(  self	:List[str]      ):
											__lowerCamelCase   :   int       =copy.deepcopy(self.__dict__      )
											__lowerCamelCase   :   int       =self.text_config.to_dict()
											__lowerCamelCase   :   int       =self.vision_config.to_dict()
											__lowerCamelCase   :   Optional[int]       =self.__class__.model_type
											return output




