


"""simple docstring"""



import json
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

   if is_vision_available():
      from transformers import OneFormerImageProcessor
      from transformers.models.oneformer.image_processing_oneformer import binary_mask_to_rle
      from transformers.models.oneformer.modeling_oneformer import OneFormerForUniversalSegmentationOutput

if is_vision_available():
   from PIL import Image







def   __lowerCAmelCase						(						lowercase  :  Optional[Any]						,							lowercase  :  List[str]="shi-labs/oneformer_demo"			)     ->						Optional[Any]:


    """simple docstring"""





    with open(hf_hub_download(snake_case__						,							snake_case__						,							repo_type="dataset"			)						,							"r"			) as f:
        snake_case   :				str				 =   json.load(snake_case__			)
    snake_case   :				Dict				 =   {}
    snake_case   :				Dict				 =   []
    snake_case   :				List[Any]				 =   []
    for key, info in class_info.items():
        snake_case   :				Optional[int]				 =   info["name"]
        class_names.append(info["name"]			)
        if info["isthing"]:
            thing_ids.append(int(snake_case__			)			)
    snake_case   :				Dict				 =   thing_ids
    snake_case   :				int				 =   class_names
    return metadata







class _lowerCAmelCase    (				unittest.TestCase     ):







   def __init__(     self						,     UpperCamelCase__						,     UpperCamelCase__=7						,     UpperCamelCase__=3						,     UpperCamelCase__=30						,     UpperCamelCase__=400						,     UpperCamelCase__=None						,     UpperCamelCase__=True						,     UpperCamelCase__=True						,     UpperCamelCase__=[0.5, 0.5, 0.5]						,     UpperCamelCase__=[0.5, 0.5, 0.5]						,     UpperCamelCase__=10						,     UpperCamelCase__=False						,     UpperCamelCase__=255						,     UpperCamelCase__="shi-labs/oneformer_demo"						,     UpperCamelCase__="ade20k_panoptic.json"						,     UpperCamelCase__=10						,     )     ->		Optional[Any]:

       '''simple docstring'''




       snake_case   :				Optional[int]				 =   parent
       snake_case   :				List[str]				 =   batch_size
       snake_case   :				Optional[int]				 =   num_channels
       snake_case   :				Optional[Any]				 =   min_resolution
       snake_case   :				Union[str, Any]				 =   max_resolution
       snake_case   :				int				 =   do_resize
       snake_case   :				str				 =   {"shortest_edge": 32, "longest_edge": 1333} if size is None else size
       snake_case   :				List[Any]				 =   do_normalize
       snake_case   :				Dict				 =   image_mean
       snake_case   :				str				 =   image_std
       snake_case   :				Any				 =   class_info_file
       snake_case   :				str				 =   prepare_metadata(lowerCAmelCase_						,     lowerCAmelCase_						)
       snake_case   :				Union[str, Any]				 =   num_text
       snake_case   :				List[Any]				 =   repo_path

       # for the post_process_functions
       snake_case   :				Dict				 =   2
       snake_case   :				Dict				 =   10
       snake_case   :				Tuple				 =   10
       snake_case   :				Tuple				 =   3
       snake_case   :				List[str]				 =   4
       snake_case   :				List[str]				 =   num_labels
       snake_case   :				Optional[int]				 =   do_reduce_labels
       snake_case   :				Union[str, Any]				 =   ignore_index







   def 			lowerCamelCase		(     self						)     ->		List[str]:

       '''simple docstring'''




       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "num_labels": self.num_labels,
           "do_reduce_labels": self.do_reduce_labels,
           "ignore_index": self.ignore_index,
           "class_info_file": self.class_info_file,
           "metadata": self.metadata,
           "num_text": self.num_text,
       }







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						,     UpperCamelCase__=False						)     ->		Any:

       '''simple docstring'''




       if not batched:
           snake_case   :				Optional[int]				 =   image_inputs[0]
           if isinstance(lowerCAmelCase_						,     Image.Image						):
               snake_case ,snake_case   :				int				 =   image.size
           else:
               snake_case ,snake_case   :				int				 =   image.shape[1], image.shape[2]
           if w < h:
               snake_case   :				Tuple				 =   int(self.size["shortest_edge"] * h / w						)
               snake_case   :				str				 =   self.size["shortest_edge"]
           elif w > h:
               snake_case   :				Tuple				 =   self.size["shortest_edge"]
               snake_case   :				List[str]				 =   int(self.size["shortest_edge"] * w / h						)
           else:
               snake_case   :				List[str]				 =   self.size["shortest_edge"]
               snake_case   :				Dict				 =   self.size["shortest_edge"]

       else:
           snake_case   :				Optional[Any]				 =   []
           for image in image_inputs:
               snake_case ,snake_case   :				Union[str, Any]				 =   self.get_expected_values([image]						)
               expected_values.append((expected_height, expected_width)						)
           snake_case   :				Optional[Any]				 =   max(lowerCAmelCase_						,     key=lambda UpperCamelCase__						: item[0]						)[0]
           snake_case   :				int				 =   max(lowerCAmelCase_						,     key=lambda UpperCamelCase__						: item[1]						)[1]

       return expected_height, expected_width







   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       return OneFormerForUniversalSegmentationOutput(
           # +1 for null class
           class_queries_logits=torch.randn((self.batch_size, self.num_queries, self.num_classes + 1)						)						,     masks_queries_logits=torch.randn((self.batch_size, self.num_queries, self.height, self.width)						)						,     )







