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

Rename trainer arg tokenizer to processing_class #2162

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

Conversation

qgallouedec
Copy link
Member

@qgallouedec qgallouedec commented Oct 3, 2024

What does this PR do?

Fixes #2161

Ensure backward compatibility for DPO and SFT only

>>> from datasets import load_dataset
>>> from transformers import AutoModelForCausalLM, AutoTokenizer
>>> from trl import DPOConfig, DPOTrainer
>>> model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
>>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
>>> dataset = load_dataset("trl-lib/Capybara-Preferences", split="train")
>>> training_args = DPOConfig(output_dir="Qwen2.5-0.5B-DPO")
>>> trainer = DPOTrainer(model=model, args=training_args, train_dataset=dataset, tokenizer=tokenizer)
/fsx/qgallouedec/miniconda3/envs/trl/lib/python3.11/site-packages/huggingface_hub/utils/_deprecation.py:101: FutureWarning: `tokenizer` is deprecated and will be removed in version 0.14.0 for `DPOTrainer.__init__`. Use `processing_class` instead.
  return f(*args, **kwargs)

TODO

  • BCO
  • CPO
  • DPO
  • GKD
  • KTO
  • Nash-MD
  • Online DPO
  • ORPO
  • PPOv2
  • Reward
  • RLOO
  • SFT
  • XPO

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.

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

@qgallouedec qgallouedec linked an issue Oct 3, 2024 that may be closed by this pull request
4 tasks
@qgallouedec qgallouedec marked this pull request as ready for review October 4, 2024 12:24
trl/trainer/dpo_trainer.py Outdated Show resolved Hide resolved
trl/trainer/ppov2_trainer.py Outdated Show resolved Hide resolved
@@ -599,7 +604,7 @@ def repeat_generator():

def generate_completions(self, sampling: bool = False):
args = self.args
tokenizer = self.tokenizer
processing_class = self.processing_class
Copy link
Member

Choose a reason for hiding this comment

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

I may be missing something but is this required? Cannot we just use self.processing_class?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. Same for args. It will probably need some refactoring in the future

Copy link
Member

Choose a reason for hiding this comment

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

I've seen that in other places too so maybe there's a rationale that I don't see for that? Not sure, but sure we'll keep it in mind

trl/trainer/rloo_trainer.py Outdated Show resolved Hide resolved
trl/trainer/rloo_trainer.py Outdated Show resolved Hide resolved
qgallouedec and others added 5 commits October 4, 2024 16:36
Co-authored-by: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com>
Co-authored-by: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com>
Co-authored-by: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com>
Co-authored-by: Alvaro Bartolome <36760800+alvarobartt@users.noreply.github.com>
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.

AttributeError: property 'tokenizer' of 'DPOTrainer' object has no setter
3 participants