



'''simple docstring'''

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


snake_case_			=     logging.get_logger(__name__)

snake_case_			=     {
    'microsoft/focalnet-tiny': 'https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json',
}


class 	a__     (				snake_case__,			snake_case__	):
	__magic_name__		:    Any	    =     """focalnet"""


	def __init__(self : List[str],					__UpperCAmelCase : Tuple=224,					__UpperCAmelCase : Optional[Any]=4,					__UpperCAmelCase : Any=3,					__UpperCAmelCase : Optional[int]=96,					__UpperCAmelCase : int=False,					__UpperCAmelCase : List[Any]=[192, 384, 768, 768],					__UpperCAmelCase : int=[2, 2, 6, 2],					__UpperCAmelCase : Optional[int]=[2, 2, 2, 2],					__UpperCAmelCase : str=[3, 3, 3, 3],					__UpperCAmelCase : Union[str, Any]="gelu",					__UpperCAmelCase : Optional[Any]=4.0,					__UpperCAmelCase : str=0.0,					__UpperCAmelCase : List[Any]=0.1,					__UpperCAmelCase : Optional[int]=False,					__UpperCAmelCase : str=1e-4,					__UpperCAmelCase : Any=False,					__UpperCAmelCase : List[Any]=False,					__UpperCAmelCase : Tuple=False,					__UpperCAmelCase : List[Any]=0.02,					__UpperCAmelCase : List[str]=1e-5,					__UpperCAmelCase : Optional[Any]=32,					__UpperCAmelCase : Union[str, Any]=None,					__UpperCAmelCase : Dict=None,					**__UpperCAmelCase : Union[str, Any],					)     ->			Optional[int]:

					"""simple docstring"""

					super().__init__(**UpperCAmelCase_      )

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= image_size
					SCREAMING_SNAKE_CASE  :						List[Any]      					= patch_size
					SCREAMING_SNAKE_CASE  :						List[str]      					= num_channels
					SCREAMING_SNAKE_CASE  :						Dict      					= embed_dim
					SCREAMING_SNAKE_CASE  :						int      					= use_conv_embed
					SCREAMING_SNAKE_CASE  :						Dict      					= hidden_sizes
					SCREAMING_SNAKE_CASE  :						Any      					= depths
					SCREAMING_SNAKE_CASE  :						List[Any]      					= focal_levels
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= focal_windows
					SCREAMING_SNAKE_CASE  :						str      					= hidden_act
					SCREAMING_SNAKE_CASE  :						Dict      					= mlp_ratio
					SCREAMING_SNAKE_CASE  :						Any      					= hidden_dropout_prob
					SCREAMING_SNAKE_CASE  :						Any      					= drop_path_rate
					SCREAMING_SNAKE_CASE  :						Any      					= use_layerscale
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= layerscale_value
					SCREAMING_SNAKE_CASE  :						Tuple      					= use_post_layernorm
					SCREAMING_SNAKE_CASE  :						Dict      					= use_post_layernorm_in_modulation
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= normalize_modulator
					SCREAMING_SNAKE_CASE  :						int      					= initializer_range
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= layer_norm_eps
					SCREAMING_SNAKE_CASE  :						Dict      					= encoder_stride
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= ['''stem'''] + [F'''stage{idx}''' for idx in range(1,					len(self.depths      ) + 1      )]
					SCREAMING_SNAKE_CASE					,					SCREAMING_SNAKE_CASE  :						Tuple      					= get_aligned_output_features_output_indices(
					    out_features=UpperCAmelCase_,					out_indices=UpperCAmelCase_,					stage_names=self.stage_names      )









'''simple docstring'''

from typing import List, Optional, Tuple, Union

import torch

from ...models import UNetaDModel
from ...schedulers import ScoreSdeVeScheduler
from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput


class 	a__     (				_lowercase	):
	__magic_name__		:    UNetaDModel
	__magic_name__		:    ScoreSdeVeScheduler


	def __init__(self : List[str],					__UpperCAmelCase : UNetaDModel,					__UpperCAmelCase : ScoreSdeVeScheduler      )     ->			Tuple:

					"""simple docstring"""

					super().__init__()
					self.register_modules(unet=__UpperCAmelCase,					scheduler=__UpperCAmelCase      )






	@torch.no_grad()
	def __call__(self : int,					__UpperCAmelCase : int = 1,					__UpperCAmelCase : int = 2000,					__UpperCAmelCase : Optional[Union[torch.Generator, List[torch.Generator]]] = None,					__UpperCAmelCase : Optional[str] = "pil",					__UpperCAmelCase : bool = True,					**__UpperCAmelCase : List[str],					)     ->			Union[ImagePipelineOutput, Tuple]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= self.unet.config.sample_size
					SCREAMING_SNAKE_CASE  :						Dict      					= (batch_size, 3, img_size, img_size)

					SCREAMING_SNAKE_CASE  :						List[Any]      					= self.unet

					SCREAMING_SNAKE_CASE  :						str      					= randn_tensor(__UpperCAmelCase,					generator=__UpperCAmelCase      ) * self.scheduler.init_noise_sigma
					SCREAMING_SNAKE_CASE  :						Any      					= sample.to(self.device      )

					self.scheduler.set_timesteps(__UpperCAmelCase      )
					self.scheduler.set_sigmas(__UpperCAmelCase      )

					for i, t in enumerate(self.progress_bar(self.scheduler.timesteps      )      ):
									SCREAMING_SNAKE_CASE  :						int      					= self.scheduler.sigmas[i] * torch.ones(shape[0],					device=self.device      )

									# correction step
									for _ in range(self.scheduler.config.correct_steps      ):
													SCREAMING_SNAKE_CASE  :						Any      					= self.unet(__UpperCAmelCase,					__UpperCAmelCase      ).sample
													SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= self.scheduler.step_correct(__UpperCAmelCase,					__UpperCAmelCase,					generator=__UpperCAmelCase      ).prev_sample

									# prediction step
									SCREAMING_SNAKE_CASE  :						str      					= model(__UpperCAmelCase,					__UpperCAmelCase      ).sample
									SCREAMING_SNAKE_CASE  :						Dict      					= self.scheduler.step_pred(__UpperCAmelCase,					__UpperCAmelCase,					__UpperCAmelCase,					generator=__UpperCAmelCase      )

									SCREAMING_SNAKE_CASE					,					SCREAMING_SNAKE_CASE  :						Optional[int]      					= output.prev_sample, output.prev_sample_mean

					SCREAMING_SNAKE_CASE  :						Dict      					= sample_mean.clamp(0,					1      )
					SCREAMING_SNAKE_CASE  :						str      					= sample.cpu().permute(0,					2,					3,					1      ).numpy()
					if output_type == "pil":
									SCREAMING_SNAKE_CASE  :						int      					= self.numpy_to_pil(__UpperCAmelCase      )

					if not return_dict:
									return (sample,)

					return ImagePipelineOutput(images=__UpperCAmelCase      )