@require_torch
@require_vision
class _lowerCAmelCase    (				__lowerCAmelCase   ,							unittest.TestCase     ):
   __UpperCAmelCase			:	Optional[int]							  =  OneFormerImageProcessor if (is_vision_available() and is_torch_available()) else None
   # only for test_image_processing_common.test_image_proc_to_json_string
   __UpperCAmelCase			:	Any							  =  image_processing_class







   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       snake_case   :				Optional[Any]				 =   OneFormerImageProcessorTester(self						)







   @property
   def 			lowerCamelCase		(     self						)     ->		List[str]:

       '''simple docstring'''




       return self.image_processing_tester.prepare_image_processor_dict()







   def 			lowerCamelCase		(     self						)     ->		Union[str, Any]:

       '''simple docstring'''




       snake_case   :				Optional[int]				 =   self.image_processing_class(**self.image_processor_dict						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "image_mean"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "image_std"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "do_normalize"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "do_resize"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "size"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "ignore_index"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "class_info_file"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "num_text"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "repo_path"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "metadata"						)						)
       self.assertTrue(hasattr(lowerCAmelCase_						,     "do_reduce_labels"						)						)







   def 			lowerCamelCase		(     self						)     ->		str:

       '''simple docstring'''




       pass







   def 			lowerCamelCase		(     self						)     ->		Optional[int]:

       '''simple docstring'''




       snake_case   :				Tuple				 =   self.image_processing_class(**self.image_processor_dict						)
       # create random PIL images
       snake_case   :				int				 =   prepare_image_inputs(self.image_processing_tester						,     equal_resolution=lowerCAmelCase_						)
       for image in image_inputs:
           self.assertIsInstance(lowerCAmelCase_						,     Image.Image						)

       # Test not batched input
       snake_case   :				str				 =   image_processor(image_inputs[0]						,     ["semantic"]						,     return_tensors="pt"						).pixel_values

       snake_case ,snake_case   :				Tuple				 =   self.image_processing_tester.get_expected_values(lowerCAmelCase_						)

       self.assertEqual(
           encoded_images.shape						,     (1, self.image_processing_tester.num_channels, expected_height, expected_width)						,     )

       # Test batched
       snake_case ,snake_case   :				Any				 =   self.image_processing_tester.get_expected_values(lowerCAmelCase_						,     batched=lowerCAmelCase_						)

       snake_case   :				List[str]				 =   image_processor(
           lowerCAmelCase_						,     ["semantic"] * len(lowerCAmelCase_						)						,     return_tensors="pt"						).pixel_values
       self.assertEqual(
           encoded_images.shape						,     (
               self.image_processing_tester.batch_size,
               self.image_processing_tester.num_channels,
               expected_height,
               expected_width,
           )						,     )







   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       snake_case   :				List[Any]				 =   self.image_processing_class(**self.image_processor_dict						)
       # create random numpy tensors
       snake_case   :				List[str]				 =   prepare_image_inputs(self.image_processing_tester						,     equal_resolution=lowerCAmelCase_						,     numpify=lowerCAmelCase_						)
       for image in image_inputs:
           self.assertIsInstance(lowerCAmelCase_						,     np.ndarray						)

       # Test not batched input
       snake_case   :				Union[str, Any]				 =   image_processor(image_inputs[0]						,     ["semantic"]						,     return_tensors="pt"						).pixel_values

       snake_case ,snake_case   :				List[str]				 =   self.image_processing_tester.get_expected_values(lowerCAmelCase_						)

       self.assertEqual(
           encoded_images.shape						,     (1, self.image_processing_tester.num_channels, expected_height, expected_width)						,     )

       # Test batched
       snake_case ,snake_case   :				int				 =   self.image_processing_tester.get_expected_values(lowerCAmelCase_						,     batched=lowerCAmelCase_						)

       snake_case   :				List[Any]				 =   image_processor(
           lowerCAmelCase_						,     ["semantic"] * len(lowerCAmelCase_						)						,     return_tensors="pt"						).pixel_values
       self.assertEqual(
           encoded_images.shape						,     (
               self.image_processing_tester.batch_size,
               self.image_processing_tester.num_channels,
               expected_height,
               expected_width,
           )						,     )







   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       snake_case   :				Optional[int]				 =   self.image_processing_class(**self.image_processor_dict						)
       # create random PyTorch tensors
       snake_case   :				List[str]				 =   prepare_image_inputs(self.image_processing_tester						,     equal_resolution=lowerCAmelCase_						,     torchify=lowerCAmelCase_						)
       for image in image_inputs:
           self.assertIsInstance(lowerCAmelCase_						,     torch.Tensor						)

       # Test not batched input
       snake_case   :				str				 =   image_processor(image_inputs[0]						,     ["semantic"]						,     return_tensors="pt"						).pixel_values

       snake_case ,snake_case   :				List[Any]				 =   self.image_processing_tester.get_expected_values(lowerCAmelCase_						)

       self.assertEqual(
           encoded_images.shape						,     (1, self.image_processing_tester.num_channels, expected_height, expected_width)						,     )

       # Test batched
       snake_case ,snake_case   :				Optional[int]				 =   self.image_processing_tester.get_expected_values(lowerCAmelCase_						,     batched=lowerCAmelCase_						)

       snake_case   :				Optional[int]				 =   image_processor(
           lowerCAmelCase_						,     ["semantic"] * len(lowerCAmelCase_						)						,     return_tensors="pt"						).pixel_values
       self.assertEqual(
           encoded_images.shape						,     (
               self.image_processing_tester.batch_size,
               self.image_processing_tester.num_channels,
               expected_height,
               expected_width,
           )						,     )







   def 			lowerCamelCase		(     self						,     UpperCamelCase__=False						,     UpperCamelCase__=False						,     UpperCamelCase__="np"						)     ->		Optional[Any]:

       '''simple docstring'''




       snake_case   :				List[Any]				 =   self.image_processing_class(**self.image_processor_dict						)
       # prepare image and target
       snake_case   :				int				 =   self.image_processing_tester.num_labels
       snake_case   :				Optional[int]				 =   None
       snake_case   :				Optional[int]				 =   None
       snake_case   :				Optional[int]				 =   prepare_image_inputs(self.image_processing_tester						,     equal_resolution=lowerCAmelCase_						)
       if with_segmentation_maps:
           snake_case   :				Union[str, Any]				 =   num_labels
           if is_instance_map:
               snake_case   :				Dict				 =   list(range(lowerCAmelCase_						)						) * 2
               snake_case   :				Any				 =   dict(enumerate(lowerCAmelCase_						)						)
           snake_case   :				Optional[int]				 =   [
               np.random.randint(0						,     high * 2						,     (img.size[1], img.size[0])						).astype(np.uinta						) for img in image_inputs
           ]
           if segmentation_type == "pil":
               snake_case   :				Dict				 =   [Image.fromarray(lowerCAmelCase_						) for annotation in annotations]

       snake_case   :				Tuple				 =   image_processor(
           lowerCAmelCase_						,     ["semantic"] * len(lowerCAmelCase_						)						,     lowerCAmelCase_						,     return_tensors="pt"						,     instance_id_to_semantic_id=lowerCAmelCase_						,     pad_and_return_pixel_mask=lowerCAmelCase_						,     )

       return inputs







   def 			lowerCamelCase		(     self						)     ->		List[str]:

       '''simple docstring'''




       pass







   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       def common(UpperCamelCase__=False						,     UpperCamelCase__=None						):
           snake_case   :				List[str]				 =   self.comm_get_image_processor_inputs(
               with_segmentation_maps=lowerCAmelCase_						,     is_instance_map=lowerCAmelCase_						,     segmentation_type=lowerCAmelCase_						)

           snake_case   :				int				 =   inputs["mask_labels"]
           snake_case   :				Optional[int]				 =   inputs["class_labels"]
           snake_case   :				Union[str, Any]				 =   inputs["pixel_values"]
           snake_case   :				Any				 =   inputs["text_inputs"]

           # check the batch_size
           for mask_label, class_label, text_input in zip(lowerCAmelCase_						,     lowerCAmelCase_						,     lowerCAmelCase_						):
               self.assertEqual(mask_label.shape[0]						,     class_label.shape[0]						)
               # this ensure padding has happened
               self.assertEqual(mask_label.shape[1:]						,     pixel_values.shape[2:]						)
               self.assertEqual(len(lowerCAmelCase_						)						,     self.image_processing_tester.num_text						)

       common()
       common(is_instance_map=lowerCAmelCase_						)
       common(is_instance_map=lowerCAmelCase_						,     segmentation_type="pil"						)
       common(is_instance_map=lowerCAmelCase_						,     segmentation_type="pil"						)







   def 			lowerCamelCase		(     self						)     ->		Optional[int]:

       '''simple docstring'''




       snake_case   :				int				 =   np.zeros((20, 50)						)
       snake_case   :				str				 =   1
       snake_case   :				List[Any]				 =   1
       snake_case   :				List[Any]				 =   1

       snake_case   :				Optional[Any]				 =   binary_mask_to_rle(lowerCAmelCase_						)
       self.assertEqual(len(lowerCAmelCase_						)						,     4						)
       self.assertEqual(rle[0]						,     21						)
       self.assertEqual(rle[1]						,     45						)







   def 			lowerCamelCase		(     self						)     ->		List[Any]:

       '''simple docstring'''




       snake_case   :				Dict				 =   self.image_processing_class(
           num_labels=self.image_processing_tester.num_classes						,     max_seq_length=77						,     task_seq_length=77						,     class_info_file="ade20k_panoptic.json"						,     num_text=self.image_processing_tester.num_text						,     repo_path="shi-labs/oneformer_demo"						,     )
       snake_case   :				Optional[Any]				 =   self.image_processing_tester.get_fake_oneformer_outputs()

       snake_case   :				Any				 =   fature_extractor.post_process_semantic_segmentation(lowerCAmelCase_						)

       self.assertEqual(len(lowerCAmelCase_						)						,     self.image_processing_tester.batch_size						)
       self.assertEqual(
           segmentation[0].shape						,     (
               self.image_processing_tester.height,
               self.image_processing_tester.width,
           )						,     )

       snake_case   :				int				 =   [(1, 4) for i in range(self.image_processing_tester.batch_size						)]
       snake_case   :				List[str]				 =   fature_extractor.post_process_semantic_segmentation(lowerCAmelCase_						,     target_sizes=lowerCAmelCase_						)

       self.assertEqual(segmentation[0].shape						,     target_sizes[0]						)







   def 			lowerCamelCase		(     self						)     ->		Dict:

       '''simple docstring'''




       snake_case   :				Tuple				 =   self.image_processing_class(
           num_labels=self.image_processing_tester.num_classes						,     max_seq_length=77						,     task_seq_length=77						,     class_info_file="ade20k_panoptic.json"						,     num_text=self.image_processing_tester.num_text						,     repo_path="shi-labs/oneformer_demo"						,     )
       snake_case   :				int				 =   self.image_processing_tester.get_fake_oneformer_outputs()
       snake_case   :				Any				 =   image_processor.post_process_instance_segmentation(lowerCAmelCase_						,     threshold=0						)

       self.assertTrue(len(lowerCAmelCase_						) == self.image_processing_tester.batch_size						)
       for el in segmentation:
           self.assertTrue("segmentation" in el						)
           self.assertTrue("segments_info" in el						)
           self.assertEqual(type(el["segments_info"]						)						,     lowerCAmelCase_						)
           self.assertEqual(
               el["segmentation"].shape						,     (self.image_processing_tester.height, self.image_processing_tester.width)						)







   def 			lowerCamelCase		(     self						)     ->		Optional[int]:

       '''simple docstring'''




       snake_case   :				Tuple				 =   self.image_processing_class(
           num_labels=self.image_processing_tester.num_classes						,     max_seq_length=77						,     task_seq_length=77						,     class_info_file="ade20k_panoptic.json"						,     num_text=self.image_processing_tester.num_text						,     repo_path="shi-labs/oneformer_demo"						,     )
       snake_case   :				Optional[Any]				 =   self.image_processing_tester.get_fake_oneformer_outputs()
       snake_case   :				Any				 =   image_processor.post_process_panoptic_segmentation(lowerCAmelCase_						,     threshold=0						)

       self.assertTrue(len(lowerCAmelCase_						) == self.image_processing_tester.batch_size						)
       for el in segmentation:
           self.assertTrue("segmentation" in el						)
           self.assertTrue("segments_info" in el						)
           self.assertEqual(type(el["segments_info"]						)						,     lowerCAmelCase_						)
           self.assertEqual(
               el["segmentation"].shape						,     (self.image_processing_tester.height, self.image_processing_tester.width)						)









