Fix: Ideogram 4.
The Actual Error
When invoking the Ideogram node with spatial prompts like "A sign reading 'OPEN' hanging above a door", the server log spat this out:
[ERROR] Text encoding failed: expected hidden_states dim [1, 256, 1024], got [1, 203, 1024]
[WARN] Bounding box projection skipped — token alignment brokenThe node loads the model fine, but the text encoder's token padding length doesn't match what the unet expects. This kills spatial bounding boxes and any prompt with more than ~4 words.
Diagnosis
I compared the custom node's model_config.json against Ideogram's reference implementation. Two issues:
1. The node forces max_position_embeddings: 256 while the local checkpoint was trained with 203
2. The tokenizer pads to the config value instead of detecting the actual sequence length
Swapping to dynamic padding based on the real token count fixed the dimension mismatch. I also had to patch the bounding box sampler to re-align tokens after truncation.
Steps That Worked
1. Clone the node into ComfyUI/custom_nodes/
2. Edit nodes/ideogram_node.py — replace the static padding with:
# Before (broken)
encoded = tokenizer(prompt, padding="max_length", max_length=256, truncation=True)
# After (fixed)
encoded = tokenizer(prompt, padding="longest", truncation=True, return_tensors="pt")
max_len = encoded.input_ids.shape[1]
# Resize position embeddings if needed
model.resize_position_embeddings(max_len)3. In model_config.json, set "max_position_embeddings": 203 to match the checkpoint
4. Restart ComfyUI — the node now preserves character counts and bounding box alignment
What Still Isn't Perfect
The local run is noticeably slower than the cloud API (batch size 1 on a 4090 takes ~18s vs ~6s). Also, I haven't cracked exact spatial prompt syntax yet — "text above image" sometimes renders below. If anyone has the correct token-bounding format for local Ideogram 4.0, I'm all ears.
For now, this patch delivers clean text rendering and functional bounding boxes on consumer hardware. I'll push the fork once I clean up the sampler fix.
