code: def get_prompts_tokens_with_weights(
      clip_tokenizer: CLIPTokenizer, prompt: str
  ):
      """
      Get prompt token ids and weights, this function works for both prompt and negative prompt
  
      Args:
          pipe (CLIPTokenizer)
              A CLIPTokenizer
          prompt (str)
              A prompt string with weights
  
      Returns:
          text_tokens (list)
              A list contains token ids
          text_weight (list)
              A list contains the correspodent weight of token ids
  
      Example:
          import torch
          from transformers import CLIPTokenizer
  
          clip_tokenizer = CLIPTokenizer.from_pretrained(
              "stablediffusionapi/deliberate-v2"
              , subfolder = "tokenizer"
              , dtype = torch.float16
          )
  
          token_id_list, token_weight_list = get_prompts_tokens_with_weights(
              clip_tokenizer = clip_tokenizer
              ,prompt = "a (red:1.5) cat"*70
          )
      """
      texts_and_weights = parse_prompt_attention(prompt)
      text_tokens, text_weights = [], []
      for word, weight in texts_and_weights:
          # tokenize and discard the starting and the ending token
          token = clip_tokenizer(word, truncation=False).input_ids[
              1:-1
          ]  # so that tokenize whatever length prompt
          # the returned token is a 1d list: [320, 1125, 539, 320]
  
          # merge the new tokens to the all tokens holder: text_tokens
          text_tokens = [*text_tokens, *token]
  
          # each token chunk will come with one weight, like ['red cat', 2.0]
          # need to expand weight for each token.
          chunk_weights = [weight] * len(token)
  
          # append the weight back to the weight holder: text_weights
          text_weights = [*text_weights, *chunk_weights]
      return text_tokens, text_weights
  
imports: import inspect
  import os
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  from transformers import CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer
  from diffusers import DiffusionPipeline, StableDiffusionXLPipeline
  from diffusers.image_processor import VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.models.attention_processor import AttnProcessor2_0, LoRAAttnProcessor2_0, LoRAXFormersAttnProcessor, XFormersAttnProcessor
  from diffusers.pipelines.stable_diffusion_xl import StableDiffusionXLPipelineOutput
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import is_accelerate_available, is_accelerate_version, is_invisible_watermark_available, logging, replace_example_docstring
  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_tokens_with_weights(clip_tokenizer, prompt) and returns: text_tokens,  text_weights