






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				,    lowerCamelCase__				,    lowerCamelCase__=12				,    lowerCamelCase__=7				,    lowerCamelCase__=True				,    lowerCamelCase__=True				,    lowerCamelCase__=True				,    lowerCamelCase__=99				,    lowerCamelCase__=32				,    lowerCamelCase__=32				,    lowerCamelCase__=5				,    lowerCamelCase__=4				,    lowerCamelCase__=37				,    lowerCamelCase__=0.1				,    lowerCamelCase__=0.1				,    lowerCamelCase__=512				,    lowerCamelCase__=0.02				,    lowerCamelCase__=0				,    lowerCamelCase__=None				,    ):




									"""simple docstring"""

									__UpperCamelCase :   Optional[Any]									=parent
									__UpperCamelCase :   Dict									=batch_size
									__UpperCamelCase :   Any									=seq_length
									__UpperCamelCase :   Optional[int]									=is_training
									__UpperCamelCase :   str									=use_input_mask
									__UpperCamelCase :   List[Any]									=use_labels
									__UpperCamelCase :   Any									=vocab_size
									__UpperCamelCase :   int									=hidden_size
									__UpperCamelCase :   Optional[int]									=projection_dim
									__UpperCamelCase :   Dict									=num_hidden_layers
									__UpperCamelCase :   Optional[int]									=num_attention_heads
									__UpperCamelCase :   Optional[int]									=intermediate_size
									__UpperCamelCase :   Any									=dropout
									__UpperCamelCase :   str									=attention_dropout
									__UpperCamelCase :   Tuple									=max_position_embeddings
									__UpperCamelCase :   Any									=initializer_range
									__UpperCamelCase :   List[str]									=scope
									__UpperCamelCase :   str									=bos_token_id


				def  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   Optional[Any]									=ids_tensor([self.batch_size, self.seq_length]				,    self.vocab_size       )

									__UpperCamelCase :   Dict									=None
									if self.use_input_mask:
														__UpperCamelCase :   Optional[int]									=random_attention_mask([self.batch_size, self.seq_length]       )

									if input_mask is not None:
														__UpperCamelCase						,							__UpperCamelCase :   Tuple									=input_mask.shape
														__UpperCamelCase :   Optional[int]									=np.random.randint(1				,    seq_length - 1				,    size=(batch_size,)       )
														for batch_idx, start_index in enumerate(__UpperCamelCase       ):
																			__UpperCamelCase :   Optional[int]									=1
																			__UpperCamelCase :   List[str]									=0

									__UpperCamelCase :   Optional[Any]									=self.get_config()

									return config, input_ids, input_mask


				def  __lowercase				(					self       ):




									"""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  __lowercase				(					self				,    lowerCamelCase__				,    lowerCamelCase__				,    lowerCamelCase__       ):




									"""simple docstring"""

									__UpperCamelCase :   List[str]									=BlipTextModel(config=__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()
									with torch.no_grad():
														__UpperCamelCase :   Dict									=model(__UpperCamelCase				,    attention_mask=__UpperCamelCase       )
														__UpperCamelCase :   Any									=model(__UpperCamelCase       )
									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  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   str									=self.prepare_config_and_inputs()
									__UpperCamelCase						,							__UpperCamelCase						,							__UpperCamelCase :   Dict									=config_and_inputs
									__UpperCamelCase :   str									={'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict




@require_torch
class 							__A	(     lowercase_ ,	unittest.TestCase					):





				"""simple docstring"""







				UpperCamelCase__					: Optional[Any]     					=(BlipTextModel,) if is_torch_available() else ()
				UpperCamelCase__					: Dict     					=False
				UpperCamelCase__					: List[str]     					=False
				UpperCamelCase__					: List[Any]     					=False


				def  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   str									=BlipTextModelTester(self       )
									__UpperCamelCase :   Tuple									=ConfigTester(self				,    config_class=__UpperCamelCase				,    hidden_size=37       )


				def  __lowercase				(					self       ):




									"""simple docstring"""

									self.config_tester.run_common_tests()


				def  __lowercase				(					self       ):




									"""simple docstring"""

									__UpperCamelCase :   Optional[int]									=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__UpperCamelCase       )


				def  __lowercase				(					self       ):




									"""simple docstring"""

									pass


				def  __lowercase				(					self       ):




									"""simple docstring"""

									pass


				@unittest.skip(reason='Blip does not use inputs_embeds'       )
				def  __lowercase				(					self       ):




									"""simple docstring"""

									pass


				@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'       )
				def  __lowercase				(					self       ):




									"""simple docstring"""

									pass


				@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'       )
				def  __lowercase				(					self       ):




									"""simple docstring"""

									pass


				@slow
				def  __lowercase				(					self       ):




									"""simple docstring"""

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







				def  __lowercase				(					self       ):




									"""simple docstring"""

									super().test_pt_tf_model_equivalence(allow_missing_keys=__UpperCamelCase       )








"""simple docstring"""
from __future__ import annotations

from queue import Queue






def    A__							(     UpperCamelCase   ,    UpperCamelCase			):
							a ^= b
							b ^= a
							a ^= b
							return a, b






def    A__							(     UpperCamelCase   ,    UpperCamelCase			):
							A						=    1
							while (1 << j) < max_node:
														for i in range(1   ,    max_node + 1			):
																					A						=    parent[j - 1][parent[j - 1][i]]
														j += 1
							return parent






def    A__							(     UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase			):
							# u must be deeper in the tree than v
							if level[u] < level[v]:
														A,      A						=    swap(UpperCamelCase   ,    UpperCamelCase			)
							# making depth of u same as depth of v
							for i in range(18   ,    -1   ,    -1			):
														if level[u] - (1 << i) >= level[v]:
																					A						=    parent[i][u]
    # at the same depth if u==v that mean lca is found
							if u == v:
														return u
							# moving both nodes upwards till lca in found
							for i in range(18   ,    -1   ,    -1			):
														if parent[i][u] not in [0, parent[i][v]]:
																					A,      A						=    parent[i][u], parent[i][v]
    # returning longest common ancestor of u,v
							return parent[0][u]






def    A__							(     UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase = 1   ,    ):
							A						=    0
							A						=    Queue(maxsize=UpperCamelCase			)
							q.put(UpperCamelCase			)
							while q.qsize() != 0:
														A						=    q.get()
														for v in graph[u]:
																					if level[v] == -1:
																												A						=    level[u] + 1
																												q.put(UpperCamelCase			)
																												A						=    u
							return level, parent






def    A__							(     ):
							A						=    13
							# initializing with 0
							A						=    [[0 for _ in range(max_node + 10			)] for _ in range(20			)]
							# initializing with -1 which means every node is unvisited
							A						=    [-1 for _ in range(max_node + 10			)]
							A						=    {
							    1: [2, 3, 4],
							    2: [5],
							    3: [6, 7],
							    4: [8],
							    5: [9, 10],
							    6: [11],
							    7: [],
							    8: [12, 13],
							    9: [],
							    10: [],
							    11: [],
							    12: [],
							    13: [],
							}
							A,      A						=    breadth_first_search(UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase   ,    UpperCamelCase   ,    1			)
							A						=    create_sparse(UpperCamelCase   ,    UpperCamelCase			)
							print("LCA of node 1 and 3 is: "   ,    lowest_common_ancestor(1   ,    3   ,    UpperCamelCase   ,    UpperCamelCase			)			)
							print("LCA of node 5 and 6 is: "   ,    lowest_common_ancestor(5   ,    6   ,    UpperCamelCase   ,    UpperCamelCase			)			)
							print("LCA of node 7 and 11 is: "   ,    lowest_common_ancestor(7   ,    11   ,    UpperCamelCase   ,    UpperCamelCase			)			)
							print("LCA of node 6 and 7 is: "   ,    lowest_common_ancestor(6   ,    7   ,    UpperCamelCase   ,    UpperCamelCase			)			)
							print("LCA of node 4 and 12 is: "   ,    lowest_common_ancestor(4   ,    12   ,    UpperCamelCase   ,    UpperCamelCase			)			)
							print("LCA of node 8 and 8 is: "   ,    lowest_common_ancestor(8   ,    8   ,    UpperCamelCase   ,    UpperCamelCase			)			)


if __name__ == "__main__":
		main()


