LiquidAI LFM-2-350M Generator
Turn one lazy sentence into a full Z-Image prompt with a 350M LLM
- model_context
- tokenizer
- STRING
This is the node the whole pack exists for. You type "a cyberpunk street market at night" and it hands you a proper Z-Image prompt: subject, lighting, camera spec, atmosphere, the works. No API, no key, no OpenAI bill - a 350M language model fine-tuned on 60,000 description-to-prompt pairs does the rewriting locally, and it's fast enough that you can batch a handful of descriptions and pick the best.
Why bother? Because modern models like Z-Image don't read your prompt as a token bag - the text encoder is a general-purpose LLM, so your prompt is an instruction, and rich, structured natural language is what it answers well to. Getting all that detail right by hand is tedious, which is exactly the kind of task a small fine-tuned LLM is good at. A bigger model like Qwen2 could do the same job but eats more VRAM; this one runs in a couple of gigabytes and can even hobble along on CPU if you're patient.
How it works
It takes the model_context and tokenizer outputs from the pack's LFM2Loader, builds a chat with your system_prompt and prompt, runs it through the model's chat template (apply_chat_template with add_generation_prompt=True), and calls model.generate() with sampling enabled. Then it decodes only the newly generated tokens and hands you one string. The sampling knobs are all real transformers parameters - temperature, top_p, top_k, min_p, repetition_penalty - not decorations.
Inputs that matter
The two from the Loader: model_context and tokenizer. Then three you'll actually edit:
system_prompt- the author ships a sensible default that tells the model to transform an image description into a detailed Z-Image Turbo prompt: rich detail, lighting info, camera specs, no negatives, and to stop right after the prompt with no preface or trailing fluff. This is the personality of the whole node. Targeting a different model, or want a different style? Rewrite this and the fine-tune follows the instruction surprisingly well.prompt- your short input. This is what gets expanded.max_new_tokens- default 512, cap 4096. Keep it at 512; the model only needs to write one prompt, and past a few hundred tokens you're just buying filler.
The sampling defaults are the README's recommended recipe (temperature 0.3, min_p 0.15, repetition_penalty 1.05), and they ship as the defaults for good reason - this is a small model and low temperature plus a repetition penalty are what keep it on the rails. seed only applies when it's greater than 0; at the default of 0 you get no reproducibility, so set a seed if you want to re-roll a specific output.
Output
A single STRING - the expanded prompt. Wire it into your image model's prompt/positive text input. It's written for Z-Image Turbo, but since it's just text, it feeds any long-token model (Flux 2, Anima, whatever you're running) - adjust the system prompt if you want the output styled for a different encoder.
Installation
Same pack as the Loader - one clone, one pip install:
cd ComfyUI/custom_nodes
git clone https://github.com/marduk191/ComfyUI_LFM2-350M.git
cd ComfyUI_LFM2-350M
pip install -r requirements.txt
Restart ComfyUI (or install via Manager, searching ComfyUI_LFM2-350M), drop in the Loader and this node, and the ~350M model downloads from HuggingFace on first run.
Troubleshooting
- Output rambles or repeats - raise
repetition_penaltytoward 1.1–1.2, or droptemperaturea touch. Small models repeat when you give them too much rope. - Output is dull and samey - nudge
temperatureup toward 0.6–0.8 for variety. The 0.3 default is the conservative starting point, not a law. - Empty or truncated output - check
max_new_tokens; if it's set low (like 50), the model runs out of room mid-prompt. Default 512 is fine. - Console spam with
LFM2 Debug -lines - normal; the pack is chatty by design, and it's genuinely handy for seeing exactly what the model generated versus the input tokens.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| model_context | LFM2_MODEL | — | |
| tokenizer | LFM2_TOKENIZER | — | |
| system_prompt | STRING | Transform the following image description into a detailed prompt for Z-Image Turbo. Use rich details, lighting info, and camera specs. Do not include negative prompts or ending explanation starting with 'this detailed prompt should' Only return the final prompt without any preface. Finish right after the prompt, do not add any concluding words after the prompt. | — |
| prompt | STRING | Hello, how are you? | — |
| max_new_tokens | INT | 5121–4096 | — |
| temperature | FLOAT | 0.300–2 | — |
| top_p | FLOAT | 0.900–1 | — |
| top_k | INT | 500–200 | — |
| min_p | FLOAT | 0.150–1 | — |
| repetition_penalty | FLOAT | 1.051–2 | — |
| seed | INT | 00–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |