-
Notifications
You must be signed in to change notification settings - Fork 2.1k
🔬 SFT simplification #2405
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
Conversation
…o sft-refactor
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. |
# 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, | ||
) | ||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
…o sft-refactor
* initial commit * update * Refactor SFTTrainer and SFTConfig * Update SFTConfig class in sft_config.py * Fix SFTConfig torch_dtype validation and dataset preprocessing flag * Refactor dataset mapping and conversion * Refactor dataset mapping in SFTTrainer * Fix SFTTrainerTester unit test by removing unnecessary code * Remove unused variables and update tokenization logic * Remove pack_dataset function * Add deprecation warning for tokenizer in SFTTrainer constructor * add docstring back * Update model parameter type annotation * Update SFTTrainer class definition * style * preprocess_dataset -> _prepare_dataset * Retro compat * Update formatting_func type hint in SFTTrainer constructor * typo * better comment * simplify tokenize row * Fix type hint for peft_config * fix doc * Add pack_examples function to `test_data_utils.py` * promote pack_examples and document * improve doc * Add new SFTTrainerTester2 class for testing * test was reversed * ©️ Copyrights update (huggingface#2454) * First changes * Other files * Finally * rm comment * fix nashmd * Fix example * Fix example * 💬 Fix chat for windows (huggingface#2443) * fix chat for windows * add some tests back * Revert "add some tests back" This reverts commit 350aef5. * 🆔 Add `datast_config` to `ScriptArguments` (huggingface#2440) * datast_config_name * Update trl/utils.py * sort import * typo * Trigger CI * Rename `dataset_config_name` to `dataset_config` * 🏎 Fix deepspeed preparation of `ref_model` in `OnlineDPOTrainer` (huggingface#2417) * Remove unused deepspeed code * add model prep back * add deepspeed even if it doesn't work * rm old code * 👯 Standardize `model_args` (huggingface#2442) * `model_config` -> `model_args` * sort * refactor config * drop skip prepare dataset * add sep to packing * drop prompt-completion for now * Revert "drop prompt-completion for now" This reverts commit 16ef195. * Revert "add sep to packing" This reverts commit dc84d08. * Revert "drop skip prepare dataset" This reverts commit d2ee070. * Revert "refactor config" This reverts commit f732aa8. * Format * Update doc-builder workflow to use specific commit sha * add peft edge cases * no logits when using liger * remove unused columns * proper handle of prompt-completion * trick to keep messages * fix messages missing * for Liger kernel, ensure only input_ids is present * packing and liger are compatible * shinny doc and final nits * another nit * refactor config and doc * re add truncation * fix ci * drop deprecated params in tests * fix link * fix config docstring --------- Co-authored-by: Kashif Rasul <kashif.rasul@gmail.com>
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:
ConstantLengthDataset
in favor of thepacking
argument alone.TrainingArguments
and imposeSFTConfig
.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 (seepack_examples
)Current status
Testing. The goal is to gather code example from anywhere and ensure there're still working.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines.
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.