



import os
import sys
import unittest


snake_case__       :  List[Any]     		= os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


snake_case__       :  Optional[Any]     		= os.path.join("""tests""", """models""", """bert""", """test_modeling_bert.py""")
snake_case__       :  str     		= os.path.join("""tests""", """models""", """blip""", """test_modeling_blip.py""")

class 	_A (			unittest.TestCase						):


						'''simple docstring'''





						def      _snake_case						(						self						:				Tuple						):






							'''simple docstring'''



							__lowercase									=      get_test_to_tester_mapping(SCREAMING_SNAKE_CASE__						)
							__lowercase									=      get_test_to_tester_mapping(SCREAMING_SNAKE_CASE__						)

							__lowercase									=      {'''BertModelTest''': '''BertModelTester'''}

							__lowercase									=      {
							    '''BlipModelTest''': '''BlipModelTester''',
							    '''BlipTextImageModelTest''': '''BlipTextImageModelsModelTester''',
							    '''BlipTextModelTest''': '''BlipTextModelTester''',
							    '''BlipTextRetrievalModelTest''': '''BlipTextRetrievalModelTester''',
							    '''BlipVQAModelTest''': '''BlipVQAModelTester''',
							    '''BlipVisionModelTest''': '''BlipVisionModelTester''',
							}

							self.assertEqual(get_test_info.to_json(SCREAMING_SNAKE_CASE__						)				,   SCREAMING_SNAKE_CASE__						)
							self.assertEqual(get_test_info.to_json(SCREAMING_SNAKE_CASE__						)				,   SCREAMING_SNAKE_CASE__						)



						def      _snake_case						(						self						:				Dict						):






							'''simple docstring'''



							__lowercase									=      get_model_to_test_mapping(SCREAMING_SNAKE_CASE__						)
							__lowercase									=      get_model_to_test_mapping(SCREAMING_SNAKE_CASE__						)

							__lowercase									=      {
							    '''BertForMaskedLM''': ['''BertModelTest'''],
							    '''BertForMultipleChoice''': ['''BertModelTest'''],
							    '''BertForNextSentencePrediction''': ['''BertModelTest'''],
							    '''BertForPreTraining''': ['''BertModelTest'''],
							    '''BertForQuestionAnswering''': ['''BertModelTest'''],
							    '''BertForSequenceClassification''': ['''BertModelTest'''],
							    '''BertForTokenClassification''': ['''BertModelTest'''],
							    '''BertLMHeadModel''': ['''BertModelTest'''],
							    '''BertModel''': ['''BertModelTest'''],
							}

							__lowercase									=      {
							    '''BlipForConditionalGeneration''': ['''BlipTextImageModelTest'''],
							    '''BlipForImageTextRetrieval''': ['''BlipTextRetrievalModelTest'''],
							    '''BlipForQuestionAnswering''': ['''BlipVQAModelTest'''],
							    '''BlipModel''': ['''BlipModelTest'''],
							    '''BlipTextModel''': ['''BlipTextModelTest'''],
							    '''BlipVisionModel''': ['''BlipVisionModelTest'''],
							}

							self.assertEqual(get_test_info.to_json(SCREAMING_SNAKE_CASE__						)				,   SCREAMING_SNAKE_CASE__						)
							self.assertEqual(get_test_info.to_json(SCREAMING_SNAKE_CASE__						)				,   SCREAMING_SNAKE_CASE__						)



						def      _snake_case						(						self						:				Optional[Any]						):






							'''simple docstring'''



							__lowercase									=      get_model_to_tester_mapping(SCREAMING_SNAKE_CASE__						)
							__lowercase									=      get_model_to_tester_mapping(SCREAMING_SNAKE_CASE__						)

							__lowercase									=      {
							    '''BertForMaskedLM''': ['''BertModelTester'''],
							    '''BertForMultipleChoice''': ['''BertModelTester'''],
							    '''BertForNextSentencePrediction''': ['''BertModelTester'''],
							    '''BertForPreTraining''': ['''BertModelTester'''],
							    '''BertForQuestionAnswering''': ['''BertModelTester'''],
							    '''BertForSequenceClassification''': ['''BertModelTester'''],
							    '''BertForTokenClassification''': ['''BertModelTester'''],
							    '''BertLMHeadModel''': ['''BertModelTester'''],
							    '''BertModel''': ['''BertModelTester'''],
							}

							__lowercase									=      {
							    '''BlipForConditionalGeneration''': ['''BlipTextImageModelsModelTester'''],
							    '''BlipForImageTextRetrieval''': ['''BlipTextRetrievalModelTester'''],
							    '''BlipForQuestionAnswering''': ['''BlipVQAModelTester'''],
							    '''BlipModel''': ['''BlipModelTester'''],
							    '''BlipTextModel''': ['''BlipTextModelTester'''],
							    '''BlipVisionModel''': ['''BlipVisionModelTester'''],
							}

							self.assertEqual(get_test_info.to_json(SCREAMING_SNAKE_CASE__						)				,   SCREAMING_SNAKE_CASE__						)
							self.assertEqual(get_test_info.to_json(SCREAMING_SNAKE_CASE__						)				,   SCREAMING_SNAKE_CASE__						)







