Skip to content

Add opt-in strict checkpoint loading to from_pretrained - #48962

Open
YeonwooSung wants to merge 1 commit into
huggingface:mainfrom
YeonwooSung:strict-from-pretrained-checkpoint
Open

YeonwooSung wants to merge 1 commit into
huggingface:mainfrom
YeonwooSung:strict-from-pretrained-checkpoint

Conversation

@YeonwooSung

Copy link
Copy Markdown
Contributor

Fixes #32067

Add opt-in strict=True to from_pretrained. After loading_info is finalized, raise if there are missing or unexpected keys. Default stays False.

This matches torch.nn.Module.load_state_dict(strict=True) for those two sets. Conversion scripts can turn it on without changing For* loads of a base checkpoint.

Discussed on #32067. Arthur +1 still stood; no ACK on missing vs unexpected after 8 days, so this raises on both.

Before submitting

Who can review?

@Cyrilvallez @ArthurZucker @qgallouedec

Raise on missing or unexpected keys when from_pretrained is called with
strict=True. Default remains False so For* loads of a base checkpoint
are unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — automatic approval blocked

This PR was not automatically approved for CI because the security gate failed.

Possible reasons:

  • The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
  • A changed file is outside the allowed directories (src/, tests/, docs/, utils/), has a disallowed extension (only .py, .txt, .md permitted outside tests/ and docs/), or is not .md/.yml inside docs/ — this covers files the PR deletes or renames, not only the ones it edits
  • A new high-severity security issue was detected in the changed Python files (Bandit check)
  • The PR touches a path this repository protects from untrusted PRs, such as the file that decides who reviews it — a maintainer must make that change in a separate PR

See the workflow run for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

@Cyrilvallez

Copy link
Copy Markdown
Member

This comes from a 2 years old feature request, so not sure we actually want it haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checkpoint validation as an option

2 participants