






'''simple docstring'''



from typing import List, Optional, Tuple, Union

import torch
from torch import nn
from torch.nn import CrossEntropyLoss

from ... import AutoBackbone
from ...modeling_outputs import SemanticSegmenterOutput
from ...modeling_utils import PreTrainedModel
from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
from ...utils.backbone_utils import BackboneMixin
from .configuration_upernet import UperNetConfig


SCREAMING_SNAKE_CASE							=						[
    'openmmlab/upernet-convnext-tiny',
    # See all UperNet models at https://huggingface.co/models?filter=upernet
]

# General docstring
SCREAMING_SNAKE_CASE							=						'UperNetConfig'
class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Tuple  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		Union[int, Tuple[int, int]]  ,   UpperCAmelCase      :		Union[int, Tuple[int, int], str] = 0  ,   UpperCAmelCase      :		bool = False  ,   UpperCAmelCase      :		Union[int, Tuple[int, int]] = 1  ,   )	->	None:


       '''simple docstring'''

       super().__init__()
       lowercase       : List[Any]						=nn.Convad(
           in_channels=UpperCAmelCase  ,   out_channels=UpperCAmelCase  ,   kernel_size=UpperCAmelCase  ,   padding=UpperCAmelCase  ,   bias=UpperCAmelCase  ,   dilation=UpperCAmelCase  ,   )
       lowercase       : Dict						=nn.BatchNormad(UpperCAmelCase		)
       lowercase       : Any						=nn.ReLU()






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		torch.Tensor		)	->	torch.Tensor:


       '''simple docstring'''

       lowercase       : Tuple						=self.conv(UpperCAmelCase		)
       lowercase       : Tuple						=self.batch_norm(UpperCAmelCase		)
       lowercase       : Any						=self.activation(UpperCAmelCase		)

       return output





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		List[Any]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		int		)	->	None:


       '''simple docstring'''

       super().__init__()
       lowercase       : int						=[
           nn.AdaptiveAvgPoolad(UpperCAmelCase		),
           UperNetConvModule(UpperCAmelCase  ,   UpperCAmelCase  ,   kernel_size=1		),
       ]
       for i, layer in enumerate(self.layers		):
        self.add_module(str(UpperCAmelCase		)  ,   UpperCAmelCase		)






      def 					A__   (			self      :		Union[str, Any]  ,   UpperCAmelCase      :		torch.Tensor		)	->	torch.Tensor:


       '''simple docstring'''

       lowercase       : Tuple						=input
       for layer in self.layers:
        lowercase       : int						=layer(UpperCAmelCase		)
       return hidden_state





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Dict  ,   UpperCAmelCase      :		Tuple[int, ...]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		bool		)	->	None:


       '''simple docstring'''

       super().__init__()
       lowercase       : List[str]						=pool_scales
       lowercase       : Optional[Any]						=align_corners
       lowercase       : List[str]						=in_channels
       lowercase       : Dict						=channels
       lowercase       : List[str]						=[]
       for i, pool_scale in enumerate(UpperCAmelCase		):
        lowercase       : List[str]						=UperNetPyramidPoolingBlock(pool_scale=UpperCAmelCase  ,   in_channels=UpperCAmelCase  ,   channels=UpperCAmelCase		)
        self.blocks.append(UpperCAmelCase		)
        self.add_module(str(UpperCAmelCase		)  ,   UpperCAmelCase		)






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		torch.Tensor		)	->	List[torch.Tensor]:


       '''simple docstring'''

       lowercase       : Optional[int]						=[]
       for ppm in self.blocks:
        lowercase       : Optional[Any]						=ppm(UpperCAmelCase		)
        lowercase       : Any						=nn.functional.interpolate(
            UpperCAmelCase  ,   size=x.size()[2:]  ,   mode='''bilinear'''  ,   align_corners=self.align_corners		)
        ppm_outs.append(UpperCAmelCase		)
       return ppm_outs





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		List[Any]  ,   UpperCAmelCase      :		Tuple  ,   UpperCAmelCase      :		Union[str, Any]		)	->	List[str]:


       '''simple docstring'''

       super().__init__()

       lowercase       : Dict						=config
       lowercase       : str						=config.pool_scales  # e.g. (1, 2, 3, 6)
       lowercase       : Optional[int]						=in_channels
       lowercase       : Tuple						=config.hidden_size
       lowercase       : int						=False
       lowercase       : List[str]						=nn.Convad(self.channels  ,   config.num_labels  ,   kernel_size=1		)

       # PSP Module
       lowercase       : Tuple						=UperNetPyramidPoolingModule(
           self.pool_scales  ,   self.in_channels[-1]  ,   self.channels  ,   align_corners=self.align_corners  ,   )
       lowercase       : Optional[Any]						=UperNetConvModule(
           self.in_channels[-1] + len(self.pool_scales		) * self.channels  ,   self.channels  ,   kernel_size=3  ,   padding=1  ,   )
       # FPN Module
       lowercase       : Tuple						=nn.ModuleList()
       lowercase       : Any						=nn.ModuleList()
       for in_channels in self.in_channels[:-1]:  # skip the top layer
        lowercase       : List[Any]						=UperNetConvModule(UpperCAmelCase  ,   self.channels  ,   kernel_size=1		)
        lowercase       : Optional[int]						=UperNetConvModule(self.channels  ,   self.channels  ,   kernel_size=3  ,   padding=1		)
        self.lateral_convs.append(UpperCAmelCase		)
        self.fpn_convs.append(UpperCAmelCase		)

       lowercase       : str						=UperNetConvModule(
           len(self.in_channels		) * self.channels  ,   self.channels  ,   kernel_size=3  ,   padding=1  ,   )






      def 					A__   (			self      :		str		)	->	str:


       '''simple docstring'''

       self.apply(self._init_weights		)






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		List[Any]		)	->	List[str]:


       '''simple docstring'''

       if isinstance(UpperCAmelCase  ,   nn.Convad		):
        module.weight.data.normal_(mean=0.0  ,   std=self.config.initializer_range		)
        if module.bias is not None:
         module.bias.data.zero_()






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		Any		)	->	Any:


       '''simple docstring'''

       lowercase       : Optional[Any]						=inputs[-1]
       lowercase       : Tuple						=[x]
       psp_outs.extend(self.psp_modules(UpperCAmelCase		)		)
       lowercase       : List[Any]						=torch.cat(UpperCAmelCase  ,   dim=1		)
       lowercase       : str						=self.bottleneck(UpperCAmelCase		)

       return output






      def 					A__   (			self      :		Optional[Any]  ,   UpperCAmelCase      :		torch.Tensor		)	->	torch.Tensor:


       '''simple docstring'''

       lowercase       : Union[str, Any]						=[lateral_conv(encoder_hidden_states[i]		) for i, lateral_conv in enumerate(self.lateral_convs		)]

       laterals.append(self.psp_forward(UpperCAmelCase		)		)

       # build top-down path
       lowercase       : Any						=len(UpperCAmelCase		)
       for i in range(used_backbone_levels - 1  ,   0  ,   -1		):
        lowercase       : Optional[int]						=laterals[i - 1].shape[2:]
        lowercase       : Tuple						=laterals[i - 1] + nn.functional.interpolate(
            laterals[i]  ,   size=UpperCAmelCase  ,   mode='''bilinear'''  ,   align_corners=self.align_corners		)

       # build outputs
       lowercase       : Optional[Any]						=[self.fpn_convs[i](laterals[i]		) for i in range(used_backbone_levels - 1		)]
       # append psp feature
       fpn_outs.append(laterals[-1]		)

       for i in range(used_backbone_levels - 1  ,   0  ,   -1		):
        lowercase       : Optional[int]						=nn.functional.interpolate(
            fpn_outs[i]  ,   size=fpn_outs[0].shape[2:]  ,   mode='''bilinear'''  ,   align_corners=self.align_corners		)
       lowercase       : Union[str, Any]						=torch.cat(UpperCAmelCase  ,   dim=1		)
       lowercase       : str						=self.fpn_bottleneck(UpperCAmelCase		)
       lowercase       : int						=self.classifier(UpperCAmelCase		)

       return output





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		int  ,   UpperCAmelCase      :		str  ,   UpperCAmelCase      :		int = 2  ,   UpperCAmelCase      :		int = 3  ,   UpperCAmelCase      :		Union[int, Tuple[int, int]] = 1		)	->	None:


       '''simple docstring'''

       super().__init__()

       lowercase       : int						=config
       lowercase       : Any						=config.auxiliary_in_channels
       lowercase       : int						=config.auxiliary_channels
       lowercase       : Dict						=config.auxiliary_num_convs
       lowercase       : List[Any]						=config.auxiliary_concat_input
       lowercase       : List[str]						=in_index

       lowercase       : Dict						=(kernel_size // 2) * dilation
       lowercase       : Union[str, Any]						=[]
       convs.append(
           UperNetConvModule(
               self.in_channels  ,   self.channels  ,   kernel_size=UpperCAmelCase  ,   padding=UpperCAmelCase  ,   dilation=UpperCAmelCase		)		)
       for i in range(self.num_convs - 1		):
        convs.append(
            UperNetConvModule(
                self.channels  ,   self.channels  ,   kernel_size=UpperCAmelCase  ,   padding=UpperCAmelCase  ,   dilation=UpperCAmelCase		)		)
       if self.num_convs == 0:
        lowercase       : int						=nn.Identity()
       else:
        lowercase       : Optional[Any]						=nn.Sequential(*UpperCAmelCase		)
       if self.concat_input:
        lowercase       : Tuple						=UperNetConvModule(
            self.in_channels + self.channels  ,   self.channels  ,   kernel_size=UpperCAmelCase  ,   padding=kernel_size // 2		)

       lowercase       : List[Any]						=nn.Convad(self.channels  ,   config.num_labels  ,   kernel_size=1		)






      def 					A__   (			self      :		List[str]		)	->	Tuple:


       '''simple docstring'''

       self.apply(self._init_weights		)






      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		str		)	->	Dict:


       '''simple docstring'''

       if isinstance(UpperCAmelCase  ,   nn.Convad		):
        module.weight.data.normal_(mean=0.0  ,   std=self.config.initializer_range		)
        if module.bias is not None:
         module.bias.data.zero_()






      def 					A__   (			self      :		List[str]  ,   UpperCAmelCase      :		torch.Tensor		)	->	torch.Tensor:


       '''simple docstring'''

       lowercase       : Dict						=encoder_hidden_states[self.in_index]
       lowercase       : List[str]						=self.convs(UpperCAmelCase		)
       if self.concat_input:
        lowercase       : str						=self.conv_cat(torch.cat([hidden_states, output]  ,   dim=1		)		)
       lowercase       : List[str]						=self.classifier(UpperCAmelCase		)
       return output





class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      UpperCamelCase_             =      UperNetConfig
      UpperCamelCase_             =      '''pixel_values'''
      UpperCamelCase_             =      True






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		List[Any]		)	->	Any:


       '''simple docstring'''

       if isinstance(UpperCAmelCase  ,   UpperCAmelCase		):
        module.backbone.init_weights()
        module.decode_head.init_weights()
        module.auxiliary_head.init_weights()






      def 					A__   (			self      :		Optional[int]		)	->	List[Any]:


       '''simple docstring'''

       self.backbone.init_weights()
       self.decode_head.init_weights()
       self.auxiliary_head.init_weights()






      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		Optional[Any]=False		)	->	List[str]:


       '''simple docstring'''

       if isinstance(UpperCAmelCase  ,   UpperCAmelCase		):
        lowercase       : List[Any]						=value





