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
  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.configuration_utils import FrozenDict
  from diffusers.image_processor import PipelineImageInput, VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AsymmetricAutoencoderKL, AutoencoderKL, UNet2DConditionModel
  from diffusers.models.lora import adjust_lora_scale_text_encoder
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
  from diffusers.utils.torch_utils import randn_tensor
  from diffusers.pipelines.pipeline_utils import DiffusionPipeline
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
  from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
  import re
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