


import inspect
import unittest
from typing import List

import numpy as np

from transformers import EfficientFormerConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import (
						    TFEfficientFormerForImageClassification,
						    TFEfficientFormerForImageClassificationWithTeacher,
						    TFEfficientFormerModel,
						)
						from transformers.models.efficientformer.modeling_tf_efficientformer import (
						    TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
						)


if is_vision_available():
						from PIL import Image

						from transformers import EfficientFormerImageProcessor







class 	snake_case_       :
					def __init__(				self       :Optional[Any]      ,__snake_case       :Any      ,__snake_case       :int = 13      ,__snake_case       :int = 64      ,__snake_case       :int = 2      ,__snake_case       :int = 3      ,__snake_case       :int = 3      ,__snake_case       :bool = True      ,__snake_case       :bool = True      ,__snake_case       :int = 1_28      ,__snake_case       :str=[16, 32, 64, 1_28]      ,__snake_case       :int = 7      ,__snake_case       :int = 4      ,__snake_case       :int = 37      ,__snake_case       :str = "gelu"      ,__snake_case       :float = 0.1      ,__snake_case       :float = 0.1      ,__snake_case       :int = 10      ,__snake_case       :float = 0.02      ,__snake_case       :int = 2      ,__snake_case       :int = 1      ,__snake_case       :int = 1_28      ,__snake_case       :List[int] = [2, 2, 2, 2]      ,__snake_case       :int = 2      ,__snake_case       :int = 2      ,) ->   Optional[int]:
												a__					=					parent
												a__					=					batch_size
												a__					=					image_size
												a__					=					patch_size
												a__					=					num_channels
												a__					=					is_training
												a__					=					use_labels
												a__					=					hidden_size
												a__					=					num_hidden_layers
												a__					=					num_attention_heads
												a__					=					intermediate_size
												a__					=					hidden_act
												a__					=					hidden_dropout_prob
												a__					=					attention_probs_dropout_prob
												a__					=					type_sequence_label_size
												a__					=					initializer_range
												a__					=					encoder_stride
												a__					=					num_attention_outputs
												a__					=					embed_dim
												a__					=					embed_dim + 1
												a__					=					resolution
												a__					=					depths
												a__					=					hidden_sizes
												a__					=					dim
												a__					=					mlp_expansion_ratio
					def 			lowerCamelCase__(				self       :List[str]				) ->   int:
												a__					=					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

												a__					=					None
												if self.use_labels:
																			a__					=					ids_tensor([self.batch_size]      ,self.type_sequence_label_size				)

												a__					=					self.get_config()

												return config, pixel_values, labels
					def 			lowerCamelCase__(				self       :Dict				) ->   Optional[Any]:
												return EfficientFormerConfig(
												    image_size=self.image_size      ,patch_size=self.patch_size      ,num_channels=self.num_channels      ,hidden_size=self.hidden_size      ,num_hidden_layers=self.num_hidden_layers      ,num_attention_heads=self.num_attention_heads      ,intermediate_size=self.intermediate_size      ,hidden_act=self.hidden_act      ,hidden_dropout_prob=self.hidden_dropout_prob      ,attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,is_decoder=__snake_case      ,initializer_range=self.initializer_range      ,encoder_stride=self.encoder_stride      ,resolution=self.resolution      ,depths=self.depths      ,hidden_sizes=self.hidden_sizes      ,dim=self.dim      ,mlp_expansion_ratio=self.mlp_expansion_ratio      ,)
					def 			lowerCamelCase__(				self       :List[Any]      ,__snake_case       :List[str]      ,__snake_case       :Tuple      ,__snake_case       :List[str]				) ->   Union[str, Any]:
												a__					=					TFEfficientFormerModel(config=__snake_case				)
												a__					=					model(__snake_case      ,training=__snake_case				)
												self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.hidden_size)				)
					def 			lowerCamelCase__(				self       :Union[str, Any]      ,__snake_case       :Optional[Any]      ,__snake_case       :Any      ,__snake_case       :str				) ->   List[str]:
												a__					=					self.type_sequence_label_size
												a__					=					TFEfficientFormerForImageClassification(__snake_case				)
												a__					=					model(__snake_case      ,labels=__snake_case      ,training=__snake_case				)
												self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.type_sequence_label_size)				)

												# test greyscale images
												a__					=					1
												a__					=					TFEfficientFormerForImageClassification(__snake_case				)

												a__					=					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]				)
												a__					=					model(__snake_case      ,labels=__snake_case				)
												self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.type_sequence_label_size)				)



					def 			lowerCamelCase__(				self       :Optional[int]				) ->   Optional[int]:
												a__					=					self.prepare_config_and_inputs()
												a__				, a__				, a__					=					config_and_inputs
												a__					=					{'pixel_values': pixel_values}
												return config, inputs_dict







