# custom_nodes/bigasp_embed_node.py import torch from diffusers import StableDiffusionPipeline from transformers import CLIPTokenizer, CLIPTextModel class BigASP_Embeddings: @classmethod def INPUT_TYPES(cls): return { "required": { "model_path": ("STRING", {"default": "silveroxides/big-asp-v2"}), "prompt": ("STRING", {"multiline": True}), "neg_prompt": ("STRING", {"multiline": True}), } } RETURN_TYPES = ("CONDITIONING", "CONDITIONING") FUNCTION = "run" CATEGORY = "embedding/BigASP" _PIPELINE_CACHE = {} def run(self, model_path, prompt, neg_prompt): # Load or reuse pipeline pipe = self._PIPELINE_CACHE.get(model_path) if pipe is None: print(f"Loading Big-ASP model from: {model_path}") pipe = StableDiffusionPipeline.from_pretrained( model_path, torch_dtype=torch.float16, use_safetensors=True ).to("cuda") pipe.safety_checker = None # Optional self._PIPELINE_CACHE[model_path] = pipe device = pipe.device # usually 'cuda' # Tokenize and move inputs to GPU text_input = pipe.tokenizer( prompt, padding="max_length", max_length=pipe.tokenizer.model_max_length, return_tensors="pt" ) neg_text_input = pipe.tokenizer( neg_prompt, padding="max_length", max_length=pipe.tokenizer.model_max_length, return_tensors="pt" ) text_input = {k: v.to(device) for k, v in text_input.items()} neg_text_input = {k: v.to(device) for k, v in neg_text_input.items()} with torch.no_grad(): prompt_embeds = pipe.text_encoder(**text_input).last_hidden_state neg_prompt_embeds = pipe.text_encoder(**neg_text_input).last_hidden_state # Move embeddings to CPU if needed by ComfyUI positive = [[prompt_embeds.to("cpu"), {}]] negative = [[neg_prompt_embeds.to("cpu"), {}]] return (positive, negative) NODE_CLASS_MAPPINGS = { "BigASP_Embeddings": BigASP_Embeddings } NODE_DISPLAY_NAME_MAPPINGS = { "BigASP_Embeddings": "BigASP Prompt Embeddings" }