code: def get_prompts_with_weights(
      pipe: DiffusionPipeline, prompt: List[str], max_length: int
  ):
      r"""
      Tokenize a list of prompts and return its tokens with weights of each token.
  
      No padding, starting or ending token is included.
      """
      tokens = []
      weights = []
      truncated = False
      for text in prompt:
          texts_and_weights = parse_prompt_attention(text)
          text_token = []
          text_weight = []
          for word, weight in texts_and_weights:
              # tokenize and discard the starting and the ending token
              token = pipe.tokenizer(word).input_ids[1:-1]
              text_token += token
              # copy the weight by length of token
              text_weight += [weight] * len(token)
              # stop if the text is too long (longer than truncation limit)
              if len(text_token) > max_length:
                  truncated = True
                  break
          # truncate
          if len(text_token) > max_length:
              truncated = True
              text_token = text_token[:max_length]
              text_weight = text_weight[:max_length]
          tokens.append(text_token)
          weights.append(text_weight)
      if truncated:
          logger.warning(
              "Prompt was truncated. Try to shorten the prompt or increase max_embeddings_multiples"
          )
      return tokens, weights
  
imports: import inspect
  import re
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from packaging import version
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
  from diffusers import DiffusionPipeline
  from diffusers.configuration_utils import FrozenDict
  from diffusers.image_processor import VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput, StableDiffusionSafetyChecker
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import PIL_INTERPOLATION, deprecate, is_accelerate_available, is_accelerate_version, logging
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 2 for calling a global function with example usage: get_prompts_with_weights(pipe, prompt, max_length) and returns: tokens,  weights