Download sdxl_embedding_node.py from Dervlex/Models: direct link, hf CLI and curl.
- Browser
- Download file 2.69 kB
-
https://huggingface.co/Dervlex/Models/resolve/ca114dba18794b0ad2d426ffe77b0dcf4735cd60/sdxl_embedding_node.py
- Command line
-
hf download hf://Dervlex/Models@ca114dba18794b0ad2d426ffe77b0dcf4735cd60/sdxl_embedding_node.py
-
curl -L -o sdxl_embedding_node.py https://huggingface.co/Dervlex/Models/resolve/ca114dba18794b0ad2d426ffe77b0dcf4735cd60/sdxl_embedding_node.py
2.69 kB
| # custom_nodes/sdxl_embed_node.py | |
| import torch | |
| import numpy as np | |
| from diffusers import StableDiffusionXLPipeline | |
| from sd_embed.embedding_funcs import get_weighted_text_embeddings_sdxl | |
| class WeightedSDXLEmbeddings: | |
| def INPUT_TYPES(cls): | |
| return { | |
| "required": { | |
| "model_path": ("STRING", {"default":"fluently/Fluently-XL-Final"}), | |
| "prompt": ("STRING", {"multiline":True}), | |
| "neg_prompt": ("STRING", {"multiline":True}), | |
| } | |
| } | |
| RETURN_TYPES = ("CONDITIONING","CONDITIONING") | |
| FUNCTION = "run" | |
| CATEGORY = "embedding/SDXL" | |
| # cache so we dont reload every batch | |
| _PIPELINE_CACHE = {} | |
| import torch | |
| import numpy as np | |
| from diffusers import StableDiffusionXLPipeline | |
| from sd_embed.embedding_funcs import get_weighted_text_embeddings_sdxl | |
| class WeightedSDXLEmbeddings: | |
| def INPUT_TYPES(cls): | |
| return { | |
| "required": { | |
| "model_path": ("STRING", {"default":"fluently/Fluently-XL-Final"}), | |
| "prompt": ("STRING", {"multiline":True}), | |
| "neg_prompt": ("STRING", {"multiline":True}), | |
| } | |
| } | |
| RETURN_TYPES = ("CONDITIONING","CONDITIONING") | |
| FUNCTION = "run" | |
| CATEGORY = "embedding/SDXL" | |
| # cache so we don't reload every batch | |
| _PIPELINE_CACHE = {} | |
| def run(self, model_path, prompt, neg_prompt): | |
| # load or re-use the SDXL pipeline | |
| pipe = self._PIPELINE_CACHE.get(model_path) | |
| if pipe is None: | |
| pipe = StableDiffusionXLPipeline.from_pretrained( | |
| model_path, | |
| torch_dtype=torch.float16 | |
| ).to("cuda") | |
| self._PIPELINE_CACHE[model_path] = pipe | |
| # get the 4 embeddings (all torch.Tensor on cuda) | |
| pe, ne, pooled_pe, pooled_ne = get_weighted_text_embeddings_sdxl( | |
| pipe, prompt=prompt, neg_prompt=neg_prompt | |
| ) | |
| # Keep as tensors instead of converting to NumPy | |
| # Just move to CPU if needed for ComfyUI | |
| pe_tensor = pe.detach().cpu() | |
| pooled_pe_tensor = pooled_pe.detach().cpu() | |
| ne_tensor = ne.detach().cpu() | |
| pooled_ne_tensor = pooled_ne.detach().cpu() | |
| # Format correctly for ComfyUI | |
| positive = [[pe_tensor, {"pooled_output": pooled_pe_tensor}]] | |
| negative = [[ne_tensor, {"pooled_output": pooled_ne_tensor}]] | |
| return (positive, negative) | |
| NODE_CLASS_MAPPINGS = { | |
| "WeightedSDXLEmbeddings": WeightedSDXLEmbeddings | |
| } | |
| NODE_DISPLAY_NAME_MAPPINGS = { | |
| "WeightedSDXLEmbeddings": "Weighted SDXL Embeddings" | |
| } | |