@require_tf
class 	snake_case_       (lowerCamelCase_     ,						lowerCamelCase_     ,						unittest.TestCase				):
					UpperCAmelCase__ :   Union[str, Any]   				=      (
					    (
					        TFEfficientFormerModel,
					        TFEfficientFormerForImageClassificationWithTeacher,
					        TFEfficientFormerForImageClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					UpperCAmelCase__ :   str   				=      (
					    {
					        '''feature-extraction''': TFEfficientFormerModel,
					        '''image-classification''': (
					            TFEfficientFormerForImageClassification,
					            TFEfficientFormerForImageClassificationWithTeacher,
					        ),
					    }
					    if is_tf_available()
					    else {}
					)

					UpperCAmelCase__ :   Union[str, Any]   				=      False

					UpperCAmelCase__ :   List[str]   				=      False
					UpperCAmelCase__ :   Union[str, Any]   				=      False
					UpperCAmelCase__ :   Any   				=      False
					UpperCAmelCase__ :   Any   				=      False
					def 			lowerCamelCase__(				self       :Any				) ->   str:
												a__					=					TFEfficientFormerModelTester(self				)
												a__					=					ConfigTester(
												    self      ,config_class=__snake_case      ,has_text_modality=__snake_case      ,hidden_size=37				)
					def 			lowerCamelCase__(				self       :Optional[Any]				) ->   Tuple:
												self.config_tester.run_common_tests()
					@unittest.skip(reason='EfficientFormer does not use inputs_embeds'				)
					def 			lowerCamelCase__(				self       :int				) ->   int:
												pass
					@unittest.skip(reason='EfficientFormer does not support input and output embeddings'				)
					def 			lowerCamelCase__(				self       :Any				) ->   List[Any]:
												pass
					def 			lowerCamelCase__(				self       :int				) ->   Dict:
												a__				, a__					=					self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			a__					=					model_class(__snake_case				)
																			a__					=					inspect.signature(model.call				)
																			# signature.parameters is an OrderedDict => so arg_names order is deterministic
																			a__					=					[*signature.parameters.keys()]

																			a__					=					['pixel_values']
																			self.assertListEqual(arg_names[:1]      ,__snake_case				)
					def 			lowerCamelCase__(				self       :List[Any]				) ->   Union[str, Any]:
												def check_hidden_states_output(__snake_case       :List[str]      ,__snake_case       :List[Any]      ,__snake_case       :str				):
																			a__					=					model_class(__snake_case				)

																			a__					=					model(**self._prepare_for_class(__snake_case      ,__snake_case				)      ,training=__snake_case				)
																			a__					=					outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																			a__					=					getattr(
																			    self.model_tester      ,'expected_num_hidden_layers'      ,self.model_tester.num_hidden_layers + 1				)
																			self.assertEqual(len(__snake_case				)      ,__snake_case				)

																			if hasattr(self.model_tester      ,'encoder_seq_length'				):
																										a__					=					self.model_tester.encoder_seq_length
																										if hasattr(self.model_tester      ,'chunk_length'				) and self.model_tester.chunk_length > 1:
																																	a__					=					seq_length * self.model_tester.chunk_length
																			else:
																										a__					=					self.model_tester.seq_length

																			self.assertListEqual(
																			    list(hidden_states[-1].shape[-2:]				)      ,[seq_length, self.model_tester.hidden_size]      ,)

																			if config.is_encoder_decoder:
																										a__					=					outputs.decoder_hidden_states

																										self.asseretIsInstance(__snake_case      ,(list, tuple)				)
																										self.assertEqual(len(__snake_case				)      ,__snake_case				)
																										a__					=					getattr(self.model_tester      ,'seq_length'      ,__snake_case				)
																										a__					=					getattr(self.model_tester      ,'decoder_seq_length'      ,__snake_case				)

																										self.assertListEqual(
																										    list(hidden_states[-1].shape[-2:]				)      ,[decoder_seq_length, self.model_tester.hidden_size]      ,)

												a__				, a__					=					self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			a__					=					True
																			check_hidden_states_output(__snake_case      ,__snake_case      ,__snake_case				)

																			# check that output_hidden_states also work using config
																			del inputs_dict["output_hidden_states"]
																			a__					=					True

																			check_hidden_states_output(__snake_case      ,__snake_case      ,__snake_case				)
					def 			lowerCamelCase__(				self       :Optional[int]      ,__snake_case       :Optional[int]      ,__snake_case       :Optional[Any]      ,__snake_case       :Dict=False				) ->   Optional[int]:
												a__					=					super()._prepare_for_class(__snake_case      ,__snake_case      ,return_labels=__snake_case				)

												if return_labels:
																			if model_class.__name__ == "TFEfficientFormerForImageClassificationWithTeacher":
																										del inputs_dict["labels"]

												return inputs_dict
					def 			lowerCamelCase__(				self       :List[str]				) ->   Union[str, Any]:
												a__					=					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__snake_case				)
					@unittest.skip(reason='EfficientFormer does not implement masked image modeling yet'				)
					def 			lowerCamelCase__(				self       :Any				) ->   str:
												a__					=					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_masked_image_modeling(*__snake_case				)
					def 			lowerCamelCase__(				self       :Optional[int]				) ->   str:
												a__					=					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*__snake_case				)
					@slow
					def 			lowerCamelCase__(				self       :List[Any]				) ->   int:
												for model_name in TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			a__					=					TFEfficientFormerModel.from_pretrained(__snake_case				)
																			self.assertIsNotNone(__snake_case				)
					def 			lowerCamelCase__(				self       :str				) ->   int:
												a__				, a__					=					self.model_tester.prepare_config_and_inputs_for_common()
												a__					=					True

												a__					=					getattr(self.model_tester      ,'seq_length'      ,__snake_case				)
												a__					=					getattr(self.model_tester      ,'encoder_seq_length'      ,__snake_case				)
												a__					=					getattr(self.model_tester      ,'key_length'      ,__snake_case				)
												a__					=					getattr(self.model_tester      ,'chunk_length'      ,__snake_case				)

												if chunk_length is not None and hasattr(self.model_tester      ,'num_hashes'				):
																			a__					=					encoder_seq_length * self.model_tester.num_hashes

												for model_class in self.all_model_classes:
																			a__					=					True
																			a__					=					False
																			a__					=					True
																			a__					=					model_class(__snake_case				)

																			a__					=					model(**self._prepare_for_class(__snake_case      ,__snake_case				)      ,training=__snake_case				)
																			a__					=					outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																			self.assertEqual(len(__snake_case				)      ,self.model_tester.num_attention_outputs				)

																			# check that output_attentions also work using config
																			del inputs_dict["output_attentions"]
																			a__					=					True
																			a__					=					model_class(__snake_case				)
																			a__					=					model(**self._prepare_for_class(__snake_case      ,__snake_case				)      ,training=__snake_case				)

																			a__					=					outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																			self.assertEqual(len(__snake_case				)      ,self.model_tester.num_attention_outputs				)

																			if chunk_length is not None:
																										self.assertListEqual(
																										    list(attentions[0].shape[-4:]				)      ,[self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length]      ,)
																			else:
																										self.assertListEqual(
																										    list(attentions[0].shape[-3:]				)      ,[self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length]      ,)



					def 			lowerCamelCase__(				self       :Dict				) ->   Union[str, Any]:
												# We use a simplified version of this test for EfficientFormer because it requires training=False
												# and Keras refuses to let us force that during functional construction
												a__				, a__					=					self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			# Prepare our model
																			a__					=					model_class(__snake_case				)
																			# These are maximally general inputs for the model, with multiple None dimensions
																			# Hopefully this will catch any conditionals that fail for flexible shapes
																			a__					=					{
																			    key: tf.keras.Input(shape=val.shape[1:]      ,dtype=val.dtype      ,name=__snake_case				)
																			    for key, val in model.input_signature.items()
																			    if key in model.dummy_inputs
																			}
																			a__					=					model(__snake_case				)
																			self.assertTrue(outputs_dict is not None				)






