Nodes/Eric ERNIE-Image Real Diffusers/Eric ERNIE-Image Load Model
ComfyUI Node

Eric ERNIE-Image Load Model

The ERNIE-Image loader that fixes a broken text encoder

By EricRollei·Created 5 months ago·Updated 5 months ago· 3
Eric ERNIE-Image Load Model
    • pipeline
    model_pathH:/Training/ERNIE-Image
    precisionbf16
    devicecuda
    keep_in_vramtrue
    load_pefalse
    attention_slicingfalse
    sequential_offloadfalse

    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-Image or baidu/ERNIE-Image-Turbo directory. Has to point at a folder containing text_encoder/, transformer/, and vae/, not at a .safetensors file.
    • precision - bf16 (default) or fp16. The README says fp16 can give a sharper VAE decode, at the cost of slightly higher OOM risk. fp32 is there if you want it slow and safe.
    • device - cuda or a specific GPU index, plus cpu for 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 set load_pe=True without transformers ≥ 5.x. Flip it off; the error message tells you exactly that.
    • VRAM, on 24 GB-class cards: bf16 is the safer default. If you OOM on load, try sequential_offload before 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.

    CategoryEric ERNIE Image

    Inputs (7)

    NameTypeDefaultDescription
    model_pathSTRINGH:/Training/ERNIE-ImagePath to ERNIE-Image or ERNIE-Image-Turbo directory.
    precisionCOMBObf16fp16 may give sharper VAE decode than bf16.
    deviceCOMBOcuda4 options: cuda, cuda:0, cuda:1, cpu
    keep_in_vramBOOLEANtrue
    load_peBOOLEANfalseRequires transformers >= 5.x. Use Prompt Rewriter instead.
    attention_slicingoptBOOLEANfalse
    sequential_offloadoptBOOLEANfalseCPU offload. Saves VRAM, slower.

    Outputs (1)

    NameTypeDescription
    pipelineERNIE_PIPELINE