code: def group_tokens_and_weights(
      token_ids: list, weights: list, pad_last_block=False
  ):
      """
      Produce tokens and weights in groups and pad the missing tokens
  
      Args:
          token_ids (list)
              The token ids from tokenizer
          weights (list)
              The weights list from function get_prompts_tokens_with_weights
          pad_last_block (bool)
              Control if fill the last token list to 75 tokens with eos
      Returns:
          new_token_ids (2d list)
          new_weights (2d list)
  
      Example:
          token_groups,weight_groups = group_tokens_and_weights(
              token_ids = token_id_list
              , weights = token_weight_list
          )
      """
      bos, eos = 49406, 49407
  
      # this will be a 2d list
      new_token_ids = []
      new_weights = []
      while len(token_ids) >= 75:
          # get the first 75 tokens
          head_75_tokens = [token_ids.pop(0) for _ in range(75)]
          head_75_weights = [weights.pop(0) for _ in range(75)]
  
          # extract token ids and weights
          temp_77_token_ids = [bos] + head_75_tokens + [eos]
          temp_77_weights = [1.0] + head_75_weights + [1.0]
  
          # add 77 token and weights chunk to the holder list
          new_token_ids.append(temp_77_token_ids)
          new_weights.append(temp_77_weights)
  
      # padding the left
      if len(token_ids) > 0:
          padding_len = 75 - len(token_ids) if pad_last_block else 0
  
          temp_77_token_ids = (
              [bos] + token_ids + [eos] * padding_len + [eos]
          )
          new_token_ids.append(temp_77_token_ids)
  
          temp_77_weights = (
              [1.0] + weights + [1.0] * padding_len + [1.0]
          )
          new_weights.append(temp_77_weights)
  
      return new_token_ids, new_weights
  
imports: import inspect
  import os
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  from PIL import Image
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer, CLIPVisionModelWithProjection
  from diffusers import DiffusionPipeline, StableDiffusionXLPipeline
  from diffusers.image_processor import PipelineImageInput, VaeImageProcessor
  from diffusers.loaders import FromSingleFileMixin, IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from diffusers.models import AutoencoderKL, ImageProjection, UNet2DConditionModel
  from diffusers.models.attention_processor import AttnProcessor2_0, FusedAttnProcessor2_0, LoRAAttnProcessor2_0, LoRAXFormersAttnProcessor, XFormersAttnProcessor
  from diffusers.pipelines.stable_diffusion_xl.pipeline_output import StableDiffusionXLPipelineOutput
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import deprecate, 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 3 for calling a global function with example usage: group_tokens_and_weights(token_ids, weights, pad_last_block) and returns: new_token_ids,  new_weights