code: def rescale_noise_cfg(
      noise_cfg, noise_pred_text, guidance_rescale=0.0
  ):
      """
      Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and
      Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4
      """
      std_text = noise_pred_text.std(
          dim=list(range(1, noise_pred_text.ndim)), keepdim=True
      )
      std_cfg = noise_cfg.std(
          dim=list(range(1, noise_cfg.ndim)), keepdim=True
      )
      # rescale the results from guidance (fixes overexposure)
      noise_pred_rescaled = noise_cfg * (std_text / std_cfg)
      # mix with the original results from guidance by factor guidance_rescale to avoid "plain looking" images
      noise_cfg = (
          guidance_rescale * noise_pred_rescaled
          + (1 - guidance_rescale) * noise_cfg
      )
      return noise_cfg
  
imports: import inspect
  import os
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  from PIL import Image
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer, CLIPVisionModelWithProjection
  from diffusers import DiffusionPipeline, StableDiffusionXLPipeline
  from diffusers.image_processor import PipelineImageInput, VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AutoencoderKL, ImageProjection, UNet2DConditionModel
  from diffusers.models.attention_processor import AttnProcessor2_0, FusedAttnProcessor2_0, LoRAAttnProcessor2_0, LoRAXFormersAttnProcessor, XFormersAttnProcessor
  from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import deprecate, is_accelerate_available, is_accelerate_version, is_invisible_watermark_available, logging, replace_example_docstring
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 5 for calling a global function with example usage: rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale) and returns: noise_cfg