def 							__lowercase       (			):
							a__					=					Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       )
							return image







@require_tf
@require_vision
class 	snake_case_       (unittest.TestCase				):
					@cached_property
					def 			lowerCamelCase__(				self       :Any				) ->   Optional[int]:
												return (
												    EfficientFormerImageProcessor.from_pretrained('snap-research/efficientformer-l1-300'				)
												    if is_vision_available()
												    else None
												)
					@slow
					def 			lowerCamelCase__(				self       :int				) ->   List[str]:
												a__					=					TFEfficientFormerForImageClassification.from_pretrained('snap-research/efficientformer-l1-300'				)
												a__					=					self.default_image_processor
												a__					=					prepare_img()
												a__					=					image_processor(images=__snake_case      ,return_tensors='tf'				)
												# forward pass
												a__					=					model(**__snake_case      ,training=__snake_case				)
												# verify the logits
												a__					=					tf.TensorShape((1, 10_00)				)
												self.assertEqual(outputs.logits.shape      ,__snake_case				)
												a__					=					tf.constant([-0.05_55, 0.48_25, -0.08_52]				)
												self.assertTrue(np.allclose(outputs.logits[0, :3]      ,__snake_case      ,atol=1E-4				)				)



					@slow
					def 			lowerCamelCase__(				self       :str				) ->   Optional[int]:
												a__					=					TFEfficientFormerForImageClassificationWithTeacher.from_pretrained(
												    'snap-research/efficientformer-l1-300'				)
												a__					=					self.default_image_processor
												a__					=					prepare_img()
												a__					=					image_processor(images=__snake_case      ,return_tensors='tf'				)
												# forward pass
												a__					=					model(**__snake_case      ,training=__snake_case				)
												# verify the logits
												a__					=					tf.TensorShape((1, 10_00)				)
												self.assertEqual(outputs.logits.shape      ,__snake_case				)
												a__					=					tf.constant([-0.13_12, 0.43_53, -1.04_99]				)
												self.assertTrue(np.allclose(outputs.logits[0, :3]      ,__snake_case      ,atol=1E-4				)				)








