





'''simple docstring'''



from logging import getLogger
from typing import Any, Callable, List, Optional, Union

import numpy as np
import PIL
import torch

from ...schedulers import DDPMScheduler
from ..onnx_utils import ORT_TO_NP_TYPE, OnnxRuntimeModel
from ..pipeline_utils import ImagePipelineOutput
from . import StableDiffusionUpscalePipeline


snake_case_   :  Union[str, Any]								=      getLogger(__name__)


snake_case_   :  int								=      4
snake_case_   :  Dict								=      7

snake_case_   :  List[Any]								=      {
    '''float16''': torch.floataa,
    '''float32''': torch.floataa,
}



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






					"""simple docstring"""

					if isinstance(_UpperCamelCase ,   torch.Tensor				):
										return image
					elif isinstance(_UpperCamelCase ,   PIL.Image.Image				):
										_UpperCamelCase											=   [image]

					if isinstance(image[0] ,   PIL.Image.Image				):
										_UpperCamelCase				,	_UpperCamelCase											=   image[0].size
										_UpperCamelCase				,	_UpperCamelCase											=   (x - x % 64 for x in (w, h))  # resize to integer multiple of 32

										_UpperCamelCase											=   [np.array(i.resize((w, h)				)				)[None, :] for i in image]
										_UpperCamelCase											=   np.concatenate(_UpperCamelCase ,   axis=0				)
										_UpperCamelCase											=   np.array(_UpperCamelCase				).astype(np.floataa				) / 255.0
										_UpperCamelCase											=   image.transpose(0 ,   3 ,   1 ,   2				)
										_UpperCamelCase											=   2.0 * image - 1.0
										_UpperCamelCase											=   torch.from_numpy(_UpperCamelCase				)
					elif isinstance(image[0] ,   torch.Tensor				):
										_UpperCamelCase											=   torch.cat(_UpperCamelCase ,   dim=0				)

					return image

