Skip to content

Tied weights load#24310

Merged
sgugger merged 7 commits intomainfrom
tied_weights_load
Jun 16, 2023
Merged

Tied weights load#24310
sgugger merged 7 commits intomainfrom
tied_weights_load

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!

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
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