import gc
import math
import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, logging, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


snake_case							:	Tuple					      =				logging.get_logger(__name__)

enable_full_determinism()







class 	snake_case_       (lowerCamelCase_     ,						lowerCamelCase_     ,						unittest.TestCase				):
					UpperCAmelCase__ :   str   				=      UNetaDModel
					UpperCAmelCase__ :   str   				=      '''sample'''
					@property
					def 			lowerCamelCase__(				self       :Optional[int]				) ->   List[str]:
												a__					=					4
												a__					=					3
												a__					=					(32, 32)

												a__					=					floats_tensor((batch_size, num_channels) + sizes				).to(__snake_case				)
												a__					=					torch.tensor([10]				).to(__snake_case				)

												return {"sample": noise, "timestep": time_step}
					@property
					def 			lowerCamelCase__(				self       :Tuple				) ->   Tuple:
												return (3, 32, 32)
					@property
					def 			lowerCamelCase__(				self       :List[str]				) ->   Optional[Any]:
												return (3, 32, 32)



					def 			lowerCamelCase__(				self       :str				) ->   Tuple:
												a__					=					{
												    'block_out_channels': (32, 64),
												    'down_block_types': ('DownBlock2D', 'AttnDownBlock2D'),
												    'up_block_types': ('AttnUpBlock2D', 'UpBlock2D'),
												    'attention_head_dim': 3,
												    'out_channels': 3,
												    'in_channels': 3,
												    'layers_per_block': 2,
												    'sample_size': 32,
												}
												a__					=					self.dummy_input
												return init_dict, inputs_dict







