code: def create_embedding(
      name, num_vectors_per_token, overwrite_old, init_text="*"
  ):
      cond_model = shared.sd_model.cond_stage_model
  
      with devices.autocast():
          cond_model(
              [""]
          )  # will send cond model to GPU if lowvram/medvram is active
  
      # cond_model expects at least some text, so we provide '*' as backup.
      embedded = cond_model.encode_embedding_init_text(
          init_text or "*", num_vectors_per_token
      )
      vec = torch.zeros(
          (num_vectors_per_token, embedded.shape[1]),
          device=devices.device,
      )
  
      # Only copy if we provided an init_text, otherwise keep vectors as zeros
      if init_text:
          for i in range(num_vectors_per_token):
              vec[i] = embedded[
                  i * int(embedded.shape[0]) // num_vectors_per_token
              ]
  
      # Remove illegal characters from name.
      name = "".join(x for x in name if (x.isalnum() or x in "._- "))
      fn = os.path.join(shared.cmd_opts.embeddings_dir, f"{name}.pt")
      if not overwrite_old:
          assert not os.path.exists(fn), f"file {fn} already exists"
  
      embedding = Embedding(vec, name)
      embedding.step = 0
      embedding.save(fn)
  
      return fn
  
imports: import os
  from collections import namedtuple
  from contextlib import closing
  import torch
  import tqdm
  import html
  import datetime
  import csv
  import safetensors.torch
  import numpy
  from PIL import Image, PngImagePlugin
  from torch.utils.tensorboard import SummaryWriter
  from modules import shared, devices, sd_hijack, sd_models, images, sd_samplers, sd_hijack_checkpoint, errors, hashes
  import modules.textual_inversion.dataset
  from modules.textual_inversion.learn_schedule import LearnRateScheduler
  from modules.textual_inversion.image_embedding import embedding_to_b64, embedding_from_b64, insert_image_data_embed, extract_image_data_embed, caption_image_overlay
  from modules.textual_inversion.logging import save_settings_to_file
label_desc: Use image node_id 2 for calling a global function with example usage: create_embedding(name, num_vectors_per_token, overwrite_old, init_text) and returns: fn