




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     a  :

     '''simple docstring'''





     def __init__(			self     :    Tuple      ,					__snake_case     :    Tuple      ,					__snake_case     :    Tuple=12      ,					__snake_case     :    List[Any]=7      ,					__snake_case     :    List[str]=True      ,					__snake_case     :    str=True      ,					__snake_case     :    str=True      ,					__snake_case     :    List[str]=99      ,					__snake_case     :    Dict=32      ,					__snake_case     :    Dict=32      ,					__snake_case     :    Tuple=5      ,					__snake_case     :    str=4      ,					__snake_case     :    int=37      ,					__snake_case     :    str=0.1      ,					__snake_case     :    str=0.1      ,					__snake_case     :    Dict=5_12      ,					__snake_case     :    Tuple=0.02      ,					__snake_case     :    List[Any]=0      ,					__snake_case     :    Optional[int]=None      ,					):
         UpperCAmelCase_											=  parent
         UpperCAmelCase_											=  batch_size
         UpperCAmelCase_											=  seq_length
         UpperCAmelCase_											=  is_training
         UpperCAmelCase_											=  use_input_mask
         UpperCAmelCase_											=  use_labels
         UpperCAmelCase_											=  vocab_size
         UpperCAmelCase_											=  hidden_size
         UpperCAmelCase_											=  projection_dim
         UpperCAmelCase_											=  num_hidden_layers
         UpperCAmelCase_											=  num_attention_heads
         UpperCAmelCase_											=  intermediate_size
         UpperCAmelCase_											=  dropout
         UpperCAmelCase_											=  attention_dropout
         UpperCAmelCase_											=  max_position_embeddings
         UpperCAmelCase_											=  initializer_range
         UpperCAmelCase_											=  scope
         UpperCAmelCase_											=  bos_token_id
     def 						lowerCamelCase_     (			self     :    Tuple       ):
         UpperCAmelCase_											=  ids_tensor([self.batch_size, self.seq_length]      ,					self.vocab_size       )

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

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

         UpperCAmelCase_											=  self.get_config()

         return config, input_ids, input_mask
     def 						lowerCamelCase_     (			self     :    Any       ):
         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 						lowerCamelCase_     (			self     :    int      ,					__snake_case     :    Optional[Any]      ,					__snake_case     :    List[Any]      ,					__snake_case     :    List[Any]       ):
         UpperCAmelCase_											=  BlipTextModel(config=__snake_case       )
         model.to(__snake_case       )
         model.eval()
         with torch.no_grad():
             UpperCAmelCase_											=  model(__snake_case      ,					attention_mask=__snake_case       )
             UpperCAmelCase_											=  model(__snake_case       )
         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 						lowerCamelCase_     (			self     :    str       ):
         UpperCAmelCase_											=  self.prepare_config_and_inputs()
         UpperCAmelCase_				,							UpperCAmelCase_				,							UpperCAmelCase_											=  config_and_inputs
         UpperCAmelCase_											=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
         return config, inputs_dict



@require_torch
class     a  (     _A			,     unittest.TestCase    ):

     '''simple docstring'''





     lowerCAmelCase       : int     	=						(BlipTextModel,) if is_torch_available() else ()
     lowerCAmelCase       : Union[str, Any]     	=						False
     lowerCAmelCase       : int     	=						False
     lowerCAmelCase       : str     	=						False
     def 						lowerCamelCase_     (			self     :    Optional[Any]       ):
         UpperCAmelCase_											=  BlipTextModelTester(self       )
         UpperCAmelCase_											=  ConfigTester(self      ,					config_class=__snake_case      ,					hidden_size=37       )
     def 						lowerCamelCase_     (			self     :    List[str]       ):
         self.config_tester.run_common_tests()
     def 						lowerCamelCase_     (			self     :    List[str]       ):
         UpperCAmelCase_											=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__snake_case       )
     def 						lowerCamelCase_     (			self     :    List[str]       ):
         pass
     def 						lowerCamelCase_     (			self     :    Union[str, Any]       ):
         pass
     @unittest.skip(reason='''Blip does not use inputs_embeds'''       )
     def 						lowerCamelCase_     (			self     :    List[str]       ):
         pass
     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''       )
     def 						lowerCamelCase_     (			self     :    Optional[Any]       ):
         pass
     @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''       )
     def 						lowerCamelCase_     (			self     :    Any       ):
         pass
     @slow
     def 						lowerCamelCase_     (			self     :    Optional[int]       ):
         for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCAmelCase_											=  BlipTextModel.from_pretrained(__snake_case       )
             self.assertIsNotNone(__snake_case       )




     def 						lowerCamelCase_     (			self     :    List[str]       ):
         super().test_pt_tf_model_equivalence(allow_missing_keys=__snake_case       )











import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils



class     a  (     unittest.TestCase    ):

     '''simple docstring'''





     @patch('''diffusers.utils.hub_utils.get_full_repo_name'''       )
     def 						lowerCamelCase_     (			self     :    List[Any]      ,					__snake_case     :    Mock       ):
         UpperCAmelCase_											=  '''full_repo_name'''
         with TemporaryDirectory() as tmpdir:
             # Dummy args values
             UpperCAmelCase_											=  Mock()
             UpperCAmelCase_											=  tmpdir
             UpperCAmelCase_											=  0
             UpperCAmelCase_											=  '''hub_token'''
             UpperCAmelCase_											=  '''dataset_name'''
             UpperCAmelCase_											=  0.01
             UpperCAmelCase_											=  10_00_00
             UpperCAmelCase_											=  1_00_00
             UpperCAmelCase_											=  0.01
             UpperCAmelCase_											=  0.02
             UpperCAmelCase_											=  0.03
             UpperCAmelCase_											=  0.0_005
             UpperCAmelCase_											=  0.000_001
             UpperCAmelCase_											=  1
             UpperCAmelCase_											=  10
             UpperCAmelCase_											=  0.001
             UpperCAmelCase_											=  0.1
             UpperCAmelCase_											=  0.2
             UpperCAmelCase_											=  True

             # Model card mush be rendered and saved
             diffusers.utils.hub_utils.create_model_card(__snake_case      ,					model_name='''model_name'''       )
             self.assertTrue((Path(__snake_case       ) / '''README.md''').is_file()       )