class     A_ (  lowerCAmelCase_  ):

			'''simple docstring'''





			def __init__(					self			,     A_			,     A_			,     A_			,     A_			,     A_			,     A_			,     A_ = 3_50			,     ):
								super().__init__(
								    vae=A_			,     text_encoder=A_			,     tokenizer=A_			,     unet=A_			,     low_res_scheduler=A_			,     scheduler=A_			,     safety_checker=A_			,     feature_extractor=A_			,     watermarker=A_			,     max_noise_level=A_			,     )




			def __call__(					self			,     A_			,     A_			,     A_ = 75			,     A_ = 9.0			,     A_ = 20			,     A_ = None			,     A_ = 1			,     A_ = 0.0			,     A_ = None			,     A_ = None			,     A_ = None			,     A_ = None			,     A_ = "pil"			,     A_ = True			,     A_ = None			,     A_ = 1			,     ):
								self.check_inputs(A_			,     A_			,     A_			,     A_   )

								# 2. Define call parameters
								if prompt is not None and isinstance(A_			,     A_   ):
													_UpperCamelCase											=   1
								elif prompt is not None and isinstance(A_			,     A_   ):
													_UpperCamelCase											=   len(A_   )
								else:
													_UpperCamelCase											=   prompt_embeds.shape[0]

								_UpperCamelCase											=   self._execution_device
								# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
								# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
								# corresponds to doing no classifier free guidance.
								_UpperCamelCase											=   guidance_scale > 1.0

								# 3. Encode input prompt
								_UpperCamelCase											=   self._encode_prompt(
								    A_			,     A_			,     A_			,     A_			,     A_			,     prompt_embeds=A_			,     negative_prompt_embeds=A_			,     )

								_UpperCamelCase											=   ORT_TO_PT_TYPE[str(text_embeddings.dtype   )]

								# 4. Preprocess image
								_UpperCamelCase											=   preprocess(A_   )
								_UpperCamelCase											=   image.cpu()

								# 5. set timesteps
								self.scheduler.set_timesteps(A_			,     device=A_   )
								_UpperCamelCase											=   self.scheduler.timesteps

								# 5. Add noise to image
								_UpperCamelCase											=   torch.tensor([noise_level]			,     dtype=torch.long			,     device=A_   )
								_UpperCamelCase											=   torch.randn(image.shape			,     generator=A_			,     device=A_			,     dtype=A_   )
								_UpperCamelCase											=   self.low_res_scheduler.add_noise(A_			,     A_			,     A_   )

								_UpperCamelCase											=   2 if do_classifier_free_guidance else 1
								_UpperCamelCase											=   np.concatenate([image] * batch_multiplier * num_images_per_prompt   )
								_UpperCamelCase											=   np.concatenate([noise_level] * image.shape[0]   )

								# 6. Prepare latent variables
								_UpperCamelCase				,	_UpperCamelCase											=   image.shape[2:]
								_UpperCamelCase											=   self.prepare_latents(
								    batch_size * num_images_per_prompt			,     A_			,     A_			,     A_			,     A_			,     A_			,     A_			,     A_			,     )

								# 7. Check that sizes of image and latents match
								_UpperCamelCase											=   image.shape[1]
								if NUM_LATENT_CHANNELS + num_channels_image != NUM_UNET_INPUT_CHANNELS:
													raise ValueError(
													    "Incorrect configuration settings! The config of `pipeline.unet` expects"
													    F" {NUM_UNET_INPUT_CHANNELS} but received `num_channels_latents`: {NUM_LATENT_CHANNELS} +"
													    F" `num_channels_image`: {num_channels_image} "
													    F" = {NUM_LATENT_CHANNELS+num_channels_image}. Please verify the config of"
													    " `pipeline.unet` or your `image` input."   )

								# 8. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
								_UpperCamelCase											=   self.prepare_extra_step_kwargs(A_			,     A_   )

								_UpperCamelCase											=   next(
								    (input.type for input in self.unet.model.get_inputs() if input.name == "timestep")			,     "tensor(float)"   )
								_UpperCamelCase											=   ORT_TO_NP_TYPE[timestep_dtype]

								# 9. Denoising loop
								_UpperCamelCase											=   len(A_   ) - num_inference_steps * self.scheduler.order
								with self.progress_bar(total=A_   ) as progress_bar:
													for i, t in enumerate(A_   ):
																		# expand the latents if we are doing classifier free guidance
																		_UpperCamelCase											=   np.concatenate([latents] * 2   ) if do_classifier_free_guidance else latents

																		# concat latents, mask, masked_image_latents in the channel dimension
																		_UpperCamelCase											=   self.scheduler.scale_model_input(A_			,     A_   )
																		_UpperCamelCase											=   np.concatenate([latent_model_input, image]			,     axis=1   )

																		# timestep to tensor
																		_UpperCamelCase											=   np.array([t]			,     dtype=A_   )

																		# predict the noise residual
																		_UpperCamelCase											=   self.unet(
																		    sample=A_			,     timestep=A_			,     encoder_hidden_states=A_			,     class_labels=noise_level.astype(np.intaa   )			,     )[0]

																		# perform guidance
																		if do_classifier_free_guidance:
																							_UpperCamelCase				,	_UpperCamelCase											=   np.split(A_			,     2   )
																		_UpperCamelCase											=   noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)

																		# compute the previous noisy sample x_t -> x_t-1
																		_UpperCamelCase											=   self.scheduler.step(
																		    torch.from_numpy(A_   )			,     A_			,     A_			,     **A_   ).prev_sample

																		# call the callback, if provided
																		if i == len(A_   ) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
																							progress_bar.update()
																							if callback is not None and i % callback_steps == 0:
																												callback(A_			,     A_			,     A_   )

        # 10. Post-processing
								_UpperCamelCase											=   self.decode_latents(latents.float()   )

								# 11. Convert to PIL
								if output_type == "pil":
													_UpperCamelCase											=   self.numpy_to_pil(A_   )

								if not return_dict:
													return (image,)

								return ImagePipelineOutput(images=A_   )




			def       a	(					self			,     A_   ):
								_UpperCamelCase											=   1 / 0.0_8333 * latents
								_UpperCamelCase											=   self.vae(latent_sample=A_   )[0]
								_UpperCamelCase											=   np.clip(image / 2 + 0.5			,     0			,     1   )
								_UpperCamelCase											=   image.transpose((0, 2, 3, 1)   )
								return image




			def       a	(					self			,     A_			,     A_			,     A_			,     A_			,     A_			,     A_ = None			,     A_ = None			,     ):
								if prompt is not None and isinstance(A_			,     A_   ):
													_UpperCamelCase											=   1
								elif prompt is not None and isinstance(A_			,     A_   ):
													_UpperCamelCase											=   len(A_   )
								else:
													_UpperCamelCase											=   prompt_embeds.shape[0]

								if prompt_embeds is None:
													_UpperCamelCase											=   self.tokenizer(
													    A_			,     padding="max_length"			,     max_length=self.tokenizer.model_max_length			,     truncation=A_			,     return_tensors="pt"			,     )
													_UpperCamelCase											=   text_inputs.input_ids
													_UpperCamelCase											=   self.tokenizer(A_			,     padding="longest"			,     return_tensors="pt"   ).input_ids

													if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(
													    A_			,     A_   ):
																		_UpperCamelCase											=   self.tokenizer.batch_decode(
																		    untruncated_ids[:, self.tokenizer.model_max_length - 1 : -1]   )
																		logger.warning(
																		    "The following part of your input was truncated because CLIP can only handle sequences up to"
																		    F" {self.tokenizer.model_max_length} tokens: {removed_text}"   )

													# no positional arguments to text_encoder
													_UpperCamelCase											=   self.text_encoder(
													    input_ids=text_input_ids.int().to(A_   )			,     )
													_UpperCamelCase											=   prompt_embeds[0]

								_UpperCamelCase				,	_UpperCamelCase				,	_UpperCamelCase											=   prompt_embeds.shape
								# duplicate text embeddings for each generation per prompt, using mps friendly method
								_UpperCamelCase											=   prompt_embeds.repeat(1			,     A_   )
								_UpperCamelCase											=   prompt_embeds.reshape(bs_embed * num_images_per_prompt			,     A_			,     -1   )

								# get unconditional embeddings for classifier free guidance
								if do_classifier_free_guidance and negative_prompt_embeds is None:
													_UpperCamelCase											=   42
													if negative_prompt is None:
																		_UpperCamelCase											=   [""] * batch_size
													elif type(A_   ) is not type(A_   ):
																		raise TypeError(
																		    F"`negative_prompt` should be the same type to `prompt`, but got {type(A_   )} !="
																		    F" {type(A_   )}."   )
													elif isinstance(A_			,     A_   ):
																		_UpperCamelCase											=   [negative_prompt]
													elif batch_size != len(A_   ):
																		raise ValueError(
																		    F"`negative_prompt`: {negative_prompt} has batch size {len(A_   )}, but `prompt`:"
																		    F" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches"
																		    " the batch size of `prompt`."   )
													else:
																		_UpperCamelCase											=   negative_prompt

													_UpperCamelCase											=   text_input_ids.shape[-1]
													_UpperCamelCase											=   self.tokenizer(
													    A_			,     padding="max_length"			,     max_length=A_			,     truncation=A_			,     return_tensors="pt"			,     )

													# if hasattr(uncond_input, "attention_mask"):
													#     attention_mask = uncond_input.attention_mask.to(device)
													# else:
													#     attention_mask = None

													_UpperCamelCase											=   self.text_encoder(
													    input_ids=uncond_input.input_ids.int().to(A_   )			,     )
													_UpperCamelCase											=   uncond_embeddings[0]

								if do_classifier_free_guidance:
													_UpperCamelCase											=   uncond_embeddings.shape[1]
													# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
													_UpperCamelCase											=   uncond_embeddings.repeat(1			,     A_   )
													_UpperCamelCase											=   uncond_embeddings.reshape(batch_size * num_images_per_prompt			,     A_			,     -1   )

													# For classifier free guidance, we need to do two forward passes.
													# Here we concatenate the unconditional and text embeddings into a single batch
													# to avoid doing two forward passes
													_UpperCamelCase											=   np.concatenate([uncond_embeddings, prompt_embeds]   )

								return prompt_embeds