"""simple docstring"""



import copy
import os
from typing import Union

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


__snake_case             =   logging.get_logger(__name__)

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







class _lowerCAmelCase    (				snake_case_     ):
   __UpperCAmelCase			:	Tuple							  =  '''altclip_text_model'''







   def __init__(     self						,     UpperCamelCase__=25_0002						,     UpperCamelCase__=1024						,     UpperCamelCase__=24						,     UpperCamelCase__=16						,     UpperCamelCase__=4096						,     UpperCamelCase__="gelu"						,     UpperCamelCase__=0.1						,     UpperCamelCase__=0.1						,     UpperCamelCase__=514						,     UpperCamelCase__=1						,     UpperCamelCase__=0.02						,     UpperCamelCase__=0.02						,     UpperCamelCase__=1e-05						,     UpperCamelCase__=1						,     UpperCamelCase__=0						,     UpperCamelCase__=2						,     UpperCamelCase__="absolute"						,     UpperCamelCase__=True						,     UpperCamelCase__=768						,     **UpperCamelCase__						,     )     ->		Optional[int]:

       '''simple docstring'''




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

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







class _lowerCAmelCase    (				snake_case_     ):
   __UpperCAmelCase			:	Tuple							  =  '''altclip_vision_model'''







   def __init__(     self						,     UpperCamelCase__=768						,     UpperCamelCase__=3072						,     UpperCamelCase__=512						,     UpperCamelCase__=12						,     UpperCamelCase__=12						,     UpperCamelCase__=3						,     UpperCamelCase__=224						,     UpperCamelCase__=32						,     UpperCamelCase__="quick_gelu"						,     UpperCamelCase__=1e-5						,     UpperCamelCase__=0.0						,     UpperCamelCase__=0.02						,     UpperCamelCase__=1.0						,     **UpperCamelCase__						,     )     ->		str:

       '''simple docstring'''




       super().__init__(**UpperCamelCase__						)

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







   @classmethod
   def 			lowerCamelCase		(     cls						,     UpperCamelCase__						,     **UpperCamelCase__						)     ->		"PretrainedConfig":

       '''simple docstring'''




       cls._set_token_in_kwargs(UpperCamelCase__						)

       snake_case ,snake_case   :				str				 =   cls.get_config_dict(UpperCamelCase__						,     **UpperCamelCase__						)

       # get the vision config dict if we are loading from AltCLIPConfig
       if config_dict.get("model_type"						) == "altclip":
           snake_case   :				Optional[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 _lowerCAmelCase    (				snake_case_     ):
   __UpperCAmelCase			:	str							  =  '''altclip'''
   __UpperCAmelCase			:	Optional[Any]							  =  True







   def __init__(     self						,     UpperCamelCase__=None						,     UpperCamelCase__=None						,     UpperCamelCase__=768						,     UpperCamelCase__=2.6592						,     **UpperCamelCase__						)     ->		Any:

       '''simple docstring'''




       snake_case   :				List[str]				 =   kwargs.pop("text_config_dict"						,     UpperCamelCase__						)
       snake_case   :				Union[str, Any]				 =   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:
               snake_case   :				List[str]				 =   {}

           # This is the complete result when using `text_config_dict`.
           snake_case   :				Dict				 =   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:
                       snake_case   :				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:
                       snake_case   :				Any				 =   (
                           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:
               snake_case   :				Union[str, Any]				 =   {}

           # This is the complete result when using `vision_config_dict`.
           snake_case   :				int				 =   AltCLIPVisionConfig(**UpperCamelCase__						).to_dict()
           # convert keys to string instead of integer
           if "id2label" in _vision_config_dict:
               snake_case   :				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:
                       snake_case   :				int				 =   (
                           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:
                       snake_case   :				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:
           snake_case   :				Optional[int]				 =   {}
           logger.info("`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."						)

       if vision_config is None:
           snake_case   :				Dict				 =   {}
           logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."						)

       snake_case   :				Dict				 =   AltCLIPTextConfig(**UpperCamelCase__						)
       snake_case   :				Tuple				 =   AltCLIPVisionConfig(**UpperCamelCase__						)

       snake_case   :				int				 =   projection_dim
       snake_case   :				List[str]				 =   logit_scale_init_value
       snake_case   :				int				 =   1.0







   @classmethod
   def 			lowerCamelCase		(     cls						,     UpperCamelCase__						,     UpperCamelCase__						,     **UpperCamelCase__						)     ->		Union[str, Any]:

       '''simple docstring'''




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







   def 			lowerCamelCase		(     self						)     ->		Optional[Any]:

       '''simple docstring'''




       snake_case   :				Tuple				 =   copy.deepcopy(self.__dict__						)
       snake_case   :				Optional[int]				 =   self.text_config.to_dict()
       snake_case   :				str				 =   self.vision_config.to_dict()
       snake_case   :				Optional[int]				 =   self.__class__.model_type
       return output





