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, Callable, Dict, List, Optional, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from packaging import version
  from safetensors import safe_open
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
  from diffusers.configuration_utils import FrozenDict
  from diffusers.image_processor import VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.models.attention_processor import FusedAttnProcessor2_0
  from diffusers.models.lora import LoRALinearLayer, adjust_lora_scale_text_encoder
  from diffusers.pipelines.pipeline_utils import DiffusionPipeline
  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, _get_model_file, deprecate, 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