code: def get_unweighted_text_embeddings(
      text_encoder,
      text_input: torch.Tensor,
      chunk_length: int,
      no_boseos_middle: Optional[bool] = True,
  ):
      """
      When the length of tokens is a multiple of the capacity of the text encoder,
      it should be split into chunks and sent to the text encoder individually.
      """
      max_embeddings_multiples = (text_input.shape[1] - 2) // (
          chunk_length - 2
      )
      if max_embeddings_multiples > 1:
          text_embeddings = []
          for i in range(max_embeddings_multiples):
              # extract the i-th chunk
              text_input_chunk = text_input[
                  :,
                  i * (chunk_length - 2) : (i + 1) * (chunk_length - 2)
                  + 2,
              ].clone()
  
              # cover the head and the tail by the starting and the ending tokens
              text_input_chunk[:, 0] = text_input[0, 0]
              text_input_chunk[:, -1] = text_input[0, -1]
              text_embedding = text_encoder(text_input_chunk)[0]
  
              if no_boseos_middle:
                  if i == 0:
                      # discard the ending token
                      text_embedding = text_embedding[:, :-1]
                  elif i == max_embeddings_multiples - 1:
                      # discard the starting token
                      text_embedding = text_embedding[:, 1:]
                  else:
                      # discard both starting and ending tokens
                      text_embedding = text_embedding[:, 1:-1]
  
              text_embeddings.append(text_embedding)
          text_embeddings = torch.concat(text_embeddings, axis=1)
      else:
          text_embeddings = text_encoder(text_input)[0]
      return text_embeddings
  
file_path: llmga/llmga/diffusers/my_utils/util.py
imports: import numpy
  import PIL.Image
  import torch
  from diffusers.utils import PIL_INTERPOLATION, deprecate, is_accelerate_available, is_accelerate_version, logging
  from diffusers.utils.torch_utils import randn_tensor
  import inspect
  import re
  from typing import Any, Callable, Dict, List, Optional, Union
label_desc: Use image node_id 5 for calling a global function with example usage: get_unweighted_text_embeddings(text_encoder, text_input, chunk_length, no_boseos_middle) and returns: text_embeddings