"""simple docstring"""






import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class      A(  unittest.TestCase		):

		"""simple docstring"""





		@property
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					torch.manual_seed(0   )
					_UpperCamelCase					:str					     =	UNetaDModel(
					    block_out_channels=(32, 64)					,				layers_per_block=2					,				sample_size=32					,				in_channels=3					,				out_channels=3					,				down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')					,				up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')					,				)
					return model





		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	self.dummy_uncond_unet
					_UpperCamelCase					:List[Any]					     =	KarrasVeScheduler()

					_UpperCamelCase					:Optional[Any]					     =	KarrasVePipeline(unet=SCREAMING_SNAKE_CASE__					,				scheduler=SCREAMING_SNAKE_CASE__   )
					pipe.to(SCREAMING_SNAKE_CASE__   )
					pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:Dict					     =	torch.manual_seed(0   )
					_UpperCamelCase					:List[Any]					     =	pipe(num_inference_steps=2					,				generator=SCREAMING_SNAKE_CASE__					,				output_type='''numpy'''   ).images

					_UpperCamelCase					:List[Any]					     =	torch.manual_seed(0   )
					_UpperCamelCase					:Dict					     =	pipe(num_inference_steps=2					,				generator=SCREAMING_SNAKE_CASE__					,				output_type='''numpy'''					,				return_dict=SCREAMING_SNAKE_CASE__   )[0]

					_UpperCamelCase					:Dict					     =	image[0, -3:, -3:, -1]
					_UpperCamelCase					:List[Any]					     =	image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					_UpperCamelCase					:List[Any]					     =	np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]   )

					assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2
					assert np.abs(image_from_tuple_slice.flatten() - expected_slice   ).max() < 1E-2






@slow
@require_torch
class      A(  unittest.TestCase		):

		"""simple docstring"""





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

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	'''google/ncsnpp-celebahq-256'''
					_UpperCamelCase					:Any					     =	UNetaDModel.from_pretrained(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[int]					     =	KarrasVeScheduler()

					_UpperCamelCase					:Optional[int]					     =	KarrasVePipeline(unet=SCREAMING_SNAKE_CASE__					,				scheduler=SCREAMING_SNAKE_CASE__   )
					pipe.to(SCREAMING_SNAKE_CASE__   )
					pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:List[str]					     =	torch.manual_seed(0   )
					_UpperCamelCase					:List[Any]					     =	pipe(num_inference_steps=20					,				generator=SCREAMING_SNAKE_CASE__					,				output_type='''numpy'''   ).images

					_UpperCamelCase					:Dict					     =	image[0, -3:, -3:, -1]
					assert image.shape == (1, 2_56, 2_56, 3)
					_UpperCamelCase					:Any					     =	np.array([0.5_7_8, 0.5_8_1_1, 0.5_9_2_4, 0.5_8_0_9, 0.5_8_7, 0.5_8_8_6, 0.5_8_6_1, 0.5_8_0_2, 0.5_8_6]   )

					assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2

