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
  from typing import Any, Dict, List, Optional, Union
  import torch
  import torch.nn
  from transformers import AutoModel, AutoTokenizer, CLIPImageProcessor
  from diffusers import DiffusionPipeline
  from diffusers.image_processor import VaeImageProcessor
  from diffusers.loaders import LoraLoaderMixin
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.models.lora import adjust_lora_scale_text_encoder
  from diffusers.pipelines.stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
  from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import USE_PEFT_BACKEND, logging, scale_lora_layers, unscale_lora_layers
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 1 for calling a global function with example usage: rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale) and returns: noise_cfg