'''simple docstring'''




import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPanoramaPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()




@skip_mps
class     a__      (   UpperCAmelCase__							,   UpperCAmelCase__							,   unittest.TestCase ):
     lowerCamelCase  :     int							=StableDiffusionPanoramaPipeline
     lowerCamelCase  :     Dict							=TEXT_TO_IMAGE_PARAMS
     lowerCamelCase  :     Union[str, Any]							=TEXT_TO_IMAGE_BATCH_PARAMS
     lowerCamelCase  :     Dict							=TEXT_TO_IMAGE_IMAGE_PARAMS
     lowerCamelCase  :     int							=TEXT_TO_IMAGE_IMAGE_PARAMS






     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict    ):





         """simple docstring"""



         torch.manual_seed(0    )
         __lowerCamelCase		=  UNetaDConditionModel(
             block_out_channels=(32, 64)  ,				layers_per_block=1  ,				sample_size=32  ,				in_channels=4  ,				out_channels=4  ,				down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')  ,				up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')  ,				cross_attention_dim=32  ,				)
         __lowerCamelCase		=  DDIMScheduler()
         torch.manual_seed(0    )
         __lowerCamelCase		=  AutoencoderKL(
             block_out_channels=[32, 64]  ,				in_channels=3  ,				out_channels=3  ,				down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']  ,				up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']  ,				latent_channels=4  ,				)
         torch.manual_seed(0    )
         __lowerCamelCase		=  CLIPTextConfig(
             bos_token_id=0  ,				eos_token_id=2  ,				hidden_size=32  ,				intermediate_size=37  ,				layer_norm_eps=1e-0_5  ,				num_attention_heads=4  ,				num_hidden_layers=5  ,				pad_token_id=1  ,				vocab_size=10_00  ,				)
         __lowerCamelCase		=  CLIPTextModel(a    )
         __lowerCamelCase		=  CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''    )

         __lowerCamelCase		=  {
             '''unet''': unet,
             '''scheduler''': scheduler,
             '''vae''': vae,
             '''text_encoder''': text_encoder,
             '''tokenizer''': tokenizer,
             '''safety_checker''': None,
             '''feature_extractor''': None,
         }
         return components






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		Dict  ,				a		:		Union[str, Any]=0    ):





         """simple docstring"""



         __lowerCamelCase		=  torch.manual_seed(a    )
         __lowerCamelCase		=  {
             '''prompt''': '''a photo of the dolomites''',
             '''generator''': generator,
             # Setting height and width to None to prevent OOMs on CPU.
             '''height''': None,
             '''width''': None,
             '''num_inference_steps''': 1,
             '''guidance_scale''': 6.0,
             '''output_type''': '''numpy''',
         }
         return inputs






     def    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
         __lowerCamelCase		=  self.get_dummy_components()
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline(**a    )
         __lowerCamelCase		=  sd_pipe.to(a    )
         sd_pipe.set_progress_bar_config(disable=a    )

         __lowerCamelCase		=  self.get_dummy_inputs(a    )
         __lowerCamelCase		=  sd_pipe(**a    ).images
         __lowerCamelCase		=  image[0, -3:, -3:, -1]
         assert image.shape == (1, 64, 64, 3)

         __lowerCamelCase		=  np.array([0.61_86, 0.53_74, 0.49_15, 0.41_35, 0.41_14, 0.45_63, 0.51_28, 0.49_77, 0.47_57]    )

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






     def    SCREAMING_SNAKE_CASE__   ( self		:		Tuple    ):





         """simple docstring"""



         super().test_inference_batch_consistent(batch_sizes=[1, 2]    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]    ):





         """simple docstring"""



         super().test_inference_batch_single_identical(batch_size=2  ,				expected_max_diff=3.2_5e-3    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
         __lowerCamelCase		=  self.get_dummy_components()
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline(**a    )
         __lowerCamelCase		=  sd_pipe.to(a    )
         sd_pipe.set_progress_bar_config(disable=a    )

         __lowerCamelCase		=  self.get_dummy_inputs(a    )
         __lowerCamelCase		=  '''french fries'''
         __lowerCamelCase		=  sd_pipe(**a  ,				negative_prompt=a    )
         __lowerCamelCase		=  output.images
         __lowerCamelCase		=  image[0, -3:, -3:, -1]

         assert image.shape == (1, 64, 64, 3)

         __lowerCamelCase		=  np.array([0.61_87, 0.53_75, 0.49_15, 0.41_36, 0.41_14, 0.45_63, 0.51_28, 0.49_76, 0.47_57]    )

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






     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict    ):





         """simple docstring"""



         __lowerCamelCase		=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
         __lowerCamelCase		=  self.get_dummy_components()
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline(**a    )
         __lowerCamelCase		=  sd_pipe.to(a    )
         sd_pipe.set_progress_bar_config(disable=a    )

         __lowerCamelCase		=  self.get_dummy_inputs(a    )
         __lowerCamelCase		=  sd_pipe(**a  ,				view_batch_size=2    )
         __lowerCamelCase		=  output.images
         __lowerCamelCase		=  image[0, -3:, -3:, -1]

         assert image.shape == (1, 64, 64, 3)

         __lowerCamelCase		=  np.array([0.61_87, 0.53_75, 0.49_15, 0.41_36, 0.41_14, 0.45_63, 0.51_28, 0.49_76, 0.47_57]    )

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






     def    SCREAMING_SNAKE_CASE__   ( self		:		Any    ):





         """simple docstring"""



         __lowerCamelCase		=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
         __lowerCamelCase		=  self.get_dummy_components()
         __lowerCamelCase		=  EulerAncestralDiscreteScheduler(
             beta_start=0.0_00_85  ,				beta_end=0.0_12  ,				beta_schedule='''scaled_linear'''    )
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline(**a    )
         __lowerCamelCase		=  sd_pipe.to(a    )
         sd_pipe.set_progress_bar_config(disable=a    )

         __lowerCamelCase		=  self.get_dummy_inputs(a    )
         __lowerCamelCase		=  sd_pipe(**a    ).images
         __lowerCamelCase		=  image[0, -3:, -3:, -1]

         assert image.shape == (1, 64, 64, 3)

         __lowerCamelCase		=  np.array([0.40_24, 0.65_10, 0.49_01, 0.53_78, 0.58_13, 0.56_22, 0.47_95, 0.44_67, 0.49_52]    )

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






     def    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
         __lowerCamelCase		=  self.get_dummy_components()
         __lowerCamelCase		=  PNDMScheduler(
             beta_start=0.0_00_85  ,				beta_end=0.0_12  ,				beta_schedule='''scaled_linear'''  ,				skip_prk_steps=a    )
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline(**a    )
         __lowerCamelCase		=  sd_pipe.to(a    )
         sd_pipe.set_progress_bar_config(disable=a    )

         __lowerCamelCase		=  self.get_dummy_inputs(a    )
         __lowerCamelCase		=  sd_pipe(**a    ).images
         __lowerCamelCase		=  image[0, -3:, -3:, -1]

         assert image.shape == (1, 64, 64, 3)

         __lowerCamelCase		=  np.array([0.63_91, 0.62_91, 0.48_61, 0.51_34, 0.55_52, 0.45_78, 0.50_32, 0.50_23, 0.45_39]    )

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




