class_docstr: Inspired by: https://github.com/haofanwang/ControlNet-for-Diffusers/
class_docstr_tok: ["Inspired","by",":","https",":","\/\/github.com\/haofanwang\/ControlNet-for-Diffusers\/"]
docstr: Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
  text_encoder, vae, controlnet, and safety checker have their state dicts saved to CPU and then are moved to a
  `torch.device('meta') and loaded to GPU only when their specific submodule has its `forward` method called.
  Note that offloading happens on a submodule basis. Memory savings are higher than with
  `enable_model_cpu_offload`, but performance is lower.
docstr_tok: ["Offloads","all","models","to","CPU","using","accelerate",",","significantly","reducing","memory","usage",".","When","called",",","unet",",","text_encoder",",","vae",",","controlnet",",","and","safety","checker","have","their","state","dicts","saved","to","CPU","and","then","are","moved","to","a","`","torch.device","(","'meta","'",")","and","loaded","to","GPU","only","when","their","specific","submodule","has","its","`","forward","`","method","called",".","Note","that","offloading","happens","on","a","submodule","basis",".","Memory","savings","are","higher","than","with","`","enable_model_cpu_offload","`",",","but","performance","is","lower","."]
code: def enable_sequential_cpu_offload(self, gpu_id=0):
      r"""
      Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
      text_encoder, vae, controlnet, and safety checker have their state dicts saved to CPU and then are moved to a
      `torch.device('meta') and loaded to GPU only when their specific submodule has its `forward` method called.
      Note that offloading happens on a submodule basis. Memory savings are higher than with
      `enable_model_cpu_offload`, but performance is lower.
      """
      if is_accelerate_available():
          from accelerate import cpu_offload
      else:
          raise ImportError(
              "Please install accelerate via `pip install accelerate`"
          )
  
      device = torch.device(f"cuda:{gpu_id}")
  
      for cpu_offloaded_model in [
          self.unet,
          self.text_encoder,
          self.vae,
          self.controlnet,
      ]:
          cpu_offload(cpu_offloaded_model, device)
  
      if self.safety_checker is not None:
          cpu_offload(
              self.safety_checker,
              execution_device=device,
              offload_buffers=True,
          )
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  import torch.nn.functional
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
  from diffusers import AutoencoderKL, ControlNetModel, DiffusionPipeline, UNet2DConditionModel, logging
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput, StableDiffusionSafetyChecker
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import PIL_INTERPOLATION, is_accelerate_available, is_accelerate_version, replace_example_docstring
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 4 for calling the StableDiffusionControlNetInpaintImg2ImgPipeline obj's underlying member method code with example usage: obj.enable_sequential_cpu_offload(gpu_id) without return types