code: def encode_prompt(
      prompt_batch,
      text_encoders,
      tokenizers,
      proportion_empty_prompts,
      is_train=True,
  ):
      prompt_embeds_list = []
  
      captions = []
      for caption in prompt_batch:
          if random.random() < proportion_empty_prompts:
              captions.append("")
          elif isinstance(caption, str):
              captions.append(caption)
          elif isinstance(caption, (list, np.ndarray)):
              # take a random caption if there are multiple
              captions.append(
                  random.choice(caption) if is_train else caption[0]
              )
  
      with torch.no_grad():
          for tokenizer, text_encoder in zip(tokenizers, text_encoders):
              text_inputs = tokenizer(
                  captions,
                  padding="max_length",
                  max_length=tokenizer.model_max_length,
                  truncation=True,
                  return_tensors="pt",
              )
              text_input_ids = text_inputs.input_ids
              prompt_embeds = text_encoder(
                  text_input_ids.to(text_encoder.device),
                  output_hidden_states=True,
              )
  
              # We are only ALWAYS interested in the pooled output of the final text encoder
              pooled_prompt_embeds = prompt_embeds[0]
              prompt_embeds = prompt_embeds.hidden_states[-2]
              bs_embed, seq_len, _ = prompt_embeds.shape
              prompt_embeds = prompt_embeds.view(bs_embed, seq_len, -1)
              prompt_embeds_list.append(prompt_embeds)
  
      prompt_embeds = torch.concat(prompt_embeds_list, dim=-1)
      pooled_prompt_embeds = pooled_prompt_embeds.view(bs_embed, -1)
      return prompt_embeds, pooled_prompt_embeds
  
imports: import argparse
  import functools
  import gc
  import itertools
  import json
  import logging
  import math
  import os
  import random
  import shutil
  from pathlib import Path
  from typing import List, Optional, Union
  import accelerate
  import cv2
  import numpy
  import torch
  import torch.utils.checkpoint
  import transformers
  import webdataset
  from accelerate import Accelerator
  from accelerate.logging import get_logger
  from accelerate.utils import ProjectConfiguration, set_seed
  from braceexpand import braceexpand
  from huggingface_hub import create_repo, upload_folder
  from packaging import version
  from PIL import Image
  from torch.utils.data import default_collate
  from torchvision import transforms
  from tqdm.auto import tqdm
  from transformers import AutoTokenizer, DPTFeatureExtractor, DPTForDepthEstimation, PretrainedConfig
  from webdataset.tariterators import base_plus_ext, tar_file_expander, url_opener, valid_sample
  import diffusers
  from diffusers import AutoencoderKL, ControlNetModel, EulerDiscreteScheduler, StableDiffusionXLControlNetPipeline, UNet2DConditionModel
  from diffusers.optimization import get_scheduler
  from diffusers.utils import check_min_version, is_wandb_available
  from diffusers.utils.import_utils import is_xformers_available
label_desc: Use image node_id 12 for calling a global function with example usage: encode_prompt(prompt_batch, text_encoders, tokenizers, proportion_empty_prompts, is_train) and returns: prompt_embeds,  pooled_prompt_embeds