import unittest

from transformers import ErnieMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      ErnieMForInformationExtraction,
      ErnieMForMultipleChoice,
      ErnieMForQuestionAnswering,
      ErnieMForSequenceClassification,
      ErnieMForTokenClassification,
      ErnieMModel,
  )
  from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST






class 							_SCREAMING_SNAKE_CASE:
   def __init__(    self							,     lowerCAmelCase_							,     lowerCAmelCase_=13							,     lowerCAmelCase_=7							,     lowerCAmelCase_=True							,     lowerCAmelCase_=True							,     lowerCAmelCase_=True							,     lowerCAmelCase_=99							,     lowerCAmelCase_=32							,     lowerCAmelCase_=5							,     lowerCAmelCase_=4							,     lowerCAmelCase_=37							,     lowerCAmelCase_="gelu"							,     lowerCAmelCase_=0.1							,     lowerCAmelCase_=0.1							,     lowerCAmelCase_=5_12							,     lowerCAmelCase_=16							,     lowerCAmelCase_=2							,     lowerCAmelCase_=0.02							,     lowerCAmelCase_=3							,     lowerCAmelCase_=4							,     lowerCAmelCase_=None							,     )	->int:
        a  :    Tuple				=						parent
        a  :    Dict				=						batch_size
        a  :    Dict				=						seq_length
        a  :    List[str]				=						is_training
        a  :    Optional[Any]				=						use_input_mask
        a  :    Tuple				=						use_labels
        a  :    List[str]				=						vocab_size
        a  :    Dict				=						hidden_size
        a  :    Dict				=						num_hidden_layers
        a  :    Optional[int]				=						num_attention_heads
        a  :    Union[str, Any]				=						intermediate_size
        a  :    Any				=						hidden_act
        a  :    List[str]				=						hidden_dropout_prob
        a  :    List[str]				=						attention_probs_dropout_prob
        a  :    Union[str, Any]				=						max_position_embeddings
        a  :    Optional[int]				=						type_vocab_size
        a  :    Union[str, Any]				=						type_sequence_label_size
        a  :    Dict				=						initializer_range
        a  :    int				=						num_labels
        a  :    Union[str, Any]				=						num_choices
        a  :    List[str]				=						scope
   def _lowercase(    self    )	->Any:
        a  :    Tuple				=						ids_tensor([self.batch_size, self.seq_length]							,     self.vocab_size    )

        a  :    Optional[int]				=						None
        if self.use_input_mask:
             a  :    str				=						random_attention_mask([self.batch_size, self.seq_length]    )

        a  :    Optional[Any]				=						None
        a  :    Any				=						None
        a  :    List[Any]				=						None
        if self.use_labels:
             a  :    Any				=						ids_tensor([self.batch_size]							,     self.type_sequence_label_size    )
             a  :    Optional[Any]				=						ids_tensor([self.batch_size, self.seq_length]							,     self.num_labels    )
             a  :    List[Any]				=						ids_tensor([self.batch_size]							,     self.num_choices    )

        a  :    str				=						self.get_config()

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
   def _lowercase(    self    )	->str:
        a  :    Optional[int]				=						ids_tensor([self.batch_size, self.seq_length]							,     self.vocab_size    )

        a  :    Union[str, Any]				=						None
        if self.use_input_mask:
             a  :    Dict				=						random_attention_mask([self.batch_size, self.seq_length]    )
        a  :    Dict				=						self.get_config()

        return config, input_ids, input_mask
   def _lowercase(    self    )	->Tuple:
        return ErnieMConfig(
            vocab_size=self.vocab_size							,     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							,     max_position_embeddings=self.max_position_embeddings							,     type_vocab_size=self.type_vocab_size							,     initializer_range=self.initializer_range							,     )
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->int:
        a  :    Union[str, Any]				=						ErnieMModel(config=lowerCAmelCase_    )
        model.to(lowerCAmelCase_    )
        model.eval()
        a  :    Optional[Any]				=						model(lowerCAmelCase_							,     return_dict=lowerCAmelCase_    )
        self.parent.assertEqual(result.last_hidden_state.shape							,     (self.batch_size, self.seq_length, self.hidden_size)    )
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->int:
        a  :    str				=						ErnieMForQuestionAnswering(config=lowerCAmelCase_    )
        model.to(lowerCAmelCase_    )
        model.eval()
        a  :    Union[str, Any]				=						model(
            lowerCAmelCase_							,     attention_mask=lowerCAmelCase_							,     start_positions=lowerCAmelCase_							,     end_positions=lowerCAmelCase_							,     )
        self.parent.assertEqual(result.start_logits.shape							,     (self.batch_size, self.seq_length)    )
        self.parent.assertEqual(result.end_logits.shape							,     (self.batch_size, self.seq_length)    )
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->Union[str, Any]:
        a  :    Dict				=						ErnieMForInformationExtraction(config=lowerCAmelCase_    )
        model.to(lowerCAmelCase_    )
        model.eval()
        a  :    Union[str, Any]				=						torch.ones_like(lowerCAmelCase_							,     dtype=torch.floataa    )
        a  :    Union[str, Any]				=						model(
            lowerCAmelCase_							,     attention_mask=lowerCAmelCase_							,     start_positions=lowerCAmelCase_							,     end_positions=lowerCAmelCase_							,     )
        self.parent.assertEqual(result.start_logits.shape							,     (self.batch_size, self.seq_length)    )
        self.parent.assertEqual(result.end_logits.shape							,     (self.batch_size, self.seq_length)    )
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->Tuple:
        a  :    Optional[int]				=						self.num_labels
        a  :    List[Any]				=						ErnieMForSequenceClassification(lowerCAmelCase_    )
        model.to(lowerCAmelCase_    )
        model.eval()
        a  :    Union[str, Any]				=						model(lowerCAmelCase_							,     attention_mask=lowerCAmelCase_							,     labels=lowerCAmelCase_    )
        self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.num_labels)    )
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->Dict:
        a  :    Union[str, Any]				=						self.num_labels
        a  :    List[Any]				=						ErnieMForTokenClassification(config=lowerCAmelCase_    )
        model.to(lowerCAmelCase_    )
        model.eval()
        input_ids.to(lowerCAmelCase_    )
        input_mask.to(lowerCAmelCase_    )
        token_labels.to(lowerCAmelCase_    )

        a  :    Union[str, Any]				=						model(lowerCAmelCase_							,     attention_mask=lowerCAmelCase_							,     labels=lowerCAmelCase_    )

        self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.seq_length, self.num_labels)    )
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->str:
        a  :    Dict				=						self.num_choices
        a  :    Optional[int]				=						ErnieMForMultipleChoice(config=lowerCAmelCase_    )
        model.to(lowerCAmelCase_    )
        model.eval()
        a  :    Any				=						input_ids.unsqueeze(1    ).expand(-1							,     self.num_choices							,     -1    ).contiguous()
        a  :    Tuple				=						input_mask.unsqueeze(1    ).expand(-1							,     self.num_choices							,     -1    ).contiguous()
        a  :    Union[str, Any]				=						model(
            lowerCAmelCase_							,     attention_mask=lowerCAmelCase_							,     labels=lowerCAmelCase_							,     )
        self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.num_choices)    )


   def _lowercase(    self    )	->Any:
        a  :    Optional[int]				=						self.prepare_config_and_inputs()
        (
            a							
        )  :    str				=						config_and_inputs
        a  :    Union[str, Any]				=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        return config, inputs_dict






