code: def collate_fn(examples, with_prior_preservation=False):
      pixel_values = [
          example["instance_images"] for example in examples
      ]
      prompts = [example["instance_prompt"] for example in examples]
  
      # Concat class and instance examples for prior preservation.
      # We do this to avoid doing two forward passes.
      if with_prior_preservation:
          pixel_values += [
              example["class_images"] for example in examples
          ]
          prompts += [example["class_prompt"] for example in examples]
  
      pixel_values = torch.stack(pixel_values)
      pixel_values = pixel_values.to(
          memory_format=torch.contiguous_format
      ).float()
  
      batch = {"pixel_values": pixel_values, "prompts": prompts}
      return batch
  
imports: import argparse
  import gc
  import itertools
  import logging
  import math
  import os
  import shutil
  import warnings
  from pathlib import Path
  import numpy
  import torch
  import torch.nn.functional
  import torch.utils.checkpoint
  import transformers
  from accelerate import Accelerator
  from accelerate.logging import get_logger
  from accelerate.utils import DistributedDataParallelKwargs, ProjectConfiguration, set_seed
  from huggingface_hub import create_repo, upload_folder
  from huggingface_hub.utils import insecure_hashlib
  from packaging import version
  from peft import LoraConfig, set_peft_model_state_dict
  from peft.utils import get_peft_model_state_dict
  from PIL import Image
  from PIL.ImageOps import exif_transpose
  from torch.utils.data import Dataset
  from torchvision import transforms
  from tqdm.auto import tqdm
  from transformers import AutoTokenizer, PretrainedConfig
  import diffusers
  from diffusers import AutoencoderKL, DDPMScheduler, DPMSolverMultistepScheduler, StableDiffusionXLPipeline, UNet2DConditionModel
  from diffusers.loaders import LoraLoaderMixin
  from diffusers.optimization import get_scheduler
  from diffusers.training_utils import _set_state_dict_into_text_encoder, cast_training_params, compute_snr
  from diffusers.utils import check_min_version, convert_state_dict_to_diffusers, convert_unet_state_dict_to_peft, is_wandb_available
  from diffusers.utils.import_utils import is_xformers_available
  from diffusers.utils.torch_utils import is_compiled_module
label_desc: Use image node_id 4 for calling a global function with example usage: collate_fn(examples, with_prior_preservation) and returns: batch