'''simple docstring'''



import collections
import inspect
import unittest

from transformers import DinatConfig
from transformers.testing_utils import require_natten, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import DinatBackbone, DinatForImageClassification, DinatModel
			from transformers.models.dinat.modeling_dinat import DINAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor

class     A_ :

			'''simple docstring'''





			def __init__(					self			,     A_			,     A_=13			,     A_=64			,     A_=4			,     A_=3			,     A_=16			,     A_=[1, 2, 1]			,     A_=[2, 4, 8]			,     A_=3			,     A_=[[3], [1, 2], [1]]			,     A_=2.0			,     A_=True			,     A_=0.0			,     A_=0.0			,     A_=0.1			,     A_="gelu"			,     A_=True			,     A_=0.02			,     A_=1e-5			,     A_=True			,     A_=None			,     A_=True			,     A_=10			,     A_=["stage1", "stage2"]			,     A_=[1, 2]			,     ):
								_UpperCamelCase											=   parent
								_UpperCamelCase											=   batch_size
								_UpperCamelCase											=   image_size
								_UpperCamelCase											=   patch_size
								_UpperCamelCase											=   num_channels
								_UpperCamelCase											=   embed_dim
								_UpperCamelCase											=   depths
								_UpperCamelCase											=   num_heads
								_UpperCamelCase											=   kernel_size
								_UpperCamelCase											=   dilations
								_UpperCamelCase											=   mlp_ratio
								_UpperCamelCase											=   qkv_bias
								_UpperCamelCase											=   hidden_dropout_prob
								_UpperCamelCase											=   attention_probs_dropout_prob
								_UpperCamelCase											=   drop_path_rate
								_UpperCamelCase											=   hidden_act
								_UpperCamelCase											=   patch_norm
								_UpperCamelCase											=   layer_norm_eps
								_UpperCamelCase											=   initializer_range
								_UpperCamelCase											=   is_training
								_UpperCamelCase											=   scope
								_UpperCamelCase											=   use_labels
								_UpperCamelCase											=   num_labels
								_UpperCamelCase											=   out_features
								_UpperCamelCase											=   out_indices




			def       a	(					self   ):
								_UpperCamelCase											=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

								_UpperCamelCase											=   None
								if self.use_labels:
													_UpperCamelCase											=   ids_tensor([self.batch_size]			,     self.num_labels   )

								_UpperCamelCase											=   self.get_config()

								return config, pixel_values, labels




			def       a	(					self   ):
								return DinatConfig(
								    num_labels=self.num_labels			,     image_size=self.image_size			,     patch_size=self.patch_size			,     num_channels=self.num_channels			,     embed_dim=self.embed_dim			,     depths=self.depths			,     num_heads=self.num_heads			,     kernel_size=self.kernel_size			,     dilations=self.dilations			,     mlp_ratio=self.mlp_ratio			,     qkv_bias=self.qkv_bias			,     hidden_dropout_prob=self.hidden_dropout_prob			,     attention_probs_dropout_prob=self.attention_probs_dropout_prob			,     drop_path_rate=self.drop_path_rate			,     hidden_act=self.hidden_act			,     patch_norm=self.patch_norm			,     layer_norm_eps=self.layer_norm_eps			,     initializer_range=self.initializer_range			,     out_features=self.out_features			,     out_indices=self.out_indices			,     )




			def       a	(					self			,     A_			,     A_			,     A_   ):
								_UpperCamelCase											=   DinatModel(config=A_   )
								model.to(A_   )
								model.eval()
								_UpperCamelCase											=   model(A_   )

								_UpperCamelCase											=   _UpperCamelCase											=   (config.image_size // config.patch_size) // (2 ** (len(config.depths   ) - 1))
								_UpperCamelCase											=   int(config.embed_dim * 2 ** (len(config.depths   ) - 1)   )

								self.parent.assertEqual(
								    result.last_hidden_state.shape			,     (self.batch_size, expected_height, expected_width, expected_dim)   )




			def       a	(					self			,     A_			,     A_			,     A_   ):
								_UpperCamelCase											=   DinatForImageClassification(A_   )
								model.to(A_   )
								model.eval()
								_UpperCamelCase											=   model(A_			,     labels=A_   )
								self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_labels)   )

								# test greyscale images
								_UpperCamelCase											=   1
								_UpperCamelCase											=   DinatForImageClassification(A_   )
								model.to(A_   )
								model.eval()

								_UpperCamelCase											=   floats_tensor([self.batch_size, 1, self.image_size, self.image_size]   )
								_UpperCamelCase											=   model(A_   )
								self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_labels)   )




			def       a	(					self			,     A_			,     A_			,     A_   ):
								_UpperCamelCase											=   DinatBackbone(config=A_   )
								model.to(A_   )
								model.eval()
								_UpperCamelCase											=   model(A_   )

								# verify hidden states
								self.parent.assertEqual(len(result.feature_maps   )			,     len(config.out_features   )   )
								self.parent.assertListEqual(list(result.feature_maps[0].shape   )			,     [self.batch_size, model.channels[0], 16, 16]   )

								# verify channels
								self.parent.assertEqual(len(model.channels   )			,     len(config.out_features   )   )

								# verify backbone works with out_features=None
								_UpperCamelCase											=   None
								_UpperCamelCase											=   DinatBackbone(config=A_   )
								model.to(A_   )
								model.eval()
								_UpperCamelCase											=   model(A_   )

								# verify feature maps
								self.parent.assertEqual(len(result.feature_maps   )			,     1   )
								self.parent.assertListEqual(list(result.feature_maps[0].shape   )			,     [self.batch_size, model.channels[-1], 4, 4]   )

								# verify channels
								self.parent.assertEqual(len(model.channels   )			,     1   )




			def       a	(					self   ):
								_UpperCamelCase											=   self.prepare_config_and_inputs()
								_UpperCamelCase				,	_UpperCamelCase				,	_UpperCamelCase											=   config_and_inputs
								_UpperCamelCase											=   {"pixel_values": pixel_values}
								return config, inputs_dict




