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

[core] Push v_head when using AutoModelForCausalLMWithValueHead #86

Merged
merged 10 commits into from
Jan 19, 2023

Conversation

younesbelkada
Copy link
Contributor

@younesbelkada younesbelkada commented Jan 16, 2023

What does this PR do?

This PR addresses saving v_head weights when calling save_pretrained. Before this PR if a user wanted to share intermediate-trained v_head weights it was not possible. The workaround that I have found needs to load the state dict twice, once by the from_pretrained method that is called by the pretrained_model attribute and once afterwards to manually load the v_head.
This PR introduces a new kwarg on the method from_pretrained termed as resume_training as I think this is quite an edge case.

Added also some tests

TODOs:

  • test push_to_hub

cc @lvwerra @lewtun

- working script
- added tests
- possible to load `v_head`
- possible to use `transformers` too
@younesbelkada younesbelkada changed the title [core] Push `v_head [core] Push v_head when using AutoModelForCausalLMWithValueHead Jan 16, 2023
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jan 16, 2023

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

@younesbelkada younesbelkada mentioned this pull request Jan 16, 2023
26 tasks
@younesbelkada younesbelkada marked this pull request as draft January 16, 2023 13:59
@younesbelkada younesbelkada marked this pull request as ready for review January 16, 2023 15:37
# state_dict is removed from the model after loading it.
# since this is only done in edge cases we force the user to do it only
# if they explicitly set resume_training to True
if resume_training:
Copy link
Member

Choose a reason for hiding this comment

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

If someone is using the AutoModelForCausalLMWithValueHead to load a model I think we can assume that they want to use the Value head so I we should always load it if it's available. What do you think?

Copy link
Contributor Author

@younesbelkada younesbelkada Jan 19, 2023

Choose a reason for hiding this comment

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

OK for me!
We should advice users to use AutoModelForCausalLM when using the model outside trl (i.e. not for training with PPO)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more description in 853d52d

- update based on comments
- add more tests
- update docs
@younesbelkada younesbelkada requested a review from lvwerra January 19, 2023 10:05
@younesbelkada
Copy link
Contributor Author

younesbelkada commented Jan 19, 2023

Actually this was not working in the sharded case, I'd expect users to load large & sharded models too!
The commit 70274c3 & bd10a97 should fix that

@younesbelkada younesbelkada requested a review from lvwerra January 19, 2023 11:13
@younesbelkada younesbelkada merged commit 4f5c16f into huggingface:main Jan 19, 2023
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