@require_torch
class 							_SCREAMING_SNAKE_CASE(   snake_case__       ,      snake_case__       ,      unittest.TestCase	):
   UpperCamelCase_				:						Union[str, Any] 			=   (
       (
           ErnieMModel,
           ErnieMForMultipleChoice,
           ErnieMForQuestionAnswering,
           ErnieMForSequenceClassification,
           ErnieMForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   UpperCamelCase_				:						List[Any] 			=   ()
   UpperCamelCase_				:						str 			=   (
       {
           'feature-extraction': ErnieMModel,
           'question-answering': ErnieMForQuestionAnswering,
           'text-classification': ErnieMForSequenceClassification,
           'token-classification': ErnieMForTokenClassification,
           'zero-shot': ErnieMForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   UpperCamelCase_				:						Tuple 			=   False
   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )	->Optional[int]:
        if pipeline_test_casse_name == "QAPipelineTests":
             return True

        return False
   def _lowercase(    self    )	->Union[str, Any]:
        a  :    Dict				=						ErnieMModelTester(self    )
        a  :    Tuple				=						ConfigTester(self							,     config_class=lowerCAmelCase_							,     hidden_size=37    )
   def _lowercase(    self    )	->int:
        self.config_tester.run_common_tests()
   def _lowercase(    self    )	->Tuple:
        a  :    Tuple				=						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase_    )
   def _lowercase(    self    )	->Any:
        a  :    int				=						self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
             a  :    int				=						type
             self.model_tester.create_and_check_model(*lowerCAmelCase_    )
   def _lowercase(    self    )	->Optional[int]:
        a  :    List[Any]				=						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase_    )
   def _lowercase(    self    )	->List[str]:
        a  :    Tuple				=						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase_    )
   def _lowercase(    self    )	->Optional[Any]:
        a  :    Dict				=						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase_    )
   def _lowercase(    self    )	->str:
        a  :    Tuple				=						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_information_extraction(*lowerCAmelCase_    )
   def _lowercase(    self    )	->List[Any]:
        a  :    str				=						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase_    )


   @slow
   def _lowercase(    self    )	->Any:
        for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             a  :    str				=						ErnieMModel.from_pretrained(lowerCAmelCase_    )
             self.assertIsNotNone(lowerCAmelCase_    )