@require_natten
@require_torch
class     A_ (  lowerCAmelCase_    ,			lowerCAmelCase_    ,			unittest.TestCase  ):

			'''simple docstring'''





			_lowerCAmelCase						=    (
			    (
			        DinatModel,
			        DinatForImageClassification,
			        DinatBackbone,
			    )
			    if is_torch_available()
			    else ()
			)
			_lowerCAmelCase						=    (
			    {"""feature-extraction""": DinatModel, """image-classification""": DinatForImageClassification}
			    if is_torch_available()
			    else {}
			)
			_lowerCAmelCase						=    False

			_lowerCAmelCase						=    False
			_lowerCAmelCase						=    False
			_lowerCAmelCase						=    False
			_lowerCAmelCase						=    False




			def       a	(					self   ):
								_UpperCamelCase											=   DinatModelTester(self   )
								_UpperCamelCase											=   ConfigTester(self			,     config_class=A_			,     embed_dim=37   )




			def       a	(					self   ):
								self.create_and_test_config_common_properties()
								self.config_tester.create_and_test_config_to_json_string()
								self.config_tester.create_and_test_config_to_json_file()
								self.config_tester.create_and_test_config_from_and_save_pretrained()
								self.config_tester.create_and_test_config_with_num_labels()
								self.config_tester.check_config_can_be_init_without_params()
								self.config_tester.check_config_arguments_init()




			def       a	(					self   ):
								return




			def       a	(					self   ):
								_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*A_   )




			def       a	(					self   ):
								_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*A_   )




			def       a	(					self   ):
								_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_backbone(*A_   )




			@unittest.skip(reason="Dinat does not use inputs_embeds"   )
			def       a	(					self   ):
								pass




			@unittest.skip(reason="Dinat does not use feedforward chunking"   )
			def       a	(					self   ):
								pass




			def       a	(					self   ):
								_UpperCamelCase				,	_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
													_UpperCamelCase											=   model_class(A_   )
													self.assertIsInstance(model.get_input_embeddings()			,     (nn.Module)   )
													_UpperCamelCase											=   model.get_output_embeddings()
													self.assertTrue(x is None or isinstance(A_			,     nn.Linear   )   )




			def       a	(					self   ):
								_UpperCamelCase				,	_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs_for_common()

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

													_UpperCamelCase											=   ["pixel_values"]
													self.assertListEqual(arg_names[:1]			,     A_   )




			def       a	(					self   ):
								self.skipTest("Dinat's attention operation is handled entirely by NATTEN."   )




			def       a	(					self			,     A_			,     A_			,     A_			,     A_   ):
								_UpperCamelCase											=   model_class(A_   )
								model.to(A_   )
								model.eval()

								with torch.no_grad():
													_UpperCamelCase											=   model(**self._prepare_for_class(A_			,     A_   )   )

								_UpperCamelCase											=   outputs.hidden_states

								_UpperCamelCase											=   getattr(
								    self.model_tester			,     "expected_num_hidden_layers"			,     len(self.model_tester.depths   ) + 1   )
								self.assertEqual(len(A_   )			,     A_   )

								# Dinat has a different seq_length
								_UpperCamelCase											=   (
								    config.patch_size
								    if isinstance(config.patch_size			,     collections.abc.Iterable   )
								    else (config.patch_size, config.patch_size)
								)

								_UpperCamelCase											=   image_size[0] // patch_size[0]
								_UpperCamelCase											=   image_size[1] // patch_size[1]

								self.assertListEqual(
								    list(hidden_states[0].shape[-3:]   )			,     [height, width, self.model_tester.embed_dim]			,     )

								if model_class.__name__ != "DinatBackbone":
													_UpperCamelCase											=   outputs.reshaped_hidden_states
													self.assertEqual(len(A_   )			,     A_   )

													_UpperCamelCase				,	_UpperCamelCase				,	_UpperCamelCase				,	_UpperCamelCase											=   reshaped_hidden_states[0].shape
													_UpperCamelCase											=   (
													    reshaped_hidden_states[0].view(A_			,     A_			,     A_			,     A_   ).permute(0			,     2			,     3			,     1   )
													)
													self.assertListEqual(
													    list(reshaped_hidden_states.shape[-3:]   )			,     [height, width, self.model_tester.embed_dim]			,     )




			def       a	(					self   ):
								_UpperCamelCase				,	_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs_for_common()

								_UpperCamelCase											=   (
								    self.model_tester.image_size
								    if isinstance(self.model_tester.image_size			,     collections.abc.Iterable   )
								    else (self.model_tester.image_size, self.model_tester.image_size)
								)

								for model_class in self.all_model_classes:
													_UpperCamelCase											=   True
													self.check_hidden_states_output(A_			,     A_			,     A_			,     A_   )

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

													self.check_hidden_states_output(A_			,     A_			,     A_			,     A_   )




			@slow
			def       a	(					self   ):
								for model_name in DINAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													_UpperCamelCase											=   DinatModel.from_pretrained(A_   )
													self.assertIsNotNone(A_   )




			def       a	(					self   ):
								_UpperCamelCase				,	_UpperCamelCase											=   self.model_tester.prepare_config_and_inputs_for_common()

								_UpperCamelCase											=   _config_zero_init(A_   )
								for model_class in self.all_model_classes:
													_UpperCamelCase											=   model_class(config=A_   )
													for name, param in model.named_parameters():
																		if "embeddings" not in name and param.requires_grad:
																							self.assertIn(
																							    ((param.data.mean() * 1e9).round() / 1e9).item()			,     [0.0, 1.0]			,     msg=F"Parameter {name} of model {model_class} seems not properly initialized"			,     )




