GPT-2 Text Generator
The old-school prompt expander that still fits in a graph
- clip
- CONDITIONING
- STRING
You've got writer's block, or you want the AI to describe its own scene before it draws it. That's the whole job of the GPT-2 Text Generator (GPT2Node from ComfyUI-HF): it takes a short seed prompt you type, lets a small language model riff on it, and hands the finished prompt to the sampler - all inside the graph, no copy-pasting into a third-party site. It's a 2022 idea, the same MagicPrompt trick everyone used back in the A1111 era, and honestly it's been mostly superseded: modern checkpoints like Flux understand natural language so well that a prompt expander is usually pointless. But if you still run SD1.5 workflows, or you just want one node that turns "cat" into a full paragraph for you, this is a tidy way to do it. The name is accurate, by the way - it genuinely runs GPT-2 locally, no API, no key, no Hugging Face account.
How it works
The mechanism is simpler than it looks. You pass it a clip (any CLIP model), a text seed, a model_repo, and a temperature. On first run the node downloads the language model from Hugging Face Hub by repo id - the default Gustavosta/MagicPrompt-Stable-Diffusion is about 500MB - then generates up to ~100 tokens of continuation from your seed. The generated string gets tokenized through your CLIP model (clip.encode_from_tokens) and comes out the CONDITIONING output, which you wire straight into a KSampler's positive input. You also get the raw STRING output, so you can see what it wrote, save it, or feed it somewhere else.
A couple of quirks worth knowing, straight from the source:
- The tokenizer is always GPT-2's, no matter which repo you pick. The code loads
AutoTokenizer.from_pretrained('gpt2')once and never swaps it. The README lists non-GPT-2 models (like the Bloom one), and pointing at those gives you a tokenizer/model mismatch - garbage in, garbage out. Stick to the GPT-2-family repos. - The temperature slider is mostly decorative. It's passed to
generate, but the node calls withdo_sample=False, and greedy decoding ignores temperature entirely. Don't chase the slider expecting variety; you're not getting any. - Model weights are cached in memory for the session per repo. Switch repos and you'll re-download; come back to a previously used one and it's instant. First run needs a working internet connection.
The inputs that matter
Out of four inputs, you'll actually touch two:
text- your seed prompt. Keep it short; the model writes the rest.model_repo- the Hugging Face repo id.microsoft/Promptistis the one interesting switch: it's a rephraser rather than an expander, and the code appendsRephrase:to your text and strips it back off the output, giving you a polished version of what you typed instead of a continuation.
clip and temperature you can leave at defaults.
Installing it
Search "ComfyUI-HF" in ComfyUI Manager and install, or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/mbrostami/ComfyUI-HF
Then restart ComfyUI. The node's requirements.txt pins transformers==4.26.1 - an old release - and that's the real installation hazard. Custom nodes all share one Python environment, and a hard-pinned, years-old transformers can either silently bump or actively clash with other nodes that expect a newer one. If you're the kind of person with 40 nodes installed, expect this pack to be the source of an occasional conflict.
Where people get burned
Two failure modes dominate. First, the Hugging Face download: no internet or no disk space on first run and you get an opaque from_pretrained error - pre-warm by running it once on a tiny prompt before you build a whole workflow around it. Second, the wrong repo: someone pastes a nice-sounding model id from the README that isn't a GPT-2 variant, and the outputs stop making sense. When that happens, check your model_repo before you blame your sampler settings.
If you're on a modern model, you probably don't need this node at all - write the sentence yourself and let T5 or the model's own encoder handle it. If you're on SD1.5 and the blank prompt box is staring back at you, it's a fun little crutch, and the STRING output makes it easy to see exactly what it handed downstream.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| clip | CLIP | — | |
| text | STRING | — | |
| model_repo | STRING | Gustavosta/MagicPrompt-Stable-Diffusion | — |
| temperature | FLOAT | 1.00.1–2 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| CONDITIONING | CONDITIONING | — |
| STRING | STRING | — |