@require_torch
class 							_SCREAMING_SNAKE_CASE(   unittest.TestCase	):
   @slow
   def _lowercase(    self    )	->Dict:
        a  :    Optional[Any]				=						ErnieMModel.from_pretrained('''susnato/ernie-m-base_pytorch'''    )
        model.eval()
        a  :    Tuple				=						torch.tensor([[0, 1, 2, 3, 4, 5]]    )
        a  :    Dict				=						model(lowerCAmelCase_    )[0]

        # TODO Replace vocab size
        a  :    Tuple				=						7_68

        a  :    int				=						torch.Size((1, 6, hidden_size)    )
        self.assertEqual(output.shape							,     lowerCAmelCase_    )

        a  :    Union[str, Any]				=						torch.tensor(
            [[[-0.00_12, 0.12_45, -0.02_14], [-0.07_42, 0.02_44, -0.07_71], [-0.03_33, 0.11_64, -0.15_54]]]    )

        self.assertTrue(torch.allclose(output[:, :3, :3]							,     lowerCAmelCase_							,     atol=1e-3    )    )
from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .embeddings import GaussianFourierProjection, TimestepEmbedding, Timesteps
from .modeling_utils import ModelMixin
from .unet_ad_blocks import UNetMidBlockaD, get_down_block, get_up_block






@dataclass
class 							_SCREAMING_SNAKE_CASE(   snake_case__	):
   UpperCamelCase_				:						torch.FloatTensor