@require_natten
@require_vision
@require_torch
class     A_ (  unittest.TestCase  ):

			'''simple docstring'''





			@cached_property
			def       a	(					self   ):
								return AutoImageProcessor.from_pretrained("shi-labs/dinat-mini-in1k-224"   ) if is_vision_available() else None




			@slow
			def       a	(					self   ):
								_UpperCamelCase											=   DinatForImageClassification.from_pretrained("shi-labs/dinat-mini-in1k-224"   ).to(A_   )
								_UpperCamelCase											=   self.default_image_processor

								_UpperCamelCase											=   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   )
								_UpperCamelCase											=   image_processor(images=A_			,     return_tensors="pt"   ).to(A_   )

								# forward pass
								with torch.no_grad():
													_UpperCamelCase											=   model(**A_   )

								# verify the logits
								_UpperCamelCase											=   torch.Size((1, 10_00)   )
								self.assertEqual(outputs.logits.shape			,     A_   )
								_UpperCamelCase											=   torch.tensor([-0.1545, -0.7667, 0.4642]   ).to(A_   )
								self.assertTrue(torch.allclose(outputs.logits[0, :3]			,     A_			,     atol=1e-4   )   )




@require_torch
@require_natten
class     A_ (  unittest.TestCase    ,			lowerCAmelCase_  ):

			'''simple docstring'''





			_lowerCAmelCase						=    (DinatBackbone,) if is_torch_available() else ()
			_lowerCAmelCase						=    DinatConfig




			def       a	(					self   ):
								_UpperCamelCase											=   DinatModelTester(self   )