@slow
@require_torch_gpu
class     a__      (   unittest.TestCase ):






     def    SCREAMING_SNAKE_CASE__   ( self		:		Any    ):





         """simple docstring"""



         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()






     def    SCREAMING_SNAKE_CASE__   ( self		:		str  ,				a		:		str=0    ):





         """simple docstring"""



         __lowerCamelCase		=  torch.manual_seed(a    )
         __lowerCamelCase		=  {
             '''prompt''': '''a photo of the dolomites''',
             '''generator''': generator,
             '''num_inference_steps''': 3,
             '''guidance_scale''': 7.5,
             '''output_type''': '''numpy''',
         }
         return inputs






     def    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  '''stabilityai/stable-diffusion-2-base'''
         __lowerCamelCase		=  DDIMScheduler.from_pretrained(a  ,				subfolder='''scheduler'''    )
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline.from_pretrained(a  ,				scheduler=a  ,				safety_checker=a    )
         pipe.to(a    )
         pipe.set_progress_bar_config(disable=a    )
         pipe.enable_attention_slicing()

         __lowerCamelCase		=  self.get_inputs()
         __lowerCamelCase		=  pipe(**a    ).images
         __lowerCamelCase		=  image[0, -3:, -3:, -1].flatten()

         assert image.shape == (1, 5_12, 20_48, 3)

         __lowerCamelCase		=  np.array(
             [
                 0.36_96_83_92,
                 0.27_02_53_72,
                 0.32_44_67_66,
                 0.28_37_93_87,
                 0.36_36_32_74,
                 0.30_73_33_47,
                 0.27_10_00_27,
                 0.27_05_41_25,
                 0.25_53_60_96,
             ]    )

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






     def    SCREAMING_SNAKE_CASE__   ( self		:		Any    ):





         """simple docstring"""



         __lowerCamelCase		=  StableDiffusionPanoramaPipeline.from_pretrained(
             '''stabilityai/stable-diffusion-2-base'''  ,				safety_checker=a    )
         __lowerCamelCase		=  LMSDiscreteScheduler.from_config(pipe.scheduler.config    )
         pipe.to(a    )
         pipe.set_progress_bar_config(disable=a    )
         pipe.enable_attention_slicing()

         __lowerCamelCase		=  self.get_inputs()
         __lowerCamelCase		=  pipe(**a    ).images
         __lowerCamelCase		=  image[0, -3:, -3:, -1].flatten()

         assert image.shape == (1, 5_12, 20_48, 3)

         __lowerCamelCase		=  np.array(
             [
                 [
                     0.0,
                     0.0,
                     0.0,
                     0.0,
                     0.0,
                     0.0,
                     0.0,
                     0.0,
                     0.0,
                 ]
             ]    )

         assert np.abs(expected_slice - image_slice    ).max() < 1e-3






     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict    ):





         """simple docstring"""



         __lowerCamelCase		=  0

         def callback_fn(a		:		int  ,				a		:		int  ,				a		:		torch.FloatTensor    ) -> None:
             __lowerCamelCase		=  True
             nonlocal number_of_steps
             number_of_steps += 1
             if step == 1:
                 __lowerCamelCase		=  latents.detach().cpu().numpy()
                 assert latents.shape == (1, 4, 64, 2_56)
                 __lowerCamelCase		=  latents[0, -3:, -3:, -1]

                 __lowerCamelCase		=  np.array(
                     [
                         0.18_68_18_69,
                         0.33_90_78_16,
                         0.5_36_12_76,
                         0.14_43_28_65,
                         -0.02_85_66_11,
                         -0.73_94_11_23,
                         0.23_39_79_87,
                         0.47_32_26_82,
                         -0.37_82_31_64,
                     ]    )
                 assert np.abs(latents_slice.flatten() - expected_slice    ).max() < 5e-2
             elif step == 2:
                 __lowerCamelCase		=  latents.detach().cpu().numpy()
                 assert latents.shape == (1, 4, 64, 2_56)
                 __lowerCamelCase		=  latents[0, -3:, -3:, -1]

                 __lowerCamelCase		=  np.array(
                     [
                         0.18_53_96_45,
                         0.33_98_72_48,
                         0.5_37_85_59,
                         0.14_43_71_42,
                         -0.02_45_52_61,
                         -0.7_33_83_17,
                         0.23_99_07_55,
                         0.47_35_62_72,
                         -0.3_78_65_05,
                     ]    )

                 assert np.abs(latents_slice.flatten() - expected_slice    ).max() < 5e-2

         __lowerCamelCase		=  False

         __lowerCamelCase		=  '''stabilityai/stable-diffusion-2-base'''
         __lowerCamelCase		=  DDIMScheduler.from_pretrained(a  ,				subfolder='''scheduler'''    )
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline.from_pretrained(a  ,				scheduler=a  ,				safety_checker=a    )
         __lowerCamelCase		=  pipe.to(a    )
         pipe.set_progress_bar_config(disable=a    )
         pipe.enable_attention_slicing()

         __lowerCamelCase		=  self.get_inputs()
         pipe(**a  ,				callback=a  ,				callback_steps=1    )
         assert callback_fn.has_been_called
         assert number_of_steps == 3






     def    SCREAMING_SNAKE_CASE__   ( self		:		Tuple    ):





         """simple docstring"""



         torch.cuda.empty_cache()
         torch.cuda.reset_max_memory_allocated()
         torch.cuda.reset_peak_memory_stats()

         __lowerCamelCase		=  '''stabilityai/stable-diffusion-2-base'''
         __lowerCamelCase		=  DDIMScheduler.from_pretrained(a  ,				subfolder='''scheduler'''    )
         __lowerCamelCase		=  StableDiffusionPanoramaPipeline.from_pretrained(a  ,				scheduler=a  ,				safety_checker=a    )
         __lowerCamelCase		=  pipe.to(a    )
         pipe.set_progress_bar_config(disable=a    )
         pipe.enable_attention_slicing(1    )
         pipe.enable_sequential_cpu_offload()

         __lowerCamelCase		=  self.get_inputs()
         __lowerCamelCase		=  pipe(**a    )

         __lowerCamelCase		=  torch.cuda.max_memory_allocated()
         # make sure that less than 5.2 GB is allocated
         assert mem_bytes < 5.5 * 10**9






