code: def forward(
      self,
      hidden_states,
      res_hidden_states_tuple,
      temb=None,
      upsample_size=None,
      scale: float = 1.0,
  ):
      is_freeu_enabled = (
          getattr(self, "s1", None)
          and getattr(self, "s2", None)
          and getattr(self, "b1", None)
          and getattr(self, "b2", None)
      )
  
      for resnet in self.resnets:
          # pop res hidden states
          res_hidden_states = res_hidden_states_tuple[-1]
          res_hidden_states_tuple = res_hidden_states_tuple[:-1]
  
          # FreeU: Only operate on the first two stages
          if is_freeu_enabled:
              hidden_states, res_hidden_states = apply_freeu(
                  self.resolution_idx,
                  hidden_states,
                  res_hidden_states,
                  s1=self.s1,
                  s2=self.s2,
                  b1=self.b1,
                  b2=self.b2,
              )
  
          hidden_states = torch.cat(
              [hidden_states, res_hidden_states], dim=1
          )
  
          if self.training and self.gradient_checkpointing:
  
              def create_custom_forward(module):
                  def custom_forward(*inputs):
                      return module(*inputs)
  
                  return custom_forward
  
              if is_torch_version(">=", "1.11.0"):
                  hidden_states = torch.utils.checkpoint.checkpoint(
                      create_custom_forward(resnet),
                      hidden_states,
                      temb,
                      use_reentrant=False,
                  )
              else:
                  hidden_states = torch.utils.checkpoint.checkpoint(
                      create_custom_forward(resnet), hidden_states, temb
                  )
          else:
              hidden_states = resnet(hidden_states, temb, scale=scale)
  
      if self.upsamplers is not None:
          for upsampler in self.upsamplers:
              hidden_states = upsampler(
                  hidden_states, upsample_size, scale=scale
              )
  
      return hidden_states
  
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from ...configuration_utils import ConfigMixin, register_to_config
  from ...models import ModelMixin
  from ...models.activations import get_activation
  from ...models.attention import Attention
  from ...models.attention_processor import ADDED_KV_ATTENTION_PROCESSORS, CROSS_ATTENTION_PROCESSORS, AttentionProcessor, AttnAddedKVProcessor, AttnAddedKVProcessor2_0, AttnProcessor
  from ...models.dual_transformer_2d import DualTransformer2DModel
  from ...models.embeddings import GaussianFourierProjection, ImageHintTimeEmbedding, ImageProjection, ImageTimeEmbedding, TextImageProjection, TextImageTimeEmbedding, TextTimeEmbedding, TimestepEmbedding, Timesteps
  from ...models.transformer_2d import Transformer2DModel
  from ...models.unet_2d_condition import UNet2DConditionOutput
  from ...utils import USE_PEFT_BACKEND, is_torch_version, logging, scale_lora_layers, unscale_lora_layers
  from ...utils.torch_utils import apply_freeu
label_desc: Use image node_id 2 for calling the UpBlockFlat obj's underlying member method code with example usage: obj.forward(hidden_states, res_hidden_states_tuple, temb, upsample_size, scale) and returns: hidden_states, custom_forward, module