invoke-ai/InvokeAI · error · NotAMatchError

could not read text_encoder/config.json: {e}

Error message

could not read text_encoder/config.json: {e}

What it means

`NotAMatchError` `could not read text_encoder/config.json: {e}` means the config file exists but could not be opened or parsed — an `OSError` (permissions, unreadable file, path issue) or a `json.JSONDecodeError` (truncated/corrupt/invalid JSON). The loader chains the underlying exception so `__cause__` holds the real reason.

Source

Thrown at invokeai/backend/model_manager/configs/qwen_vl_encoder.py:102

            )

        text_encoder_dir = mod.path / "text_encoder"
        tokenizer_dir = mod.path / "tokenizer"

        if not text_encoder_dir.is_dir():
            raise NotAMatchError("missing text_encoder/ subfolder")
        if not tokenizer_dir.is_dir():
            raise NotAMatchError("missing tokenizer/ subfolder")

        config_path = text_encoder_dir / "config.json"
        if not config_path.is_file():
            raise NotAMatchError(f"missing {config_path}")

        try:
            with open(config_path, "r", encoding="utf-8") as f:
                cfg = json.load(f)
        except (OSError, json.JSONDecodeError) as e:
            raise NotAMatchError(f"could not read text_encoder/config.json: {e}") from e

        class_name = cfg.get("_class_name")
        architectures = cfg.get("architectures") or []
        candidates = {class_name, *architectures} - {None}

        if not candidates & _RECOGNIZED_TEXT_ENCODER_CLASSES:
            raise NotAMatchError(
                f"text_encoder class is {sorted(candidates) or 'unknown'}, "
                f"expected one of {sorted(_RECOGNIZED_TEXT_ENCODER_CLASSES)}"
            )

        return cls(**override_fields)


class QwenVLEncoder_Checkpoint_Config(Checkpoint_Config_Base, Config_Base):
    """Configuration for single-file Qwen2.5-VL encoder checkpoints (safetensors).

    This matches ComfyUI-style consolidated single-file encoders such as

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Inspect `error.__cause__` to see whether it is an OSError or JSONDecodeError
  2. Validate the file: `python -c "import json;print(json.load(open('text_encoder/config.json')))"`
  3. Re-download `text_encoder/config.json` from the source HF repo
  4. Fix file permissions (`chmod 644`) or move the model off a failing network mount

Example fix

# before: truncated / corrupt config.json
# after
huggingface-cli download <repo> text_encoder/config.json --force-download
Defensive patterns

Strategy: validation

Validate before calling

import json
from pathlib import Path

def config_json_parses(model_dir: Path) -> bool:
    p = model_dir / "text_encoder" / "config.json"
    try:
        json.loads(p.read_text(encoding="utf-8"))
        return True
    except (OSError, json.JSONDecodeError):
        return False

Try / catch

try:
    cfg = QwenVLTextEncoderConfig.from_model_on_disk(mod, override_fields)
except NotAMatchError as e:
    cause = e.__cause__
    print(f"config.json unreadable: {cause!r}")  # OSError vs JSONDecodeError tells you the fix
    raise

Prevention

When it happens

Trigger: `from_model_on_disk` (invoked via model probing) on a model whose `text_encoder/config.json` is unreadable: zero-byte file from an interrupted download, HTML error page saved as config.json, permission-denied, or truncated write.

Common situations: Interrupted or disk-full downloads, files synced before upload finished (cloud-drive placeholders), non-UTF8 or hand-edited JSON with trailing commas, files locked by another process on network shares.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/0eac95dfc5d21c9f. Report an issue: GitHub.