Eric ERNIE-Image Load Model
The ERNIE-Image loader that fixes a broken text encoder
- pipeline
There's a real argument that Baidu's ERNIE-Image ships with a broken text encoder in the default ComfyUI path, and this node exists to fix it. ERNIE-Image's text encoder is a Ministral 3B model that uses head_dim=128 explicitly, but the standard MistralConfig computes head_dim = hidden_size / num_heads = 3072 / 32 = 96. The result, per the pack author's writeup: all 104 attention matrices (4 per layer × 26 layers) load with the wrong shapes and get silently skipped by strict=False, so the encoder runs on random attention weights and contributes near-zero semantic content. That's not a small quality tweak - that's the difference between prompt-following and mush.
Eric Ernie ERNIE-Image Load Model is the entry point for the whole Ernie_Image_Real_Diffusers pack, and it's the node that applies the compatibility patches nobody else does. It loads the native ErnieImagePipeline from diffusers (not the UNet/KSampler abstraction ComfyUI's core ERNIE support uses) and monkey-patches, in order: TokenizersBackend for transformers' lazy modules, ministral3 registration in CONFIG_MAPPING, MistralAttention.__init__ for the head_dim=128 projection shapes, and the rotary_emb.inv_freq buffer from [48] back to [64]. It also pre-builds the text encoder and passes it into from_pretrained, so that 7.7 GB safetensors file gets read once instead of twice.
Inputs that matter
You mostly set four things:
- model_path - path to a downloaded
baidu/ERNIE-Imageorbaidu/ERNIE-Image-Turbodirectory. Has to point at a folder containingtext_encoder/,transformer/, andvae/, not at a.safetensorsfile. - precision -
bf16(default) orfp16. The README says fp16 can give a sharper VAE decode, at the cost of slightly higher OOM risk.fp32is there if you want it slow and safe. - device -
cudaor a specific GPU index, pluscpufor testing. - keep_in_vram - caches the loaded pipeline so later runs reuse it instead of re-loading. Leave it on; that's what makes the pack's Unload node make sense.
- load_pe - leave this False on a standard ComfyUI install. It loads ERNIE's built-in Prompt Enhancer, a separate 3B LLM that needs transformers ≥ 5.x, and the node will refuse with a clear error if your environment can't do it. The pack's own Prompt Rewriter node replaces it.
Two optional toggles are worth knowing: attention_slicing and sequential_offload (CPU offload - saves VRAM, noticeably slower).
Wiring and output
Output is a single pipeline (ERNIE_PIPELINE) that feeds both ErnieImageGenerate and ErnieImageEncode. Nothing else in the graph touches it.
Installation
Via ComfyUI Manager (search "Eric ERNIE-Image"), or the manual way:
cd ComfyUI/custom_nodes
git clone https://github.com/EricRollei/Ernie_Image_Real_Diffusers
Then grab a checkpoint from HuggingFace (baidu/ERNIE-Image or baidu/ERNIE-Image-Turbo) and point model_path at it. The pack itself has almost no dependencies - it leans on the diffusers, transformers, and safetensors already in your environment. The one real requirement: diffusers with ErnieImagePipeline support. If your install predates it, pip install git+https://github.com/huggingface/diffusers and restart.
Where people get burned
- "Could not load from path" - you pointed at the wrong folder, or the model hasn't finished downloading.
- A
TokenizersBackend/'list' object has no attribute 'keys'error only appears when you setload_pe=Truewithout transformers ≥ 5.x. Flip it off; the error message tells you exactly that. - VRAM, on 24 GB-class cards:
bf16is the safer default. If you OOM on load, trysequential_offloadbefore dropping to CPU.
One honest caveat: this is a small community pack (zero search traffic, a handful of users), and its whole pitch is "the official nodes get the text encoder wrong." The diffusers maintainers may fix that upstream eventually - at which point the loader becomes a convenience wrapper instead of a necessity. For now, if you're generating ERNIE in ComfyUI, this is the version that actually uses the model's full weights.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| model_path | STRING | H:/Training/ERNIE-Image | Path to ERNIE-Image or ERNIE-Image-Turbo directory. |
| precision | COMBO | bf16 | fp16 may give sharper VAE decode than bf16. |
| device | COMBO | cuda | 4 options: cuda, cuda:0, cuda:1, cpu |
| keep_in_vram | BOOLEAN | true | — |
| load_pe | BOOLEAN | false | Requires transformers >= 5.x. Use Prompt Rewriter instead. |
| attention_slicingopt | BOOLEAN | false | — |
| sequential_offloadopt | BOOLEAN | false | CPU offload. Saves VRAM, slower. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| pipeline | ERNIE_PIPELINE | — |