class 	snake_case_       (lowerCamelCase_     ,						lowerCamelCase_     ,						unittest.TestCase				):
					UpperCAmelCase__ :   int   				=      UNetaDModel
					UpperCAmelCase__ :   Any   				=      '''sample'''
					@property
					def 			lowerCamelCase__(				self       :Dict				) ->   List[str]:
												a__					=					4
												a__					=					4
												a__					=					(32, 32)

												a__					=					floats_tensor((batch_size, num_channels) + sizes				).to(__snake_case				)
												a__					=					torch.tensor([10]				).to(__snake_case				)

												return {"sample": noise, "timestep": time_step}
					@property
					def 			lowerCamelCase__(				self       :Any				) ->   str:
												return (4, 32, 32)
					@property
					def 			lowerCamelCase__(				self       :Any				) ->   Dict:
												return (4, 32, 32)
					def 			lowerCamelCase__(				self       :int				) ->   int:
												a__					=					{
												    'sample_size': 32,
												    'in_channels': 4,
												    'out_channels': 4,
												    'layers_per_block': 2,
												    'block_out_channels': (32, 64),
												    'attention_head_dim': 32,
												    'down_block_types': ('DownBlock2D', 'DownBlock2D'),
												    'up_block_types': ('UpBlock2D', 'UpBlock2D'),
												}
												a__					=					self.dummy_input
												return init_dict, inputs_dict
					def 			lowerCamelCase__(				self       :str				) ->   Any:
												a__				, a__					=					UNetaDModel.from_pretrained('fusing/unet-ldm-dummy-update'      ,output_loading_info=__snake_case				)

												self.assertIsNotNone(__snake_case				)
												self.assertEqual(len(loading_info['missing_keys']				)      ,0				)

												model.to(__snake_case				)
												a__					=					model(**self.dummy_input				).sample

												assert image is not None, "Make sure output is not None"
					@unittest.skipIf(torch_device != 'cuda'      ,'This test is supposed to run on GPU'				)
					def 			lowerCamelCase__(				self       :Tuple				) ->   Optional[int]:
												a__				, a__					=					UNetaDModel.from_pretrained('fusing/unet-ldm-dummy-update'      ,output_loading_info=__snake_case				)
												model.to(__snake_case				)
												a__					=					model(**self.dummy_input				).sample

												assert image is not None, "Make sure output is not None"
					@unittest.skipIf(torch_device != 'cuda'      ,'This test is supposed to run on GPU'				)
					def 			lowerCamelCase__(				self       :Union[str, Any]				) ->   int:
												# by defautl model loading will use accelerate as `low_cpu_mem_usage=True`
												a__				, a__					=					UNetaDModel.from_pretrained('fusing/unet-ldm-dummy-update'      ,output_loading_info=__snake_case				)
												model_accelerate.to(__snake_case				)
												model_accelerate.eval()

												a__					=					torch.randn(
												    1      ,model_accelerate.config.in_channels      ,model_accelerate.config.sample_size      ,model_accelerate.config.sample_size      ,generator=torch.manual_seed(0				)      ,)
												a__					=					noise.to(__snake_case				)
												a__					=					torch.tensor([10] * noise.shape[0]				).to(__snake_case				)

												a__					=					model_accelerate(__snake_case      ,__snake_case				)['sample']

												# two models don't need to stay in the device at the same time
												del model_accelerate
												torch.cuda.empty_cache()
												gc.collect()

												a__				, a__					=					UNetaDModel.from_pretrained(
												    'fusing/unet-ldm-dummy-update'      ,output_loading_info=__snake_case      ,low_cpu_mem_usage=__snake_case				)
												model_normal_load.to(__snake_case				)
												model_normal_load.eval()
												a__					=					model_normal_load(__snake_case      ,__snake_case				)['sample']

												assert torch_all_close(__snake_case      ,__snake_case      ,rtol=1E-3				)



					def 			lowerCamelCase__(				self       :str				) ->   Union[str, Any]:
												a__					=					UNetaDModel.from_pretrained('fusing/unet-ldm-dummy-update'				)
												model.eval()
												model.to(__snake_case				)

												a__					=					torch.randn(
												    1      ,model.config.in_channels      ,model.config.sample_size      ,model.config.sample_size      ,generator=torch.manual_seed(0				)      ,)
												a__					=					noise.to(__snake_case				)
												a__					=					torch.tensor([10] * noise.shape[0]				).to(__snake_case				)

												with torch.no_grad():
																			a__					=					model(__snake_case      ,__snake_case				).sample

												a__					=					output[0, -1, -3:, -3:].flatten().cpu()
												# fmt: off
												a__					=					torch.tensor([-13.32_58, -20.11_00, -15.98_73, -17.66_17, -23.05_96, -17.94_19, -13.36_75, -16.18_89, -12.38_00]				)
												# fmt: on

												self.assertTrue(torch_all_close(__snake_case      ,__snake_case      ,rtol=1E-3				)				)







