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

🔬 SFT simplification #2405

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

🔬 SFT simplification #2405

wants to merge 47 commits into from

Conversation

qgallouedec
Copy link
Member

@qgallouedec qgallouedec commented Nov 28, 2024

What does this PR do?

Context

This PR is the first iteration of SFT refactoring: tests have deliberately been left unmodified, to ensure continuity of support for the user and, if possible, no breaking changes.

Other PRs will follow to further simplify the SFT (to be discussed on a case-by-case basis). These modifications would require test modifications and breaking changes. For example:

  • drop support for ConstantLengthDataset in favor of the packing argument alone.
  • don't allow TrainingArguments and impose SFTConfig.
  • better structure tests
  • full support of training on completions only (does not require a response template but use the data directly)
  • ...

What's in this PR

This PR refactor and simplifies SFT.

Add full conversational/standard dataset support

Part of #2071

Refactor packing

Drop ConstantLengthDataset in favour of a simpler approach (see pack_examples)

Current status

Testing. The goal is to gather code example from anywhere and ensure there're still working.

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.

Comment on lines -410 to -449
# This should not work because not enough data for one sample
training_args = SFTConfig(
output_dir=tmp_dir,
dataloader_drop_last=True,
max_steps=2,
eval_steps=1,
save_steps=1,
per_device_train_batch_size=2,
max_seq_length=1024, # make sure there is NOT at least 1 packed sequence
packing=True,
report_to="none",
)
with self.assertRaises(ValueError):
_ = SFTTrainer(
model=self.model,
args=training_args,
train_dataset=self.dummy_dataset,
formatting_func=formatting_prompts_func,
)

# This should not work as well
with self.assertRaises(ValueError):
training_args = SFTConfig(
output_dir=tmp_dir,
dataloader_drop_last=True,
max_steps=2,
eval_steps=1,
save_steps=1,
per_device_train_batch_size=2,
packing=False,
report_to="none",
)
_ = SFTTrainer(
model=self.model,
args=training_args,
train_dataset=self.dummy_dataset,
formatting_func=formatting_prompts_func,
)

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 new implementation extend the support for these two cases

@@ -807,8 +768,6 @@ def test_sft_trainer_infinite_with_model(self):
eval_dataset=self.eval_dataset,
)

self.assertTrue(trainer.train_dataset.infinite)
Copy link
Member Author

@qgallouedec qgallouedec Dec 1, 2024

Choose a reason for hiding this comment

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

the trainer is not "infinite" (subclass of ConstantLenghtDataset) anymore: it's better since we can use num_epochs now

@qgallouedec qgallouedec changed the title [Experimental] 🔬 SFT simplification 🔬 SFT simplification Dec 1, 2024
@qgallouedec qgallouedec requested review from lewtun and kashif December 1, 2024 14:52
@qgallouedec qgallouedec marked this pull request as ready for review December 1, 2024 14:52
@qgallouedec
Copy link
Member Author

qgallouedec commented Dec 4, 2024

FSDP + QLora from https://github.com/huggingface/peft/blob/main/examples/sft/run_peft_qlora_fsdp.sh

green: main
purple: pr

Screenshot 2024-12-04 at 14 18 09

qgallouedec and others added 12 commits December 4, 2024 14:39
* First changes

* Other files

* Finally

* rm comment

* fix nashmd

* Fix example

* Fix example [ci skip]
* fix chat for windows

* add some tests back

* Revert "add some tests back"

This reverts commit 350aef5.
* datast_config_name

* Update trl/utils.py [ci skip]

* sort import

* typo [ci skip]

* Trigger CI

* Rename `dataset_config_name` to `dataset_config`
* Remove unused deepspeed code

* add model prep back

* add deepspeed even if it doesn't work

* rm old code
* `model_config` -> `model_args`

* sort
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.

2 participants