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

👮 Deprecate policy in favor of model in PPOTrainer #2386

Merged
merged 6 commits into from
Nov 26, 2024
Merged

Conversation

qgallouedec
Copy link
Member

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? 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.
  • 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.

@qgallouedec qgallouedec requested review from kashif and lewtun November 22, 2024 18:37
if module is not None:
disable_dropout_in_model(module)
if args.stop_token and args.stop_token == "eos":
args.stop_token_id = processing_class.eos_token_id
self.model = PolicyAndValueWrapper(self.policy, self.value_model)
Copy link
Member Author

Choose a reason for hiding this comment

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

model replaced by policy_and_value
policy replaced by model

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

def __init__(
self,
config: PPOConfig,
processing_class: Optional[
Union[PreTrainedTokenizerBase, BaseImageProcessor, FeatureExtractionMixin, ProcessorMixin]
],
policy: nn.Module,
ref_policy: Optional[nn.Module],
model: nn.Module,
Copy link
Member

Choose a reason for hiding this comment

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

If I'm not mistaken, won't this breaking change be introduced in the next TRL release (i.e. v0.13.0 instead of 0.150)? In other words, don't we technically need to support both sets of args until v0.15?

Copy link
Member Author

Choose a reason for hiding this comment

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

The decorator allows for supporting both args, and when the old one is used, raises a warning:

>>> from datasets import load_dataset
>>> from transformers import AutoModelForCausalLM, AutoModelForSequenceClassification, AutoTokenizer
>>> from trl import PPOConfig, PPOTrainer
>>> args = PPOConfig("my_out_dir")
>>> tokenizer = AutoTokenizer.from_pretrained("EleutherAI/pythia-1b-deduped")
>>> model = AutoModelForCausalLM.from_pretrained("EleutherAI/pythia-1b-deduped")
>>> ref_model = AutoModelForCausalLM.from_pretrained("EleutherAI/pythia-1b-deduped")
>>> reward_model = AutoModelForSequenceClassification.from_pretrained("EleutherAI/pythia-1b-deduped", num_labels=1)
>>> value_model = AutoModelForSequenceClassification.from_pretrained("EleutherAI/pythia-1b-deduped", num_labels=1)
>>> dataset = load_dataset("trl-internal-testing/descriptiveness-sentiment-trl-style", split="descriptiveness")
>>> trainer = PPOTrainer(
...      config=args,
...      processing_class=tokenizer,
...      policy=model,  # old arg here
...      ref_model=ref_model,
...      reward_model=reward_model,
...      value_model=value_model,
...      train_dataset=dataset,
...  )
/fsx/qgallouedec/transformers/src/transformers/utils/deprecation.py:165: FutureWarning: `policy` is deprecated and removed starting from version 0.15.0 for `PPOTrainer.__init__`. Use `model` instead.
  return func(*args, **kwargs)

Did I misunderstand your point?

Copy link
Member

Choose a reason for hiding this comment

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

Ah I was mistaken indeed. This looks great then!

Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but I have a concern this will break the trainer in the next release instead of the desired v0.15. I realise this trainer isn't used much, so it's probably OK to break across revisions in the interest of reaching stability long-term

@qgallouedec qgallouedec merged commit 16fa13c into main Nov 26, 2024
14 checks passed
@qgallouedec qgallouedec deleted the model-ppo-arg branch November 26, 2024 07:13
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