{"slug": "fix-ideogram-4", "title": "Fix: Ideogram 4.", "summary": "A ComfyUI custom node for Ideogram 4.0 failed to render spatial prompts due to a text encoder token padding mismatch, causing errors like 'expected hidden_states dim [1, 256, 1024], got [1, 203, 1024]'. The fix involved changing padding to 'longest', resizing position embeddings dynamically, and setting 'max_position_embeddings' to 203 in model_config.json, which restored bounding box alignment and clean text rendering on consumer hardware. The patch is slower than the cloud API (18s vs 6s on a 4090) and spatial prompt syntax remains imperfect.", "body_md": "# Fix: Ideogram 4.\n\n## The Actual Error\n\nWhen invoking the Ideogram node with spatial prompts like `\"A sign reading 'OPEN' hanging above a door\"`\n\n, the server log spat this out:\n\n```\n[ERROR] Text encoding failed: expected hidden_states dim [1, 256, 1024], got [1, 203, 1024]\n[WARN]  Bounding box projection skipped — token alignment broken\n```\n\nThe 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.\n\n## Diagnosis\n\nI compared the custom node's `model_config.json`\n\nagainst Ideogram's reference implementation. Two issues:\n\n1. The node forces `max_position_embeddings: 256`\n\nwhile the local checkpoint was trained with `203`\n\n2. The tokenizer pads to the config value instead of detecting the actual sequence length\n\nSwapping 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.\n\n## Steps That Worked\n\n1. Clone the node into `ComfyUI/custom_nodes/`\n\n2. Edit `nodes/ideogram_node.py`\n\n— replace the static padding with:\n\n```\n# Before (broken)\nencoded = tokenizer(prompt, padding=\"max_length\", max_length=256, truncation=True)\n\n# After (fixed)\nencoded = tokenizer(prompt, padding=\"longest\", truncation=True, return_tensors=\"pt\")\nmax_len = encoded.input_ids.shape[1]\n# Resize position embeddings if needed\nmodel.resize_position_embeddings(max_len)\n```\n\n3. In `model_config.json`\n\n, set `\"max_position_embeddings\": 203`\n\nto match the checkpoint\n\n4. Restart ComfyUI — the node now preserves character counts and bounding box alignment\n\n## What Still Isn't Perfect\n\nThe 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\"`\n\nsometimes renders below. If anyone has the correct token-bounding format for local Ideogram 4.0, I'm all ears.\n\nFor 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.\n\n[Next XXO-Bench →](/en/threads/5001/)\n\n[a library of Claude prompt techniques](http://154.12.95.112/), with plenty of directly applicable cases.", "url": "https://wpnews.pro/news/fix-ideogram-4", "canonical_source": "https://promptcube3.com/en/threads/5004/", "published_at": "2026-08-04 22:27:24+00:00", "updated_at": "2026-08-04 22:49:05.788528+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-tools", "ai-infrastructure"], "entities": ["Ideogram", "ComfyUI", "Claude"], "alternates": {"html": "https://wpnews.pro/news/fix-ideogram-4", "markdown": "https://wpnews.pro/news/fix-ideogram-4.md", "text": "https://wpnews.pro/news/fix-ideogram-4.txt", "jsonld": "https://wpnews.pro/news/fix-ideogram-4.jsonld"}}