opendatalab/MinerU · error · ValueError

{MODEL_SOURCE_ENV_VAR}=auto is not supported. Unset {MODEL_S

Error message

{MODEL_SOURCE_ENV_VAR}=auto is not supported. Unset {MODEL_SOURCE_ENV_VAR} to use auto detection once, or set it to huggingface/modelscope/local.

What it means

Raised by resolve_model_source() in MineRU's model download utilities when the environment variable MINERU_MODEL_SOURCE is explicitly set to the literal 'auto'. 'auto' is a special internal sentinel meaning 'detect once and persist the result'; pinning it via the environment is disallowed because it would make every call re-run network detection instead of using the persisted source. Valid explicit values are huggingface, modelscope, or local.

Source

Thrown at mineru/utils/models_download_utils.py:216

            )
            if 200 <= response.status_code < 400:
                return "huggingface"
            last_error = f"status_code={response.status_code}"
        except Exception as exc:
            last_error = str(exc)

    logger.warning(
        f"Failed to access {HUGGINGFACE_MODELS_PAGE_URL}: {last_error}, fallback to modelscope."
    )
    return "modelscope"


def resolve_model_source(model_source: str | None = None, allow_auto: bool = False) -> str:
    """将环境变量或配置文件中的模型来源解析为实际可下载的来源。"""
    if model_source is None:
        model_source = os.getenv(MODEL_SOURCE_ENV_VAR)
        if isinstance(model_source, str) and model_source.strip().lower() == "auto":
            raise ValueError(
                f"{MODEL_SOURCE_ENV_VAR}=auto is not supported. "
                f"Unset {MODEL_SOURCE_ENV_VAR} to use auto detection once, "
                "or set it to huggingface/modelscope/local."
            )
    if model_source is None:
        model_source = get_configured_model_source()
    if model_source is None:
        model_source = "auto"
        allow_auto = True

    if not isinstance(model_source, str):
        logger.warning(f"Unsupported model source type: {type(model_source)}, fallback to auto.")
        model_source = "auto"
        allow_auto = True

    normalized_model_source = model_source.strip().lower()
    if normalized_model_source == "local":
        return "local"

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Unset the variable to get one-time auto detection: unset MINERU_MODEL_SOURCE — detection runs, resolves to huggingface or modelscope, and persists the result.
  2. Or pin an explicit source: export MINERU_MODEL_SOURCE=modelscope (or huggingface / local).
  3. Search deployment scripts, Docker ENV lines, and CI variables for MINERU_MODEL_SOURCE=auto and remove or replace it.

Example fix

# before
export MINERU_MODEL_SOURCE=auto

# after
unset MINERU_MODEL_SOURCE
# or: export MINERU_MODEL_SOURCE=modelscope
Defensive patterns

Strategy: validation

Validate before calling

import os
val = os.getenv('MINERU_MODEL_SOURCE')
if val is not None and val.strip().lower() == 'auto':
    os.environ.pop('MINERU_MODEL_SOURCE')  # let MineRU auto-detect once
assert os.getenv('MINERU_MODEL_SOURCE', 'huggingface') in {'huggingface', 'modelscope', 'local'}

Type guard

def is_explicit_model_source(val: str | None) -> bool:
    return val is None or val.strip().lower() in {'huggingface', 'modelscope', 'local'}

Try / catch

try:
    root = auto_download_and_get_model_root_path(rel)
except ValueError as e:
    if 'MINERU_MODEL_SOURCE=auto' in str(e):
        os.environ.pop('MINERU_MODEL_SOURCE', None)
        root = auto_download_and_get_model_root_path(rel)
    else:
        raise

Prevention

When it happens

Trigger: Exporting MINERU_MODEL_SOURCE=auto (any case, surrounding whitespace tolerated) and then calling any model-download path (e.g. auto_download_and_get_model_root_path) that calls resolve_model_source().

Common situations: A user copies an example that lists auto among possible values and exports it 'to be safe'; a CI matrix sets the variable for every job including the auto-detection one; a migration from an older version where auto was accepted as an env value.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/76d3d013244f37be. Report an issue: GitHub.