"""simple docstring"""






from __future__ import annotations

import copy
import tempfile
import unittest

from transformers import CONFIG_MAPPING, AutoConfig, BertConfig, GPTaConfig, TaConfig, TapasConfig, is_tf_available
from transformers.testing_utils import (
    DUMMY_UNKNOWN_IDENTIFIER,
    SMALL_MODEL_IDENTIFIER,
    RequestCounter,
    require_tensorflow_probability,
    require_tf,
    slow,
)

from ..bert.test_modeling_bert import BertModelTester


if is_tf_available():
			from transformers import (
			    TFAutoModel,
			    TFAutoModelForCausalLM,
			    TFAutoModelForMaskedLM,
			    TFAutoModelForPreTraining,
			    TFAutoModelForQuestionAnswering,
			    TFAutoModelForSeqaSeqLM,
			    TFAutoModelForSequenceClassification,
			    TFAutoModelForTableQuestionAnswering,
			    TFAutoModelForTokenClassification,
			    TFAutoModelWithLMHead,
			    TFBertForMaskedLM,
			    TFBertForPreTraining,
			    TFBertForQuestionAnswering,
			    TFBertForSequenceClassification,
			    TFBertModel,
			    TFFunnelBaseModel,
			    TFFunnelModel,
			    TFGPTaLMHeadModel,
			    TFRobertaForMaskedLM,
			    TFTaForConditionalGeneration,
			    TFTapasForQuestionAnswering,
			)
			from transformers.models.auto.modeling_tf_auto import (
			    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
			    TF_MODEL_FOR_MASKED_LM_MAPPING,
			    TF_MODEL_FOR_PRETRAINING_MAPPING,
			    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
			    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
			    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
			    TF_MODEL_MAPPING,
			)
			from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
			from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
			from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST
			from transformers.models.tapas.modeling_tf_tapas import TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST






