transformers - 💡(How to fix) Fix PretrainedConfig.from_pretrained: silent default on missing config.json

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When PretrainedConfig.from_pretrained(path) is given a local directory with no config.json, it silently returns a default-populated config instead of raising OSError. The return type is the config class itself (not Optional) and the docstring does not document this fallback, so a wrong-path call has no way to surface until much later (model build, weight load, OOM, CI timeout).

Root Cause

(AutoConfig raises ValueError("Unrecognized model") because the factory needs model_type; the silent fallback is on concrete PretrainedConfig subclasses.)

Code Example

import tempfile
from transformers import LlamaConfig

with tempfile.TemporaryDirectory() as d:
    cfg = LlamaConfig.from_pretrained(d)
    print(type(cfg).__name__, cfg.model_type)
    # 5.5.4: raises OSError ("...no file named config.json...")
    # 5.6+:  silently returns LlamaConfig with defaults

---

_get_config_dict   -> (None, kwargs)
get_config_dict    -> ({}, kwargs)
from_dict({})      -> cls()   # populates from defaults; no raise
RAW_BUFFERClick to expand / collapse

System Info

  • transformers 5.6+ (verified on 5.8.0; 5.5.4 raised)
  • introduced by #36033 ("Large/full refactor of from_pretrained", 2025-03-12)

Description

When PretrainedConfig.from_pretrained(path) is given a local directory with no config.json, it silently returns a default-populated config instead of raising OSError. The return type is the config class itself (not Optional) and the docstring does not document this fallback, so a wrong-path call has no way to surface until much later (model build, weight load, OOM, CI timeout).

Reproduction

import tempfile
from transformers import LlamaConfig

with tempfile.TemporaryDirectory() as d:
    cfg = LlamaConfig.from_pretrained(d)
    print(type(cfg).__name__, cfg.model_type)
    # 5.5.4: raises OSError ("...no file named config.json...")
    # 5.6+:  silently returns LlamaConfig with defaults

(AutoConfig raises ValueError("Unrecognized model") because the factory needs model_type; the silent fallback is on concrete PretrainedConfig subclasses.)

Where it changed

cached_files (hub.py) has long special-cased missing config.json to return None (unchanged since 5.5.4; needed so a Hub model id with a cache miss can fall through to download).

#36033 changed the caller chain in configuration_utils.py:

_get_config_dict   -> (None, kwargs)
get_config_dict    -> ({}, kwargs)
from_dict({})      -> cls()   # populates from defaults; no raise

In 5.5.4 the caller raised at this junction.

Suggested fix

For a local directory input, restore the 5.5.4 caller-side raise. Hub-id fallback semantics can stay.

Note

I confirm this is not a pure code-agent issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING