Skip to content

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 merged commit 5b9236d into main Feb 7, 2025
@qgallouedec qgallouedec deleted the sft-refactor branch February 7, 2025 23:21
yxliu-TAMU pushed a commit to mincheolseong/ECEN743-GRPO-Project-Proposal that referenced this pull request Apr 20, 2025
* 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>
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