



import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask


if is_torch_available():
     import torch

     from transformers import BlipTextModel
     from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST



class 		_lowercase		:

   def __init__(   self      :							Dict				, __lowerCAmelCase      :							str				, __lowerCAmelCase      :							List[str]=12				, __lowerCAmelCase      :							Optional[Any]=7				, __lowerCAmelCase      :							Any=True				, __lowerCAmelCase      :							str=True				, __lowerCAmelCase      :							List[str]=True				, __lowerCAmelCase      :							Any=99				, __lowerCAmelCase      :							Optional[Any]=32				, __lowerCAmelCase      :							Optional[Any]=32				, __lowerCAmelCase      :							str=5				, __lowerCAmelCase      :							Optional[Any]=4				, __lowerCAmelCase      :							Tuple=37				, __lowerCAmelCase      :							Any=0.1				, __lowerCAmelCase      :							int=0.1				, __lowerCAmelCase      :							Dict=512				, __lowerCAmelCase      :							Optional[Any]=0.0_2				, __lowerCAmelCase      :							Optional[Any]=0				, __lowerCAmelCase      :							Optional[int]=None				, )							->					Optional[Any]:


    """simple docstring"""






    a							=		parent
    a							=		batch_size
    a							=		seq_length
    a							=		is_training
    a							=		use_input_mask
    a							=		use_labels
    a							=		vocab_size
    a							=		hidden_size
    a							=		projection_dim
    a							=		num_hidden_layers
    a							=		num_attention_heads
    a							=		intermediate_size
    a							=		dropout
    a							=		attention_dropout
    a							=		max_position_embeddings
    a							=		initializer_range
    a							=		scope
    a							=		bos_token_id

   def 		A				(   self      :							int				)							->					Tuple:


    """simple docstring"""






    a							=		ids_tensor([self.batch_size, self.seq_length]				, self.vocab_size				)

    a							=		None
    if self.use_input_mask:
     a							=		random_attention_mask([self.batch_size, self.seq_length]				)

    if input_mask is not None:
     a		,	a							=		input_mask.shape
     a							=		np.random.randint(1				, seq_length - 1				, size=(batch_size,)				)
     for batch_idx, start_index in enumerate(__lowerCAmelCase				):
      a							=		1
      a							=		0

    a							=		self.get_config()

    return config, input_ids, input_mask

   def 		A				(   self      :							str				)							->					Optional[int]:


    """simple docstring"""






    return BlipTextConfig(
        vocab_size=self.vocab_size				, hidden_size=self.hidden_size				, projection_dim=self.projection_dim				, num_hidden_layers=self.num_hidden_layers				, num_attention_heads=self.num_attention_heads				, intermediate_size=self.intermediate_size				, dropout=self.dropout				, attention_dropout=self.attention_dropout				, max_position_embeddings=self.max_position_embeddings				, initializer_range=self.initializer_range				, bos_token_id=self.bos_token_id				, )

   def 		A				(   self      :							List[Any]				, __lowerCAmelCase      :							str				, __lowerCAmelCase      :							List[Any]				, __lowerCAmelCase      :							List[Any]				)							->					Union[str, Any]:


    """simple docstring"""






    a							=		BlipTextModel(config=__lowerCAmelCase				)
    model.to(__lowerCAmelCase				)
    model.eval()
    with torch.no_grad():
     a							=		model(__lowerCAmelCase				, attention_mask=__lowerCAmelCase				)
     a							=		model(__lowerCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape				, (self.batch_size, self.seq_length, self.hidden_size)				)
    self.parent.assertEqual(result.pooler_output.shape				, (self.batch_size, self.hidden_size)				)




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


    """simple docstring"""






    a							=		self.prepare_config_and_inputs()
    a		,	a		,	a							=		config_and_inputs
    a							=		{"input_ids": input_ids, "attention_mask": input_mask}
    return config, inputs_dict



@require_torch
class 		_lowercase		(							UpperCAmelCase__, unittest.TestCase						):
   _UpperCAmelCase  						=      (BlipTextModel,) if is_torch_available() else ()
   _UpperCAmelCase  						=      False
   _UpperCAmelCase  						=      False
   _UpperCAmelCase  						=      False

   def 		A				(   self      :							Dict				)							->					Tuple:


    """simple docstring"""






    a							=		BlipTextModelTester(self				)
    a							=		ConfigTester(self				, config_class=__lowerCAmelCase				, hidden_size=37				)

   def 		A				(   self      :							Optional[Any]				)							->					List[Any]:


    """simple docstring"""






    self.config_tester.run_common_tests()

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


    """simple docstring"""






    a							=		self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__lowerCAmelCase				)

   def 		A				(   self      :							List[str]				)							->					Optional[Any]:


    """simple docstring"""






    pass

   def 		A				(   self      :							List[str]				)							->					Dict:


    """simple docstring"""






    pass

   @unittest.skip(reason="Blip does not use inputs_embeds"				)
   def 		A				(   self      :							Optional[Any]				)							->					str:


    """simple docstring"""






    pass

   @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"				)
   def 		A				(   self      :							Dict				)							->					Tuple:


    """simple docstring"""






    pass

   @unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"				)
   def 		A				(   self      :							Union[str, Any]				)							->					Tuple:


    """simple docstring"""






    pass

   @slow
   def 		A				(   self      :							Optional[int]				)							->					Optional[Any]:


    """simple docstring"""






    for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     a							=		BlipTextModel.from_pretrained(__lowerCAmelCase				)
     self.assertIsNotNone(__lowerCAmelCase				)




   def 		A				(   self      :							Tuple				)							->					Any:


    """simple docstring"""






    super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCAmelCase				)






from collections import Counter


def 						UpperCAmelCase__   (   UpperCAmelCase__			:list[int]       ):






 '''simple docstring'''

 return sum(socks_by_color // 2 for socks_by_color in Counter(UpperCAmelCase__       ).values()       )


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     A_		:  List[str]										=  [int(x) for x in input('''Enter socks by color :''').rstrip().split()]
     print(F"""sock_merchant({colors}) = {sock_merchant(colors)}""")

