code: def setup_prior_preservation(accelerator, config):
      class_images_dir = Path(config.class_image_path)
      if not class_images_dir.exists():
          class_images_dir.mkdir(parents=True)
      cur_class_images = len(list(class_images_dir.iterdir()))
  
      if cur_class_images < config.num_class_images:
          torch_dtype = (
              torch.float16
              if accelerator.device.type == "cuda"
              else torch.float32
          )
          if config.prior_generation_precision == "fp32":
              torch_dtype = torch.float32
          elif config.prior_generation_precision == "fp16":
              torch_dtype = torch.float16
          elif config.prior_generation_precision == "bf16":
              torch_dtype = torch.bfloat16
          if config.xl:
              pipeline = StableDiffusionXLPipeline.from_pretrained(
                  config.model,
                  torch_dtype=torch_dtype,
                  safety_checker=None,
                  revision=config.revision,
              )
          else:
              pipeline = DiffusionPipeline.from_pretrained(
                  config.model,
                  torch_dtype=torch_dtype,
                  safety_checker=None,
                  revision=config.revision,
              )
          pipeline.set_progress_bar_config(disable=True)
  
          num_new_images = config.num_class_images - cur_class_images
          logger.info(
              f"Number of class images to sample: {num_new_images}."
          )
  
          sample_dataset = PromptDataset(
              config.class_prompt, num_new_images
          )
          sample_dataloader = torch.utils.data.DataLoader(
              sample_dataset, batch_size=config.sample_batch_size
          )
  
          sample_dataloader = accelerator.prepare(sample_dataloader)
          pipeline.to(accelerator.device)
  
          for example in tqdm(
              sample_dataloader,
              desc="Generating class images",
              disable=not accelerator.is_local_main_process,
          ):
              images = pipeline(example["prompt"]).images
  
              for i, image in enumerate(images):
                  hash_image = hashlib.sha1(image.tobytes()).hexdigest()
                  image_filename = (
                      class_images_dir
                      / f"{example['index'][i] + cur_class_images}-{hash_image}.jpg"
                  )
                  image.save(image_filename)
  
          del pipeline
          if torch.cuda.is_available():
              torch.cuda.empty_cache()
  
imports: import hashlib
  import itertools
  import os
  from pathlib import Path
  from typing import Dict
  import torch
  from diffusers import AutoencoderKL, DDPMScheduler, DiffusionPipeline, StableDiffusionXLPipeline, UNet2DConditionModel
  from diffusers.utils.import_utils import is_xformers_available
  from packaging import version
  from tqdm import tqdm
  from transformers import AutoTokenizer, PretrainedConfig
  from autotrain import logger
  from autotrain.trainers.dreambooth.datasets import PromptDataset
label_desc: Use image node_id 7 for calling a global function with example usage: setup_prior_preservation(accelerator, config) without return types