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 collections.abc import Callable
  from typing import Any, List, Optional, Union
  import numpy
  import PIL
  import torch
  import torch.nn.functional
  from transformers import CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer
  from diffusers import DiffusionPipeline
  from diffusers.image_processor import PipelineImageInput, VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, LoraLoaderMixin, StableDiffusionXLLoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AutoencoderKL, ControlNetModel, MultiAdapter, T2IAdapter, UNet2DConditionModel
  from diffusers.models.attention_processor import AttnProcessor2_0, LoRAAttnProcessor2_0, LoRAXFormersAttnProcessor, XFormersAttnProcessor
  from diffusers.models.lora import adjust_lora_scale_text_encoder
  from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
  from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import PIL_INTERPOLATION, USE_PEFT_BACKEND, logging, replace_example_docstring, scale_lora_layers, unscale_lora_layers
  from diffusers.utils.torch_utils import is_compiled_module, randn_tensor
label_desc: Use image node_id 4 for calling a global function with example usage: rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale) and returns: noise_cfg