class 							_SCREAMING_SNAKE_CASE(   snake_case__       ,      snake_case__	):
   @register_to_config
   def __init__(    self							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = 3							,     lowerCAmelCase_ = 3							,     lowerCAmelCase_ = False							,     lowerCAmelCase_ = "positional"							,     lowerCAmelCase_ = 0							,     lowerCAmelCase_ = True							,     lowerCAmelCase_ = ("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D")							,     lowerCAmelCase_ = ("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D")							,     lowerCAmelCase_ = (2_24, 4_48, 6_72, 8_96)							,     lowerCAmelCase_ = 2							,     lowerCAmelCase_ = 1							,     lowerCAmelCase_ = 1							,     lowerCAmelCase_ = "conv"							,     lowerCAmelCase_ = "conv"							,     lowerCAmelCase_ = "silu"							,     lowerCAmelCase_ = 8							,     lowerCAmelCase_ = 32							,     lowerCAmelCase_ = 1e-5							,     lowerCAmelCase_ = "default"							,     lowerCAmelCase_ = True							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = None							,     )	->Tuple:
        super().__init__()

        a  :    List[Any]				=						sample_size
        a  :    List[Any]				=						block_out_channels[0] * 4

        # Check inputs
        if len(lowerCAmelCase_    ) != len(lowerCAmelCase_    ):
             raise ValueError(
                 F"""Must provide the same number of `down_block_types` as `up_block_types`. `down_block_types`: {down_block_types}. `up_block_types`: {up_block_types}."""    )

        if len(lowerCAmelCase_    ) != len(lowerCAmelCase_    ):
             raise ValueError(
                 F"""Must provide the same number of `block_out_channels` as `down_block_types`. `block_out_channels`: {block_out_channels}. `down_block_types`: {down_block_types}."""    )

        # input
        a  :    List[Any]				=						nn.Convad(lowerCAmelCase_							,     block_out_channels[0]							,     kernel_size=3							,     padding=(1, 1)    )

        # time
        if time_embedding_type == "fourier":
             a  :    List[Any]				=						GaussianFourierProjection(embedding_size=block_out_channels[0]							,     scale=16    )
             a  :    List[Any]				=						2 * block_out_channels[0]
        elif time_embedding_type == "positional":
             a  :    Dict				=						Timesteps(block_out_channels[0]							,     lowerCAmelCase_							,     lowerCAmelCase_    )
             a  :    List[str]				=						block_out_channels[0]

        a  :    List[str]				=						TimestepEmbedding(lowerCAmelCase_							,     lowerCAmelCase_    )

        # class embedding
        if class_embed_type is None and num_class_embeds is not None:
             a  :    Dict				=						nn.Embedding(lowerCAmelCase_							,     lowerCAmelCase_    )
        elif class_embed_type == "timestep":
             a  :    str				=						TimestepEmbedding(lowerCAmelCase_							,     lowerCAmelCase_    )
        elif class_embed_type == "identity":
             a  :    List[str]				=						nn.Identity(lowerCAmelCase_							,     lowerCAmelCase_    )
        else:
             a  :    Optional[Any]				=						None

        a  :    str				=						nn.ModuleList([]    )
        a  :    Any				=						None
        a  :    List[Any]				=						nn.ModuleList([]    )

        # down
        a  :    List[Any]				=						block_out_channels[0]
        for i, down_block_type in enumerate(lowerCAmelCase_    ):
             a  :    Dict				=						output_channel
             a  :    Union[str, Any]				=						block_out_channels[i]
             a  :    int				=						i == len(lowerCAmelCase_    ) - 1

             a  :    Tuple				=						get_down_block(
                 lowerCAmelCase_							,     num_layers=lowerCAmelCase_							,     in_channels=lowerCAmelCase_							,     out_channels=lowerCAmelCase_							,     temb_channels=lowerCAmelCase_							,     add_downsample=not is_final_block							,     resnet_eps=lowerCAmelCase_							,     resnet_act_fn=lowerCAmelCase_							,     resnet_groups=lowerCAmelCase_							,     attention_head_dim=attention_head_dim if attention_head_dim is not None else output_channel							,     downsample_padding=lowerCAmelCase_							,     resnet_time_scale_shift=lowerCAmelCase_							,     downsample_type=lowerCAmelCase_							,     )
             self.down_blocks.append(lowerCAmelCase_    )

        # mid
        a  :    int				=						UNetMidBlockaD(
            in_channels=block_out_channels[-1]							,     temb_channels=lowerCAmelCase_							,     resnet_eps=lowerCAmelCase_							,     resnet_act_fn=lowerCAmelCase_							,     output_scale_factor=lowerCAmelCase_							,     resnet_time_scale_shift=lowerCAmelCase_							,     attention_head_dim=attention_head_dim if attention_head_dim is not None else block_out_channels[-1]							,     resnet_groups=lowerCAmelCase_							,     add_attention=lowerCAmelCase_							,     )

        # up
        a  :    Optional[int]				=						list(reversed(lowerCAmelCase_    )    )
        a  :    Tuple				=						reversed_block_out_channels[0]
        for i, up_block_type in enumerate(lowerCAmelCase_    ):
             a  :    List[Any]				=						output_channel
             a  :    Optional[Any]				=						reversed_block_out_channels[i]
             a  :    Dict				=						reversed_block_out_channels[min(i + 1							,     len(lowerCAmelCase_    ) - 1    )]

             a  :    Any				=						i == len(lowerCAmelCase_    ) - 1

             a  :    List[Any]				=						get_up_block(
                 lowerCAmelCase_							,     num_layers=layers_per_block + 1							,     in_channels=lowerCAmelCase_							,     out_channels=lowerCAmelCase_							,     prev_output_channel=lowerCAmelCase_							,     temb_channels=lowerCAmelCase_							,     add_upsample=not is_final_block							,     resnet_eps=lowerCAmelCase_							,     resnet_act_fn=lowerCAmelCase_							,     resnet_groups=lowerCAmelCase_							,     attention_head_dim=attention_head_dim if attention_head_dim is not None else output_channel							,     resnet_time_scale_shift=lowerCAmelCase_							,     upsample_type=lowerCAmelCase_							,     )
             self.up_blocks.append(lowerCAmelCase_    )
             a  :    Any				=						output_channel

        # out
        a  :    str				=						norm_num_groups if norm_num_groups is not None else min(block_out_channels[0] // 4							,     32    )
        a  :    Tuple				=						nn.GroupNorm(num_channels=block_out_channels[0]							,     num_groups=lowerCAmelCase_							,     eps=lowerCAmelCase_    )
        a  :    Any				=						nn.SiLU()
        a  :    List[Any]				=						nn.Convad(block_out_channels[0]							,     lowerCAmelCase_							,     kernel_size=3							,     padding=1    )


   def _lowercase(    self							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_ = None							,     lowerCAmelCase_ = True							,     )	->Union[UNetaDOutput, Tuple]:
        # 0. center input if necessary
        if self.config.center_input_sample:
             a  :    Any				=						2 * sample - 1.0

        # 1. time
        a  :    Optional[Any]				=						timestep
        if not torch.is_tensor(lowerCAmelCase_    ):
             a  :    Dict				=						torch.tensor([timesteps]							,     dtype=torch.long							,     device=sample.device    )
        elif torch.is_tensor(lowerCAmelCase_    ) and len(timesteps.shape    ) == 0:
             a  :    Any				=						timesteps[None].to(sample.device    )

        # broadcast to batch dimension in a way that's compatible with ONNX/Core ML
        a  :    Optional[Any]				=						timesteps * torch.ones(sample.shape[0]							,     dtype=timesteps.dtype							,     device=timesteps.device    )

        a  :    Dict				=						self.time_proj(lowerCAmelCase_    )

        # timesteps does not contain any weights and will always return f32 tensors
        # but time_embedding might actually be running in fp16. so we need to cast here.
        # there might be better ways to encapsulate this.
        a  :    Optional[Any]				=						t_emb.to(dtype=self.dtype    )
        a  :    Dict				=						self.time_embedding(lowerCAmelCase_    )

        if self.class_embedding is not None:
             if class_labels is None:
                  raise ValueError('''class_labels should be provided when doing class conditioning'''    )

             if self.config.class_embed_type == "timestep":
                  a  :    List[str]				=						self.time_proj(lowerCAmelCase_    )

             a  :    Any				=						self.class_embedding(lowerCAmelCase_    ).to(dtype=self.dtype    )
             a  :    Optional[int]				=						emb + class_emb

        # 2. pre-process
        a  :    int				=						sample
        a  :    Dict				=						self.conv_in(lowerCAmelCase_    )

        # 3. down
        a  :    Union[str, Any]				=						(sample,)
        for downsample_block in self.down_blocks:
             if hasattr(lowerCAmelCase_							,     '''skip_conv'''    ):
                  a			,							a			,							a  :    str				=						downsample_block(
                      hidden_states=lowerCAmelCase_							,     temb=lowerCAmelCase_							,     skip_sample=lowerCAmelCase_    )
             else:
                  a			,							a  :    List[str]				=						downsample_block(hidden_states=lowerCAmelCase_							,     temb=lowerCAmelCase_    )

             down_block_res_samples += res_samples

        # 4. mid
        a  :    str				=						self.mid_block(lowerCAmelCase_							,     lowerCAmelCase_    )

        # 5. up
        a  :    int				=						None
        for upsample_block in self.up_blocks:
             a  :    List[str]				=						down_block_res_samples[-len(upsample_block.resnets    ) :]
             a  :    Any				=						down_block_res_samples[: -len(upsample_block.resnets    )]

             if hasattr(lowerCAmelCase_							,     '''skip_conv'''    ):
                  a			,							a  :    Any				=						upsample_block(lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )
             else:
                  a  :    Union[str, Any]				=						upsample_block(lowerCAmelCase_							,     lowerCAmelCase_							,     lowerCAmelCase_    )

        # 6. post-process
        a  :    Tuple				=						self.conv_norm_out(lowerCAmelCase_    )
        a  :    Optional[Any]				=						self.conv_act(lowerCAmelCase_    )
        a  :    Tuple				=						self.conv_out(lowerCAmelCase_    )

        if skip_sample is not None:
             sample += skip_sample

        if self.config.time_embedding_type == "fourier":
             a  :    Optional[Any]				=						timesteps.reshape((sample.shape[0], *([1] * len(sample.shape[1:]    )))    )
             a  :    int				=						sample / timesteps

        if not return_dict:
             return (sample,)

        return UNetaDOutput(sample=lowerCAmelCase_    )