Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose the strict flag to allow catching missing model layers while loading a checkpoint #36760

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HarikrishnanBalagopal
Copy link

@HarikrishnanBalagopal HarikrishnanBalagopal commented Mar 17, 2025

What does this PR do?

Currently model loading succeeds even when a layer is missing from the saved model weights.
This pull reqeust exposes the strict flag from https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.load_state_dict
to allow raising an error when the checkpoint is incomplete (missing some layers).

Also see pytorch/pytorch#82963

Fixes

  warnings.warn(
There were missing keys in the checkpoint model loaded: ['lm_head.weight'].

Related issues:

Before submitting

  • [n] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [y] Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions github-actions bot marked this pull request as draft March 17, 2025 09:54
Copy link

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the Ready for review button (at the bottom of the PR page).

@HarikrishnanBalagopal HarikrishnanBalagopal marked this pull request as ready for review March 17, 2025 10:02
@github-actions github-actions bot requested review from muellerzr and SunMarc March 17, 2025 10:03
…hile loading a checkpoint

Signed-off-by: Harikrishnan Balagopal <harikrishmenon@gmail.com>
Signed-off-by: Harikrishnan Balagopal <harikrishmenon@gmail.com>
Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want to add this flag in trainer as this is related to model loading cc @muellerzr This is something that should be fixed when trying to load the model before the training.

@HarikrishnanBalagopal
Copy link
Author

Not sure we want to add this flag in trainer as this is related to model loading cc @muellerzr This is something that should be fixed when trying to load the model before the training.

I understand the concern but the train function also has resume_from_checkpoint which does model loading.

Copy link
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a training arg instead, so we don't need to change all of the function signatures. (I'm open to this being a thing since during resume we don't do that outside, however it should be in TrainingArguments instead)

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.

3 participants