


'''simple docstring'''






import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
  import torch

  from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
  from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import AutoImageProcessor






class        __snake_case	:







    """simple docstring"""



    def __init__(       self   :  str   ,						lowerCamelCase   :  Any   ,						lowerCamelCase   :  Optional[Any]=13   ,						lowerCamelCase   :  int=32   ,						lowerCamelCase   :  List[str]=3   ,						lowerCamelCase   :  int=4   ,						lowerCamelCase   :  Tuple=[10, 20, 30, 40]   ,						lowerCamelCase   :  Optional[int]=[2, 2, 3, 2]   ,						lowerCamelCase   :  int=True   ,						lowerCamelCase   :  Tuple=True   ,						lowerCamelCase   :  Union[str, Any]=37   ,						lowerCamelCase   :  Dict="gelu"   ,						lowerCamelCase   :  int=10   ,						lowerCamelCase   :  Any=0.02   ,						lowerCamelCase   :  Dict=["stage2", "stage3", "stage4"]   ,						lowerCamelCase   :  Tuple=[2, 3, 4]   ,						lowerCamelCase   :  Dict=None   ,						)       ->  Dict:
      lowerCAmelCase_      :				Optional[int]      =       parent
      lowerCAmelCase_      :				Any      =       batch_size
      lowerCAmelCase_      :				Tuple      =       image_size
      lowerCAmelCase_      :				List[Any]      =       num_channels
      lowerCAmelCase_      :				Any      =       num_stages
      lowerCAmelCase_      :				int      =       hidden_sizes
      lowerCAmelCase_      :				Tuple      =       depths
      lowerCAmelCase_      :				Dict      =       is_training
      lowerCAmelCase_      :				List[Any]      =       use_labels
      lowerCAmelCase_      :				Optional[int]      =       intermediate_size
      lowerCAmelCase_      :				Optional[Any]      =       hidden_act
      lowerCAmelCase_      :				Optional[Any]      =       num_labels
      lowerCAmelCase_      :				str      =       initializer_range
      lowerCAmelCase_      :				Dict      =       out_features
      lowerCAmelCase_      :				List[Any]      =       out_indices
      lowerCAmelCase_      :				str      =       scope

    def __lowercase       (       self   :  List[str]		)       ->  List[str]:
      lowerCAmelCase_      :				Tuple      =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

      lowerCAmelCase_      :				Optional[int]      =       None
      if self.use_labels:
        lowerCAmelCase_      :				int      =       ids_tensor([self.batch_size]   ,						self.num_labels		)

      lowerCAmelCase_      :				int      =       self.get_config()

      return config, pixel_values, labels

    def __lowercase       (       self   :  str		)       ->  List[str]:
      return ConvNextVaConfig(
          num_channels=self.num_channels   ,						hidden_sizes=self.hidden_sizes   ,						depths=self.depths   ,						num_stages=self.num_stages   ,						hidden_act=self.hidden_act   ,						is_decoder=lowerCamelCase   ,						initializer_range=self.initializer_range   ,						out_features=self.out_features   ,						out_indices=self.out_indices   ,						num_labels=self.num_labels   ,						)

    def __lowercase       (       self   :  List[str]   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  Optional[int]		)       ->  List[Any]:
      lowerCAmelCase_      :				Tuple      =       ConvNextVaModel(config=lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.eval()
      lowerCAmelCase_      :				int      =       model(lowerCamelCase		)
      # expected last hidden states: B, C, H // 32, W // 32
      self.parent.assertEqual(
          result.last_hidden_state.shape   ,						(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)   ,						)

    def __lowercase       (       self   :  Optional[Any]   ,						lowerCamelCase   :  Tuple   ,						lowerCamelCase   :  Dict   ,						lowerCamelCase   :  int		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				Any      =       ConvNextVaForImageClassification(lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.eval()
      lowerCAmelCase_      :				Optional[Any]      =       model(lowerCamelCase   ,						labels=lowerCamelCase		)
      self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels)		)

    def __lowercase       (       self   :  str   ,						lowerCamelCase   :  Optional[Any]   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  Optional[int]		)       ->  int:
      lowerCAmelCase_      :				List[Any]      =       ConvNextVaBackbone(config=lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.eval()
      lowerCAmelCase_      :				int      =       model(lowerCamelCase		)

      # 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, self.hidden_sizes[1], 4, 4]		)

      # verify channels
      self.parent.assertEqual(len(model.channels		)   ,						len(config.out_features		)		)
      self.parent.assertListEqual(model.channels   ,						config.hidden_sizes[1:]		)

      # verify backbone works with out_features=None
      lowerCAmelCase_      :				Union[str, Any]      =       None
      lowerCAmelCase_      :				Any      =       ConvNextVaBackbone(config=lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.eval()
      lowerCAmelCase_      :				Any      =       model(lowerCamelCase		)

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

      # verify channels
      self.parent.assertEqual(len(model.channels		)   ,						1		)
      self.parent.assertListEqual(model.channels   ,						[config.hidden_sizes[-1]]		)

    def __lowercase       (       self   :  Dict		)       ->  int:
      lowerCAmelCase_      :				List[str]      =       self.prepare_config_and_inputs()
      lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_      :				Any      =       config_and_inputs
      lowerCAmelCase_      :				Tuple      =       {"""pixel_values""": pixel_values}
      return config, inputs_dict





    def __lowercase       (       self   :  Tuple		)       ->  Dict:
      lowerCAmelCase_      :				Tuple      =       self.prepare_config_and_inputs()
      lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_      :				Any      =       config_and_inputs
      lowerCAmelCase_      :				Optional[int]      =       {"""pixel_values""": pixel_values, """labels""": labels}
      return config, inputs_dict







@require_torch
class        __snake_case	(       _SCREAMING_SNAKE_CASE     ,_SCREAMING_SNAKE_CASE     ,unittest.TestCase):







    """simple docstring"""



    lowercase       			= (
        (
            ConvNextVaModel,
            ConvNextVaForImageClassification,
            ConvNextVaBackbone,
        )
        if is_torch_available()
        else ()
    )
    lowercase       			= (
        {'feature-extraction': ConvNextVaModel, 'image-classification': ConvNextVaForImageClassification}
        if is_torch_available()
        else {}
    )

    lowercase       			= False
    lowercase       			= False
    lowercase       			= False
    lowercase       			= False
    lowercase       			= False

    def __lowercase       (       self   :  Any		)       ->  Any:
      lowerCAmelCase_      :				Dict      =       ConvNextVaModelTester(self		)
      lowerCAmelCase_      :				Tuple      =       ConfigTester(self   ,						config_class=lowerCamelCase   ,						has_text_modality=lowerCamelCase   ,						hidden_size=37		)

    def __lowercase       (       self   :  List[str]		)       ->  Dict:
      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 __lowercase       (       self   :  Dict		)       ->  List[Any]:
      return

    @unittest.skip(reason="""ConvNextV2 does not use inputs_embeds"""		)
    def __lowercase       (       self   :  Optional[int]		)       ->  List[str]:
      pass

    @unittest.skip(reason="""ConvNextV2 does not support input and output embeddings"""		)
    def __lowercase       (       self   :  Union[str, Any]		)       ->  int:
      pass

    @unittest.skip(reason="""ConvNextV2 does not use feedforward chunking"""		)
    def __lowercase       (       self   :  str		)       ->  List[Any]:
      pass

    def __lowercase       (       self   :  Optional[int]		)       ->  List[Any]:
      if not self.model_tester.is_training:
        return

      for model_class in self.all_model_classes:
        lowerCAmelCase_,							lowerCAmelCase_      :				Dict      =       self.model_tester.prepare_config_and_inputs_with_labels()
        lowerCAmelCase_      :				Any      =       True

        if model_class.__name__ in [
            *get_values(lowerCamelCase		),
            *get_values(lowerCamelCase		),
        ]:
          continue

        lowerCAmelCase_      :				List[Any]      =       model_class(lowerCamelCase		)
        model.to(lowerCamelCase		)
        model.train()
        lowerCAmelCase_      :				List[str]      =       self._prepare_for_class(lowerCamelCase   ,						lowerCamelCase   ,						return_labels=lowerCamelCase		)
        lowerCAmelCase_      :				Union[str, Any]      =       model(**lowerCamelCase		).loss
        loss.backward()

    def __lowercase       (       self   :  Optional[int]		)       ->  Any:
      if not self.model_tester.is_training:
        return

      for model_class in self.all_model_classes:
        lowerCAmelCase_,							lowerCAmelCase_      :				int      =       self.model_tester.prepare_config_and_inputs_with_labels()
        lowerCAmelCase_      :				Tuple      =       False
        lowerCAmelCase_      :				int      =       True

        if (
            model_class.__name__
            in [*get_values(lowerCamelCase		), *get_values(lowerCamelCase		)]
            or not model_class.supports_gradient_checkpointing
        ):
          continue

        lowerCAmelCase_      :				List[str]      =       model_class(lowerCamelCase		)
        model.to(lowerCamelCase		)
        model.gradient_checkpointing_enable()
        model.train()
        lowerCAmelCase_      :				int      =       self._prepare_for_class(lowerCamelCase   ,						lowerCamelCase   ,						return_labels=lowerCamelCase		)
        lowerCAmelCase_      :				Dict      =       model(**lowerCamelCase		).loss
        loss.backward()

    def __lowercase       (       self   :  List[Any]		)       ->  int:
      lowerCAmelCase_,							lowerCAmelCase_      :				Tuple      =       self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowerCAmelCase_      :				str      =       model_class(lowerCamelCase		)
        lowerCAmelCase_      :				List[Any]      =       inspect.signature(model.forward		)
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        lowerCAmelCase_      :				Optional[Any]      =       [*signature.parameters.keys()]

        lowerCAmelCase_      :				Any      =       ["""pixel_values"""]
        self.assertListEqual(arg_names[:1]   ,						lowerCamelCase		)

    def __lowercase       (       self   :  List[Any]		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				Union[str, Any]      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*lowerCamelCase		)

    def __lowercase       (       self   :  Optional[Any]		)       ->  List[Any]:
      def check_hidden_states_output(lowerCamelCase   :  Optional[int]   ,						lowerCamelCase   :  List[Any]   ,						lowerCamelCase   :  int		):
        lowerCAmelCase_      :				Optional[int]      =       model_class(lowerCamelCase		)
        model.to(lowerCamelCase		)
        model.eval()

        with torch.no_grad():
          lowerCAmelCase_      :				int      =       model(**self._prepare_for_class(lowerCamelCase   ,						lowerCamelCase		)		)

        lowerCAmelCase_      :				Any      =       outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

        lowerCAmelCase_      :				Optional[Any]      =       self.model_tester.num_stages
        self.assertEqual(len(lowerCamelCase		)   ,						expected_num_stages + 1		)

        # ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
        self.assertListEqual(
            list(hidden_states[0].shape[-2:]		)   ,						[self.model_tester.image_size // 4, self.model_tester.image_size // 4]   ,						)

      lowerCAmelCase_,							lowerCAmelCase_      :				str      =       self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowerCAmelCase_      :				Dict      =       True
        check_hidden_states_output(lowerCamelCase   ,						lowerCamelCase   ,						lowerCamelCase		)

        # check that output_hidden_states also work using config
        del inputs_dict["output_hidden_states"]
        lowerCAmelCase_      :				Tuple      =       True

        check_hidden_states_output(lowerCamelCase   ,						lowerCamelCase   ,						lowerCamelCase		)

    def __lowercase       (       self   :  List[str]		)       ->  Dict:
      lowerCAmelCase_      :				str      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*lowerCamelCase		)





    @slow
    def __lowercase       (       self   :  Optional[int]		)       ->  List[Any]:
      for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowerCAmelCase_      :				Optional[int]      =       ConvNextVaModel.from_pretrained(lowerCamelCase		)
        self.assertIsNotNone(lowerCamelCase		)







def     UpperCamelCase_      (   ):
  '''simple docstring'''





  lowerCAmelCase_      :				List[Any]      =       Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
  return image






@require_torch
@require_vision
class        __snake_case	(       unittest.TestCase):







    """simple docstring"""



    @cached_property
    def __lowercase       (       self   :  List[str]		)       ->  str:
      return AutoImageProcessor.from_pretrained("""facebook/convnextv2-tiny-1k-224"""		) if is_vision_available() else None





    @slow
    def __lowercase       (       self   :  List[Any]		)       ->  Optional[Any]:
      lowerCAmelCase_      :				Union[str, Any]      =       ConvNextVaForImageClassification.from_pretrained("""facebook/convnextv2-tiny-1k-224"""		).to(lowerCamelCase		)

      lowerCAmelCase_      :				Any      =       self.default_image_processor
      lowerCAmelCase_      :				List[str]      =       prepare_img()
      lowerCAmelCase_      :				int      =       preprocessor(images=lowerCamelCase   ,						return_tensors="""pt"""		).to(lowerCamelCase		)

      # forward pass
      with torch.no_grad():
        lowerCAmelCase_      :				Tuple      =       model(**lowerCamelCase		)

      # verify the logits
      lowerCAmelCase_      :				Dict      =       torch.Size((1, 10_00)		)
      self.assertEqual(outputs.logits.shape   ,						lowerCamelCase		)

      lowerCAmelCase_      :				List[str]      =       torch.tensor([0.9_996, 0.1_966, -0.4_386]		).to(lowerCamelCase		)
      self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,						lowerCamelCase   ,						atol=1E-4		)		)







'''simple docstring'''






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 get_down_block, get_mid_block, get_out_block, get_up_block






@dataclass
class        __snake_case	(       _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase       			= 42







class        __snake_case	(       _SCREAMING_SNAKE_CASE     ,_SCREAMING_SNAKE_CASE):







    """simple docstring"""



    @register_to_config
    def __init__(       self   :  Optional[int]   ,						lowerCamelCase   :  int = 6_55_36   ,						lowerCamelCase   :  Optional[int] = None   ,						lowerCamelCase   :  int = 2   ,						lowerCamelCase   :  int = 2   ,						lowerCamelCase   :  int = 0   ,						lowerCamelCase   :  str = "fourier"   ,						lowerCamelCase   :  bool = True   ,						lowerCamelCase   :  bool = False   ,						lowerCamelCase   :  float = 0.0   ,						lowerCamelCase   :  Tuple[str] = ("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D")   ,						lowerCamelCase   :  Tuple[str] = ("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip")   ,						lowerCamelCase   :  Tuple[str] = "UNetMidBlock1D"   ,						lowerCamelCase   :  str = None   ,						lowerCamelCase   :  Tuple[int] = (32, 32, 64)   ,						lowerCamelCase   :  str = None   ,						lowerCamelCase   :  int = 8   ,						lowerCamelCase   :  int = 1   ,						lowerCamelCase   :  bool = False   ,						)       ->  List[Any]:
      super().__init__()
      lowerCAmelCase_      :				Optional[Any]      =       sample_size

      # time
      if time_embedding_type == "fourier":
        lowerCAmelCase_      :				int      =       GaussianFourierProjection(
            embedding_size=8   ,						set_W_to_weight=lowerCamelCase   ,						log=lowerCamelCase   ,						flip_sin_to_cos=lowerCamelCase		)
        lowerCAmelCase_      :				List[Any]      =       2 * block_out_channels[0]
      elif time_embedding_type == "positional":
        lowerCAmelCase_      :				Optional[int]      =       Timesteps(
            block_out_channels[0]   ,						flip_sin_to_cos=lowerCamelCase   ,						downscale_freq_shift=lowerCamelCase		)
        lowerCAmelCase_      :				Union[str, Any]      =       block_out_channels[0]

      if use_timestep_embedding:
        lowerCAmelCase_      :				List[str]      =       block_out_channels[0] * 4
        lowerCAmelCase_      :				List[str]      =       TimestepEmbedding(
            in_channels=lowerCamelCase   ,						time_embed_dim=lowerCamelCase   ,						act_fn=lowerCamelCase   ,						out_dim=block_out_channels[0]   ,						)

      lowerCAmelCase_      :				str      =       nn.ModuleList([]		)
      lowerCAmelCase_      :				Tuple      =       None
      lowerCAmelCase_      :				str      =       nn.ModuleList([]		)
      lowerCAmelCase_      :				List[str]      =       None

      # down
      lowerCAmelCase_      :				List[str]      =       in_channels
      for i, down_block_type in enumerate(lowerCamelCase		):
        lowerCAmelCase_      :				Optional[Any]      =       output_channel
        lowerCAmelCase_      :				str      =       block_out_channels[i]

        if i == 0:
          input_channel += extra_in_channels

        lowerCAmelCase_      :				int      =       i == len(lowerCamelCase		) - 1

        lowerCAmelCase_      :				List[str]      =       get_down_block(
            lowerCamelCase   ,						num_layers=lowerCamelCase   ,						in_channels=lowerCamelCase   ,						out_channels=lowerCamelCase   ,						temb_channels=block_out_channels[0]   ,						add_downsample=not is_final_block or downsample_each_block   ,						)
        self.down_blocks.append(lowerCamelCase		)

      # mid
      lowerCAmelCase_      :				Dict      =       get_mid_block(
          lowerCamelCase   ,						in_channels=block_out_channels[-1]   ,						mid_channels=block_out_channels[-1]   ,						out_channels=block_out_channels[-1]   ,						embed_dim=block_out_channels[0]   ,						num_layers=lowerCamelCase   ,						add_downsample=lowerCamelCase   ,						)

      # up
      lowerCAmelCase_      :				List[str]      =       list(reversed(lowerCamelCase		)		)
      lowerCAmelCase_      :				str      =       reversed_block_out_channels[0]
      if out_block_type is None:
        lowerCAmelCase_      :				Optional[int]      =       out_channels
      else:
        lowerCAmelCase_      :				Optional[Any]      =       block_out_channels[0]

      for i, up_block_type in enumerate(lowerCamelCase		):
        lowerCAmelCase_      :				Any      =       output_channel
        lowerCAmelCase_      :				str      =       (
            reversed_block_out_channels[i + 1] if i < len(lowerCamelCase		) - 1 else final_upsample_channels
        )

        lowerCAmelCase_      :				int      =       i == len(lowerCamelCase		) - 1

        lowerCAmelCase_      :				Any      =       get_up_block(
            lowerCamelCase   ,						num_layers=lowerCamelCase   ,						in_channels=lowerCamelCase   ,						out_channels=lowerCamelCase   ,						temb_channels=block_out_channels[0]   ,						add_upsample=not is_final_block   ,						)
        self.up_blocks.append(lowerCamelCase		)
        lowerCAmelCase_      :				Optional[int]      =       output_channel

      # out
      lowerCAmelCase_      :				str      =       norm_num_groups if norm_num_groups is not None else min(block_out_channels[0] // 4   ,						32		)
      lowerCAmelCase_      :				Union[str, Any]      =       get_out_block(
          out_block_type=lowerCamelCase   ,						num_groups_out=lowerCamelCase   ,						embed_dim=block_out_channels[0]   ,						out_channels=lowerCamelCase   ,						act_fn=lowerCamelCase   ,						fc_dim=block_out_channels[-1] // 4   ,						)





    def __lowercase       (       self   :  List[Any]   ,						lowerCamelCase   :  torch.FloatTensor   ,						lowerCamelCase   :  Union[torch.Tensor, float, int]   ,						lowerCamelCase   :  bool = True   ,						)       ->  Union[UNetaDOutput, Tuple]:
      lowerCAmelCase_      :				Optional[Any]      =       timestep
      if not torch.is_tensor(lowerCamelCase		):
        lowerCAmelCase_      :				Any      =       torch.tensor([timesteps]   ,						dtype=torch.long   ,						device=sample.device		)
      elif torch.is_tensor(lowerCamelCase		) and len(timesteps.shape		) == 0:
        lowerCAmelCase_      :				Dict      =       timesteps[None].to(sample.device		)

      lowerCAmelCase_      :				int      =       self.time_proj(lowerCamelCase		)
      if self.config.use_timestep_embedding:
        lowerCAmelCase_      :				int      =       self.time_mlp(lowerCamelCase		)
      else:
        lowerCAmelCase_      :				Tuple      =       timestep_embed[..., None]
        lowerCAmelCase_      :				Dict      =       timestep_embed.repeat([1, 1, sample.shape[2]]		).to(sample.dtype		)
        lowerCAmelCase_      :				Union[str, Any]      =       timestep_embed.broadcast_to((sample.shape[:1] + timestep_embed.shape[1:])		)

      # 2. down
      lowerCAmelCase_      :				Optional[Any]      =       ()
      for downsample_block in self.down_blocks:
        lowerCAmelCase_,							lowerCAmelCase_      :				Any      =       downsample_block(hidden_states=lowerCamelCase   ,						temb=lowerCamelCase		)
        down_block_res_samples += res_samples

      # 3. mid
      if self.mid_block:
        lowerCAmelCase_      :				int      =       self.mid_block(lowerCamelCase   ,						lowerCamelCase		)

      # 4. up
      for i, upsample_block in enumerate(self.up_blocks		):
        lowerCAmelCase_      :				str      =       down_block_res_samples[-1:]
        lowerCAmelCase_      :				Union[str, Any]      =       down_block_res_samples[:-1]
        lowerCAmelCase_      :				List[str]      =       upsample_block(lowerCamelCase   ,						res_hidden_states_tuple=lowerCamelCase   ,						temb=lowerCamelCase		)

      # 5. post-process
      if self.out_block:
        lowerCAmelCase_      :				Union[str, Any]      =       self.out_block(lowerCamelCase   ,						lowerCamelCase		)

      if not return_dict:
        return (sample,)

      return UNetaDOutput(sample=lowerCamelCase		)



