sgl-project/sglang · error · RuntimeError

Failed to load diffusers config from {file_path}: {e}

Error message

Failed to load diffusers config from {file_path}: {e}

What it means

load_dict wraps all exceptions raised while reading/parsing a diffusers component config JSON (missing file, permission error, JSONDecodeError) into a RuntimeError with the offending path and cause.

Source

Thrown at python/sglang/multimodal_gen/runtime/utils/hf_diffusers_utils.py:474

):
    return AutoConfig.from_pretrained(
        model, trust_remote_code=trust_remote_code, revision=revision, **kwargs
    )


def load_dict(file_path):
    if not os.path.exists(file_path):
        return {}
    try:
        # Load the config directly from the file
        with open(file_path) as f:
            config_dict: dict[str, Any] = json.load(f)
        if "_diffusers_version" in config_dict:
            config_dict.pop("_diffusers_version")
        # TODO(will): apply any overrides from inference args
        return config_dict
    except Exception as e:
        raise RuntimeError(
            f"Failed to load diffusers config from {file_path}: {e}"
        ) from e


def _split_hf_subfolder(path: str) -> tuple[str, str | None]:
    """Split 'namespace/repo/subfolder' into (repo_id, subfolder), or return (path, None)."""
    if os.path.isabs(path):
        return path, None
    parts = path.split("/")
    if len(parts) > 2:
        return "/".join(parts[:2]), "/".join(parts[2:])
    return path, None


def prepare_diffusers_component_path_for_loading(component_path: str) -> str:
    """Download component repos if needed and patch legacy flat ModelOpt configs."""
    if os.path.exists(component_path):
        local_component_path = component_path

View on GitHub (pinned to 0132848349)

Solutions

  1. Validate the file exists and parses: python -m json.tool <path>
  2. If the HF cache snapshot is partial/corrupt, delete the model directory and re-download
  3. Check the component/subfolder name passed to the loader matches the repo layout
Defensive patterns

Strategy: try-catch

Validate before calling

import json, os
assert os.path.isfile(path)
json.loads(open(path).read())  # dry parse

Try / catch

try:
    cfg = load_dict(path)
except RuntimeError as e:
    if 'Failed to load diffusers config' in str(e):
        # re-download or fall back to default config
        ...

Prevention

When it happens

Trigger: Calling load_customized or get_diffusers_component_config where the component config JSON path does not exist, is unreadable, or contains malformed JSON. The `except Exception` also swallows json.pop bugs on unexpected structures.

Common situations: Corrupted or partially downloaded HF cache snapshot; manually edited config.json with trailing commas; wrong subfolder name passed to component loading.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b1cc14d7a8dd04d4. Report an issue: GitHub.