class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			lowerCamelCase__      =			"""new-model"""


if is_tf_available():






			class lowerCAmelCase__	(     lowercase						):






						'''simple docstring'''



						lowerCamelCase__      =			NewModelConfig






@require_tf
class lowerCAmelCase__	(     unittest.TestCase						):






			'''simple docstring'''



			@slow
			def 					A_    (  self  ):
							_lowerCamelCase     :			List[str]    =    'bert-base-cased'
							_lowerCamelCase     :			Union[str, Any]    =    AutoConfig.from_pretrained(lowercase  )
							self.assertIsNotNone(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )

							_lowerCamelCase     :			Union[str, Any]    =    TFAutoModel.from_pretrained(lowercase  )
							self.assertIsNotNone(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							_lowerCamelCase     :			List[str]    =    'bert-base-cased'
							_lowerCamelCase     :			int    =    AutoConfig.from_pretrained(lowercase  )
							self.assertIsNotNone(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )

							_lowerCamelCase     :			int    =    TFAutoModelForPreTraining.from_pretrained(lowercase  )
							self.assertIsNotNone(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_lowerCamelCase     :			Dict    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			int    =    TFAutoModelForCausalLM.from_pretrained(lowercase  )
											_lowerCamelCase, _lowerCamelCase     :			str    =    TFAutoModelForCausalLM.from_pretrained(lowercase  ,      output_loading_info=lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_lowerCamelCase     :			List[Any]    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			str    =    TFAutoModelWithLMHead.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_lowerCamelCase     :			Tuple    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			Optional[int]    =    TFAutoModelForMaskedLM.from_pretrained(lowercase  )
											_lowerCamelCase, _lowerCamelCase     :			Tuple    =    TFAutoModelForMaskedLM.from_pretrained(lowercase  ,      output_loading_info=lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_lowerCamelCase     :			Optional[int]    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			Tuple    =    TFAutoModelForSeqaSeqLM.from_pretrained(lowercase  )
											_lowerCamelCase, _lowerCamelCase     :			Tuple    =    TFAutoModelForSeqaSeqLM.from_pretrained(lowercase  ,      output_loading_info=lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							for model_name in ["bert-base-uncased"]:
											_lowerCamelCase     :			str    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			Union[str, Any]    =    TFAutoModelForSequenceClassification.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			def 					A_    (  self  ):
							# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							for model_name in ["bert-base-uncased"]:
											_lowerCamelCase     :			Optional[Any]    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			List[str]    =    TFAutoModelForQuestionAnswering.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			@slow
			@require_tensorflow_probability
			def 					A_    (  self  ):
							for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
											_lowerCamelCase     :			Dict    =    AutoConfig.from_pretrained(lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )

											_lowerCamelCase     :			Dict    =    TFAutoModelForTableQuestionAnswering.from_pretrained(lowercase  )
											_lowerCamelCase, _lowerCamelCase     :			List[Any]    =    TFAutoModelForTableQuestionAnswering.from_pretrained(
											    lowercase  ,      output_loading_info=lowercase  )
											self.assertIsNotNone(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			def 					A_    (  self  ):
							_lowerCamelCase     :			int    =    TFAutoModelWithLMHead.from_pretrained(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )
							self.assertEqual(model.num_parameters()  ,      14410  )
							self.assertEqual(model.num_parameters(only_trainable=lowercase  )  ,      14410  )
			def 					A_    (  self  ):
							_lowerCamelCase     :			Any    =    TFAutoModelWithLMHead.from_pretrained(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )
							self.assertEqual(model.num_parameters()  ,      14410  )
							self.assertEqual(model.num_parameters(only_trainable=lowercase  )  ,      14410  )
			def 					A_    (  self  ):
							# For the auto model mapping, FunnelConfig has two models: FunnelModel and FunnelBaseModel
							_lowerCamelCase     :			List[str]    =    TFAutoModel.from_pretrained('sgugger/funnel-random-tiny'  )
							self.assertIsInstance(lowercase  ,      lowercase  )

							_lowerCamelCase     :			Optional[int]    =    copy.deepcopy(model.config  )
							_lowerCamelCase     :			Dict    =    ['FunnelBaseModel']
							_lowerCamelCase     :			List[Any]    =    TFAutoModel.from_config(lowercase  )
							self.assertIsInstance(lowercase  ,      lowercase  )

							with tempfile.TemporaryDirectory() as tmp_dir:
											model.save_pretrained(lowercase  )
											_lowerCamelCase     :			Tuple    =    TFAutoModel.from_pretrained(lowercase  )
											self.assertIsInstance(lowercase  ,      lowercase  )
			def 					A_    (  self  ):
							try:
											AutoConfig.register('new-model'  ,      lowercase  )

											_lowerCamelCase     :			Tuple    =    [
											    TFAutoModel,
											    TFAutoModelForCausalLM,
											    TFAutoModelForMaskedLM,
											    TFAutoModelForPreTraining,
											    TFAutoModelForQuestionAnswering,
											    TFAutoModelForSequenceClassification,
											    TFAutoModelForTokenClassification,
											]

											for auto_class in auto_classes:
															with self.subTest(auto_class.__name__  ):
																			# Wrong config class will raise an error
																			with self.assertRaises(lowercase  ):
																							auto_class.register(lowercase  ,      lowercase  )
																			auto_class.register(lowercase  ,      lowercase  )
																			# Trying to register something existing in the Transformers library will raise an error
																			with self.assertRaises(lowercase  ):
																							auto_class.register(lowercase  ,      lowercase  )

																			# Now that the config is registered, it can be used as any other config with the auto-API
																			_lowerCamelCase     :			Optional[Any]    =    BertModelTester(self  ).get_config()
																			_lowerCamelCase     :			Dict    =    NewModelConfig(**tiny_config.to_dict()  )
																			_lowerCamelCase     :			int    =    auto_class.from_config(lowercase  )
																			self.assertIsInstance(lowercase  ,      lowercase  )

																			with tempfile.TemporaryDirectory() as tmp_dir:
																							model.save_pretrained(lowercase  )
																							_lowerCamelCase     :			List[Any]    =    auto_class.from_pretrained(lowercase  )
																							self.assertIsInstance(lowercase  ,      lowercase  )

							finally:
											if "new-model" in CONFIG_MAPPING._extra_content:
															del CONFIG_MAPPING._extra_content["new-model"]
											for mapping in (
											    TF_MODEL_MAPPING,
											    TF_MODEL_FOR_PRETRAINING_MAPPING,
											    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
											    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
											    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
											    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
											    TF_MODEL_FOR_MASKED_LM_MAPPING,
											):
															if NewModelConfig in mapping._extra_content:
																			del mapping._extra_content[NewModelConfig]
			def 					A_    (  self  ):
							with self.assertRaisesRegex(
							    lowercase  ,      'bert-base is not a local folder and is not a valid model identifier'  ):
											_lowerCamelCase     :			Union[str, Any]    =    TFAutoModel.from_pretrained('bert-base'  )
			def 					A_    (  self  ):
							with self.assertRaisesRegex(
							    lowercase  ,      r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'  ):
											_lowerCamelCase     :			str    =    TFAutoModel.from_pretrained(lowercase  ,      revision='aaaaaa'  )
			def 					A_    (  self  ):
							with self.assertRaisesRegex(
							    lowercase  ,      'hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin'  ,      ):
											_lowerCamelCase     :			Tuple    =    TFAutoModel.from_pretrained('hf-internal-testing/config-no-model'  )
			def 					A_    (  self  ):
							with self.assertRaisesRegex(lowercase  ,      'Use `from_pt=True` to load this model'  ):
											_lowerCamelCase     :			Tuple    =    TFAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only'  )






			def 					A_    (  self  ):
							# Make sure we have cached the model.
							_lowerCamelCase     :			Optional[int]    =    TFAutoModel.from_pretrained('hf-internal-testing/tiny-random-bert'  )
							with RequestCounter() as counter:
											_lowerCamelCase     :			Optional[int]    =    TFAutoModel.from_pretrained('hf-internal-testing/tiny-random-bert'  )
											self.assertEqual(counter.get_request_count  ,      0  )
											self.assertEqual(counter.head_request_count  ,      1  )
											self.assertEqual(counter.other_request_count  ,      0  )

							# With a sharded checkpoint
							_lowerCamelCase     :			int    =    TFAutoModel.from_pretrained('ArthurZ/tiny-random-bert-sharded'  )
							with RequestCounter() as counter:
											_lowerCamelCase     :			List[Any]    =    TFAutoModel.from_pretrained('ArthurZ/tiny-random-bert-sharded'  )
											self.assertEqual(counter.get_request_count  ,      0  )
											self.assertEqual(counter.head_request_count  ,      1  )
											self.assertEqual(counter.other_request_count  ,      0  )