Nodes/ComfyUI-HF-Diffusers/HF Diffusers encode prompt
ComfyUI Node

HF Diffusers encode prompt

The expert knob nobody clicks

By Yahweasel·Created 8 months ago·Updated 7 months ago· 2
HF Diffusers encode prompt
  • pipeline
  • TENSOR
  • TENSOR
  • TENSOR
  • TENSOR
prompta photo of an astronaut riding a horse on mars
kwargs

Either you already know what prompt_embeds are and you're here for the wiring, or a workflow dumped this node on your canvas and you're trying to figure out whether you can delete it. Answer: you can usually delete it. But when you want it, it's the only node that does this.

HFDEncodePrompt takes a loaded diffusers pipeline and a prompt and calls the pipeline's own encode_prompt(), handing you the resulting tensors on four TENSOR outputs. The catch - and it's a real one - is that which tensor is on which output depends entirely on the pipeline. The author spells out the mapping:

  • SDXL: (prompt_embeds, negative_prompt_embeds, pooled_prompt_embeds, pooled_negative_prompt_embeds)
  • Flux: (prompt_embeds, pooled_prompt_embeds, _, _)
  • Z-Image: (prompt_embeds, negative_prompt_embeds, _, _)
  • LongCat Image: (prompt_embeds, _, _, _) - but that pipeline can't even accept pre-encoded embeds, so don't bother.

If a pipeline returns fewer than four, the leftover outputs are None. There's no label on the wires beyond their position, so this is a "know your pipeline" node by design. That's the whole reason it has zero search impressions: it's for people who've read enough source to know exactly what they're doing.

Why bother?

The outputs plug into HFDRunPipeline's optional prompt_embeds, negative_prompt_embeds, pooled_prompt_embeds, and negative_pooled_prompt_embeds inputs. Once you wire any of them in, HFDRunPipeline drops the text prompt entirely and uses your tensors - which is the point. You can pre-encode once and reuse, cache embeddings for prompt weighting experiments, or manipulate the tensors with math nodes before they hit the sampler. It's prompt surgery, and it's the kind of thing ComfyUI exists to let you do even though almost nobody does it.

One honest warning: this is also the node most likely to break when you swap pipelines, because encode_prompt's signature differs from pipeline to pipeline. The "exploded" SDXL workflow in the pack uses it; the plain workflows don't, and that's not an accident.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/Yahweasel/ComfyUI-HF-Diffusers

or install ComfyUI-HF-Diffusers via ComfyUI Manager, then restart. requirements.txt pins diffusers~=0.36.0.

The short version

If you don't know why you'd pre-encode a prompt, skip this node - HFDRunPipeline encodes for you at run time, and for 99% of images that's the right call. If you do know, this is the tool, and the README's pipeline-to-output table is your reference. Keep it open.

Categoryhuggingface-diffusers

Inputs (3)

NameTypeDefaultDescription
pipelineHFD_PIPELINE
promptSTRINGa photo of an astronaut riding a horse on mars
kwargsSTRING

Outputs (4)

NameTypeDescription
TENSORTENSOR
TENSORTENSOR
TENSORTENSOR
TENSORTENSOR