class 	snake_case_       (lowerCamelCase_     ,						lowerCamelCase_     ,						unittest.TestCase				):
					UpperCAmelCase__ :   Dict   				=      UNetaDModel
					UpperCAmelCase__ :   Optional[Any]   				=      '''sample'''
					@property
					def 			lowerCamelCase__(				self       :Optional[Any]      ,__snake_case       :List[Any]=(32, 32)				) ->   Optional[int]:
												a__					=					4
												a__					=					3

												a__					=					floats_tensor((batch_size, num_channels) + sizes				).to(__snake_case				)
												a__					=					torch.tensor(batch_size * [10]				).to(dtype=torch.intaa      ,device=__snake_case				)

												return {"sample": noise, "timestep": time_step}
					@property
					def 			lowerCamelCase__(				self       :Tuple				) ->   Optional[int]:
												return (3, 32, 32)
					@property
					def 			lowerCamelCase__(				self       :Optional[Any]				) ->   Optional[int]:
												return (3, 32, 32)
					def 			lowerCamelCase__(				self       :Optional[Any]				) ->   List[str]:
												a__					=					{
												    'block_out_channels': [32, 64, 64, 64],
												    'in_channels': 3,
												    'layers_per_block': 1,
												    'out_channels': 3,
												    'time_embedding_type': 'fourier',
												    'norm_eps': 1E-6,
												    'mid_block_scale_factor': math.sqrt(2.0				),
												    'norm_num_groups': None,
												    'down_block_types': [
												        'SkipDownBlock2D',
												        'AttnSkipDownBlock2D',
												        'SkipDownBlock2D',
												        'SkipDownBlock2D',
												    ],
												    'up_block_types': [
												        'SkipUpBlock2D',
												        'SkipUpBlock2D',
												        'AttnSkipUpBlock2D',
												        'SkipUpBlock2D',
												    ],
												}
												a__					=					self.dummy_input
												return init_dict, inputs_dict
					@slow
					def 			lowerCamelCase__(				self       :str				) ->   Tuple:
												a__				, a__					=					UNetaDModel.from_pretrained('google/ncsnpp-celebahq-256'      ,output_loading_info=__snake_case				)
												self.assertIsNotNone(__snake_case				)
												self.assertEqual(len(loading_info['missing_keys']				)      ,0				)

												model.to(__snake_case				)
												a__					=					self.dummy_input
												a__					=					floats_tensor((4, 3) + (2_56, 2_56)				).to(__snake_case				)
												a__					=					noise
												a__					=					model(**__snake_case				)

												assert image is not None, "Make sure output is not None"
					@slow
					def 			lowerCamelCase__(				self       :Union[str, Any]				) ->   Dict:
												a__					=					UNetaDModel.from_pretrained('google/ncsnpp-celebahq-256'				)
												model.to(__snake_case				)

												a__					=					4
												a__					=					3
												a__					=					(2_56, 2_56)

												a__					=					torch.ones((batch_size, num_channels) + sizes				).to(__snake_case				)
												a__					=					torch.tensor(batch_size * [1E-4]				).to(__snake_case				)

												with torch.no_grad():
																			a__					=					model(__snake_case      ,__snake_case				).sample

												a__					=					output[0, -3:, -3:, -1].flatten().cpu()
												# fmt: off
												a__					=					torch.tensor([-48_42.86_91, -64_99.66_31, -38_00.19_53, -79_78.26_86, -1_09_80.71_29, -2_00_28.85_35, 81_48.28_22, 23_42.29_05, 5_67.76_08]				)
												# fmt: on

												self.assertTrue(torch_all_close(__snake_case      ,__snake_case      ,rtol=1E-2				)				)
					def 			lowerCamelCase__(				self       :Dict				) ->   int:
												a__					=					UNetaDModel.from_pretrained('fusing/ncsnpp-ffhq-ve-dummy-update'				)
												model.to(__snake_case				)

												a__					=					4
												a__					=					3
												a__					=					(32, 32)

												a__					=					torch.ones((batch_size, num_channels) + sizes				).to(__snake_case				)
												a__					=					torch.tensor(batch_size * [1E-4]				).to(__snake_case				)

												with torch.no_grad():
																			a__					=					model(__snake_case      ,__snake_case				).sample

												a__					=					output[0, -3:, -3:, -1].flatten().cpu()
												# fmt: off
												a__					=					torch.tensor([-0.03_25, -0.09_00, -0.08_69, -0.03_32, -0.07_25, -0.02_70, -0.01_01, 0.02_27, 0.02_56]				)
												# fmt: on

												self.assertTrue(torch_all_close(__snake_case      ,__snake_case      ,rtol=1E-2				)				)



					def 			lowerCamelCase__(				self       :int				) ->   str:
												# not required for this model
												pass




