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

Tied weights load #24310

Merged
merged 7 commits into from
Jun 16, 2023
Merged

Tied weights load #24310

merged 7 commits into from
Jun 16, 2023

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Jun 15, 2023

What does this PR do?

This continue cleaning up a bit the model loading by:

  1. Using the new _tied_weight_keys class variable when deleting weights without warning for safetensors serialization
  2. Fix the logic that deletes tied params in missing keys and add a test (which fails on main)
  3. As discussed internally, use a logger.info for the unexepected keys warning when the class used to load the model does not match the class in the config.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 15, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@@ -3274,7 +3267,9 @@ def _find_mismatched_keys(
missing_keys = [elem for elem in missing_keys if "SCB" not in elem]

if len(unexpected_keys) > 0:
logger.warning(
archs = [] if model.config.architectures is None else model.config.architectures
warner = logger.warn if model.__class__.__name__ in archs else logger.info
Copy link
Member

Choose a reason for hiding this comment

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

Good!

@sgugger sgugger merged commit 096f2cf into main Jun 16, 2023
@sgugger sgugger deleted the tied_weights_load branch June 16, 2023 14:55
@ydshieh ydshieh restored the tied_weights_load branch June 19, 2023 14:04
@@ -3019,22 +3019,15 @@ def _fix_key(key):
unexpected_keys = list(set(loaded_keys) - set(expected_keys))

if is_accelerate_available():
model.tie_weights()
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sgugger This line causes a test of marian failing due to garbage output values.

It was removed by @SunMarc in #24200 when I reported the same issue to him.

If this line is necessary, we might need some fix/change for marian or its test.

tests/models/marian/test_modeling_marian.py::TestMarian_FI_EN_V2::test_batch_generation_en_fr

(line 433)  AssertionError: Lists differ: ['I like to read books', 'I like watching football'] != ['obliterat obliterat obliterat obliterat o[1345 chars]ɰɰɰ']

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line is necessary. I'll look at the test later today.

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.

4 participants