code: def forward(
      self,
      hidden_states: torch.FloatTensor,
      temb: Optional[torch.FloatTensor] = None,
      encoder_hidden_states: Optional[torch.FloatTensor] = None,
      attention_mask: Optional[torch.FloatTensor] = None,
      cross_attention_kwargs: Optional[Dict[str, Any]] = None,
      encoder_attention_mask: Optional[torch.FloatTensor] = None,
      additional_residuals=None,
  ):
      output_states = ()
  
      lora_scale = (
          cross_attention_kwargs.get("scale", 1.0)
          if cross_attention_kwargs is not None
          else 1.0
      )
  
      blocks = list(zip(self.resnets, self.attentions))
  
      for i, (resnet, attn) in enumerate(blocks):
          if self.training and self.gradient_checkpointing:
  
              def create_custom_forward(module, return_dict=None):
                  def custom_forward(*inputs):
                      if return_dict is not None:
                          return module(
                              *inputs, return_dict=return_dict
                          )
                      else:
                          return module(*inputs)
  
                  return custom_forward
  
              ckpt_kwargs: Dict[str, Any] = (
                  {"use_reentrant": False}
                  if is_torch_version(">=", "1.11.0")
                  else {}
              )
              hidden_states = torch.utils.checkpoint.checkpoint(
                  create_custom_forward(resnet),
                  hidden_states,
                  temb,
                  **ckpt_kwargs,
              )
              hidden_states = attn(
                  hidden_states,
                  encoder_hidden_states=encoder_hidden_states,
                  cross_attention_kwargs=cross_attention_kwargs,
                  attention_mask=attention_mask,
                  encoder_attention_mask=encoder_attention_mask,
                  return_dict=False,
              )[0]
          else:
              hidden_states = resnet(
                  hidden_states, temb, scale=lora_scale
              )
              hidden_states = attn(
                  hidden_states,
                  encoder_hidden_states=encoder_hidden_states,
                  cross_attention_kwargs=cross_attention_kwargs,
                  attention_mask=attention_mask,
                  encoder_attention_mask=encoder_attention_mask,
                  return_dict=False,
              )[0]
  
          # apply additional residuals to the output of the last pair of resnet and attention blocks
          if i == len(blocks) - 1 and additional_residuals is not None:
              hidden_states = hidden_states + additional_residuals
  
          output_states = output_states + (hidden_states,)
  
      if self.downsamplers is not None:
          for downsampler in self.downsamplers:
              hidden_states = downsampler(
                  hidden_states, scale=lora_scale
              )
  
          output_states = output_states + (hidden_states,)
  
      return hidden_states, output_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 CrossAttnDownBlockFlat obj's underlying member method code with example usage: obj.forward(hidden_states, temb, encoder_hidden_states, attention_mask, cross_attention_kwargs, encoder_attention_mask, additional_residuals) and returns: hidden_states,  output_states, custom_forward, module, module