SCREAMING_SNAKE_CASE							=						r'\n    Parameters:\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n        config ([`UperNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

SCREAMING_SNAKE_CASE							=						r'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using\n            [`AutoImageProcessor`]. See [`SegformerImageProcessor.__call__`] for details.\n        output_attentions (`bool`, *optional*):\n            Whether or not to return the attentions tensors of all attention layers in case the backbone has them. See\n            `attentions` under returned tensors for more detail.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers of the backbone. See `hidden_states` under\n            returned tensors for more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'
@add_start_docstrings(
    '''UperNet framework leveraging any vision backbone e.g. for ADE20k, CityScapes.'''					,							__A					,							)
class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      def __init__(			self      :		Union[str, Any]  ,   UpperCAmelCase      :		str		)	->	Optional[int]:


       '''simple docstring'''

       super().__init__(UpperCAmelCase		)

       lowercase       : Optional[int]						=AutoBackbone.from_config(config.backbone_config		)

       # Semantic segmentation head(s)
       lowercase       : Optional[Any]						=UperNetHead(UpperCAmelCase  ,   in_channels=self.backbone.channels		)
       lowercase       : Optional[int]						=UperNetFCNHead(UpperCAmelCase		) if config.use_auxiliary_head else None

       # Initialize weights and apply final processing
       self.post_init()






      @add_start_docstrings_to_model_forward(UPERNET_INPUTS_DOCSTRING.format('''batch_size, sequence_length'''		)		)
      @replace_return_docstrings(output_type=UpperCAmelCase  ,   config_class=_CONFIG_FOR_DOC		)
      def 					A__   (			self      :		Dict  ,   UpperCAmelCase      :		Optional[torch.Tensor] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   UpperCAmelCase      :		Optional[torch.Tensor] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   )	->	Union[tuple, SemanticSegmenterOutput]:


       '''simple docstring'''

       lowercase       : Tuple						=return_dict if return_dict is not None else self.config.use_return_dict
       lowercase       : List[str]						=(
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       lowercase       : Any						=output_attentions if output_attentions is not None else self.config.output_attentions

       lowercase       : Union[str, Any]						=self.backbone.forward_with_filtered_kwargs(
           UpperCAmelCase  ,   output_hidden_states=UpperCAmelCase  ,   output_attentions=UpperCAmelCase		)
       lowercase       : List[Any]						=outputs.feature_maps

       lowercase       : Dict						=self.decode_head(UpperCAmelCase		)
       lowercase       : List[Any]						=nn.functional.interpolate(UpperCAmelCase  ,   size=pixel_values.shape[2:]  ,   mode='''bilinear'''  ,   align_corners=UpperCAmelCase		)

       lowercase       : str						=None
       if self.auxiliary_head is not None:
        lowercase       : Optional[Any]						=self.auxiliary_head(UpperCAmelCase		)
        lowercase       : int						=nn.functional.interpolate(
            UpperCAmelCase  ,   size=pixel_values.shape[2:]  ,   mode='''bilinear'''  ,   align_corners=UpperCAmelCase		)

       lowercase       : Optional[int]						=None
       if labels is not None:
        if self.config.num_labels == 1:
         raise ValueError('''The number of labels should be greater than one'''		)
        else:
         # compute weighted loss
         lowercase       : Optional[Any]						=CrossEntropyLoss(ignore_index=self.config.loss_ignore_index		)
         lowercase       : List[Any]						=loss_fct(UpperCAmelCase  ,   UpperCAmelCase		)
         lowercase       : Any						=loss_fct(UpperCAmelCase  ,   UpperCAmelCase		)
         lowercase       : List[str]						=main_loss + self.config.auxiliary_loss_weight * auxiliary_loss

       if not return_dict:
        if output_hidden_states:
         lowercase       : Tuple						=(logits,) + outputs[1:]
        else:
         lowercase       : Tuple						=(logits,) + outputs[2:]
        return ((loss,) + output) if loss is not None else output

       return SemanticSegmenterOutput(
           loss=UpperCAmelCase  ,   logits=UpperCAmelCase  ,   hidden_states=outputs.hidden_states  ,   attentions=outputs.attentions  ,   )










import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class       __lowerCAmelCase					(       _UpperCamelCase      ):


	'''simple docstring'''





	_A													=				(EulerDiscreteScheduler,)
	_A													=				10

	def    snake_case__(						self:						List[Any],					**lowerCamelCase_:						Any			):
			lowercase__					:      Tuple      =		{
			    'num_train_timesteps': 1100,
			    'beta_start': 0.0_0_0_1,
			    'beta_end': 0.0_2,
			    'beta_schedule': 'linear',
			}

			config.update(**lowerCamelCase_			)
			return config

	def    snake_case__(						self:						Optional[Any]			):
			for timesteps in [10, 50, 100, 1000]:
					self.check_over_configs(num_train_timesteps=lowerCamelCase_			)

	def    snake_case__(						self:						Optional[int]			):
			for beta_start, beta_end in zip([0.0_0_0_0_1, 0.0_0_0_1, 0.0_0_1],					[0.0_0_0_2, 0.0_0_2, 0.0_2]			):
					self.check_over_configs(beta_start=lowerCamelCase_,					beta_end=lowerCamelCase_			)

	def    snake_case__(						self:						Optional[Any]			):
			for schedule in ["linear", "scaled_linear"]:
					self.check_over_configs(beta_schedule=lowerCamelCase_			)

	def    snake_case__(						self:						str			):
			for prediction_type in ["epsilon", "v_prediction"]:
					self.check_over_configs(prediction_type=lowerCamelCase_			)

	def    snake_case__(						self:						List[str]			):
			lowercase__					:      List[str]      =		self.scheduler_classes[0]
			lowercase__					:      Tuple      =		self.get_scheduler_config()
			lowercase__					:      List[str]      =		scheduler_class(**lowerCamelCase_			)

			scheduler.set_timesteps(self.num_inference_steps			)

			lowercase__					:      Any      =		torch.manual_seed(0			)

			lowercase__					:      int      =		self.dummy_model()
			lowercase__					:      Tuple      =		self.dummy_sample_deter * scheduler.init_noise_sigma
			lowercase__					:      Union[str, Any]      =		sample.to(lowerCamelCase_			)

			for i, t in enumerate(scheduler.timesteps			):
					lowercase__					:      Dict      =		scheduler.scale_model_input(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      Dict      =		model(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      Tuple      =		scheduler.step(lowerCamelCase_,					lowerCamelCase_,					lowerCamelCase_,					generator=lowerCamelCase_			)
					lowercase__					:      List[str]      =		output.prev_sample

			lowercase__					:      Any      =		torch.sum(torch.abs(lowerCamelCase_			)			)
			lowercase__					:      Optional[Any]      =		torch.mean(torch.abs(lowerCamelCase_			)			)

			assert abs(result_sum.item() - 1_0.0_8_0_7			) < 1E-2
			assert abs(result_mean.item() - 0.0_1_3_1			) < 1E-3

	def    snake_case__(						self:						Dict			):
			lowercase__					:      Dict      =		self.scheduler_classes[0]
			lowercase__					:      str      =		self.get_scheduler_config(prediction_type='v_prediction'			)
			lowercase__					:      Optional[int]      =		scheduler_class(**lowerCamelCase_			)

			scheduler.set_timesteps(self.num_inference_steps			)

			lowercase__					:      Optional[int]      =		torch.manual_seed(0			)

			lowercase__					:      str      =		self.dummy_model()
			lowercase__					:      Optional[int]      =		self.dummy_sample_deter * scheduler.init_noise_sigma
			lowercase__					:      Optional[int]      =		sample.to(lowerCamelCase_			)

			for i, t in enumerate(scheduler.timesteps			):
					lowercase__					:      int      =		scheduler.scale_model_input(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      str      =		model(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      Tuple      =		scheduler.step(lowerCamelCase_,					lowerCamelCase_,					lowerCamelCase_,					generator=lowerCamelCase_			)
					lowercase__					:      List[str]      =		output.prev_sample

			lowercase__					:      Dict      =		torch.sum(torch.abs(lowerCamelCase_			)			)
			lowercase__					:      Optional[Any]      =		torch.mean(torch.abs(lowerCamelCase_			)			)

			assert abs(result_sum.item() - 0.0_0_0_2			) < 1E-2
			assert abs(result_mean.item() - 2.2676E-06			) < 1E-3

	def    snake_case__(						self:						List[Any]			):
			lowercase__					:      List[str]      =		self.scheduler_classes[0]
			lowercase__					:      Dict      =		self.get_scheduler_config()
			lowercase__					:      List[str]      =		scheduler_class(**lowerCamelCase_			)

			scheduler.set_timesteps(self.num_inference_steps,					device=lowerCamelCase_			)

			lowercase__					:      Dict      =		torch.manual_seed(0			)

			lowercase__					:      Union[str, Any]      =		self.dummy_model()
			lowercase__					:      Any      =		self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
			lowercase__					:      List[Any]      =		sample.to(lowerCamelCase_			)

			for t in scheduler.timesteps:
					lowercase__					:      Optional[int]      =		scheduler.scale_model_input(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      Dict      =		model(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      List[Any]      =		scheduler.step(lowerCamelCase_,					lowerCamelCase_,					lowerCamelCase_,					generator=lowerCamelCase_			)
					lowercase__					:      Union[str, Any]      =		output.prev_sample

			lowercase__					:      Union[str, Any]      =		torch.sum(torch.abs(lowerCamelCase_			)			)
			lowercase__					:      Union[str, Any]      =		torch.mean(torch.abs(lowerCamelCase_			)			)

			assert abs(result_sum.item() - 1_0.0_8_0_7			) < 1E-2
			assert abs(result_mean.item() - 0.0_1_3_1			) < 1E-3





	def    snake_case__(						self:						Optional[int]			):
			lowercase__					:      Tuple      =		self.scheduler_classes[0]
			lowercase__					:      Tuple      =		self.get_scheduler_config()
			lowercase__					:      Dict      =		scheduler_class(**lowerCamelCase_,					use_karras_sigmas=lowerCamelCase_			)

			scheduler.set_timesteps(self.num_inference_steps,					device=lowerCamelCase_			)

			lowercase__					:      int      =		torch.manual_seed(0			)

			lowercase__					:      Optional[int]      =		self.dummy_model()
			lowercase__					:      str      =		self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
			lowercase__					:      List[str]      =		sample.to(lowerCamelCase_			)

			for t in scheduler.timesteps:
					lowercase__					:      Any      =		scheduler.scale_model_input(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      Optional[Any]      =		model(lowerCamelCase_,					lowerCamelCase_			)

					lowercase__					:      Tuple      =		scheduler.step(lowerCamelCase_,					lowerCamelCase_,					lowerCamelCase_,					generator=lowerCamelCase_			)
					lowercase__					:      Optional[Any]      =		output.prev_sample

			lowercase__					:      int      =		torch.sum(torch.abs(lowerCamelCase_			)			)
			lowercase__					:      Dict      =		torch.mean(torch.abs(lowerCamelCase_			)			)

			assert abs(result_sum.item() - 1_2_4.5_2_2_9_9_4_9_9_5_1_1_7_1_9			) < 1E-2
			assert abs(result_mean.item() - 0.1_6_2_1_3_9_3_2_6_3_3_3_9_9_9_6_3			) < 1E-3


