Comfy-Org/ComfyUI · error · RuntimeError

ERROR: audio encoder file is invalid or unsupported embed_di

Error message

ERROR: audio encoder file is invalid or unsupported embed_dim: {}

What it means

load_audio_encoder detects wav2vec2-family checkpoints by state-dict keys and then switches on the encoder's embed_dim (e.g. 1024 for large, 768 for base). Any other embed_dim has no known config, so it raises RuntimeError rather than guessing an architecture and producing garbage. The file is treated as invalid-or-unsupported for this code path.

Source

Thrown at comfy/audio_encoders/audio_encoders.py:76

                "num_layers": 24,
                "conv_norm": True,
                "conv_bias": True,
                "do_normalize": True,
                "do_stable_layer_norm": True
                }
        elif embed_dim == 768: # base
            config = {
                "model_type": "wav2vec2",
                "embed_dim": 768,
                "num_heads": 12,
                "num_layers": 12,
                "conv_norm": False,
                "conv_bias": False,
                "do_normalize": False, # chinese-wav2vec2-base has this False
                "do_stable_layer_norm": False
            }
        else:
            raise RuntimeError("ERROR: audio encoder file is invalid or unsupported embed_dim: {}".format(embed_dim))
    elif "model.encoder.embed_positions.weight" in sd:
        sd = comfy.utils.state_dict_prefix_replace(sd, {"model.": ""})
        config = {
            "model_type": "whisper3",
        }
    else:
        raise RuntimeError("ERROR: audio encoder not supported.")

    audio_encoder = AudioEncoderModel(config)
    m, u = audio_encoder.load_sd(sd)
    if len(m) > 0:
        logging.warning("missing audio encoder: {}".format(m))
    if len(u) > 0:
        logging.warning("unexpected audio encoder: {}".format(u))

    return audio_encoder

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Use one of the supported checkpoints (wav2vec2-large or base-family encoders, e.g. the ones referenced by ComfyUI audio nodes).
  2. Re-download the model in case of corruption, and verify it loads in transformers with AutoModel.
  3. If it is a custom fine-tune, export with the original architecture dims or patch load_audio_encoder locally to add a config for your embed_dim.
Defensive patterns

Strategy: validation

Validate before calling

sd = comfy.utils.load_torch_file(path)
key = "model.encoder.layers.0.self_attn.q_proj.weight"  # adjust per checkpoint
embed_dim = sd[key].shape[0] if key in sd else None
if key in sd and embed_dim not in (768, 1024):
    raise SystemExit(f"unsupported embed_dim {embed_dim}; use a supported wav2vec2 checkpoint")

Type guard

def is_supported_embed_dim(sd: dict) -> bool:
    for k, v in sd.items():
        if k.endswith("self_attn.q_proj.weight"):
            return v.shape[0] in (768, 1024)
    return False

Try / catch

try:
    enc = load_audio_encoder(sd)
except RuntimeError as e:
    if "embed_dim" in str(e):
        raise SystemExit("Use a supported wav2vec2 base/large encoder checkpoint")
    raise

Prevention

When it happens

Trigger: Loading a wav2vec2 checkpoint with an unusual hidden size (small/large variants fine-tuned with a projection, e.g. 1024-projected or custom distills); a partially exported or re-saved checkpoint; a non-wav2vec2 file whose keys happen to match the wav2vec2 signature.

Common situations: Using a community fine-tune with modified projection layers; loading a HuBERT/Data2Vec-ish checkpoint with overlapping key names; wrong file downloaded (half-converted safetensors).

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/0a5d03cb40bcf005. Report an issue: GitHub.