-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable completion-only loss in SFTTrainer when using Liger Kernel #3674
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
Enable completion-only loss in SFTTrainer when using Liger Kernel #3674
Conversation
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. |
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.
Hi @kswhitecross very nice catch! Thanks for your contribution!
I've ran make precommit
let's see if the ci passes!
I've also tested using
from trl import SFTTrainer, SFTConfig
from datasets import Dataset
dataset = load_dataset("trl-lib/tldr", split="train")
training_args = SFTConfig(
use_liger_kernel=True,
completion_only_loss=True
)
trainer = SFTTrainer(
model="Qwen/Qwen2.5-0.5B",
train_dataset=dataset,
args=training_args
)
print(trainer.train_dataset)
trainer.train()
run command:
accelerate launch pr3674.py
my env setup by trl env
:
- Platform: Linux-5.15.0-1048-aws-x86_64-with-glibc2.31
- Python version: 3.10.16
- TRL version: 0.20.0.dev0+78de9d6
- PyTorch version: 2.7.0
- accelerator(s): NVIDIA H100 80GB HBM3
- Transformers version: 4.52.4
- Accelerate version: 1.7.0
- Accelerate config:
- compute_environment: LOCAL_MACHINE
- distributed_type: NO
- mixed_precision: fp16
- use_cpu: False
- debug: False
- num_processes: 1
- machine_rank: 0
- num_machines: 1
- gpu_ids: 0
- rdzv_backend: static
- same_network: True
- main_training_function: main
- enable_cpu_affinity: False
- downcast_bf16: no
- tpu_use_cluster: False
- tpu_use_sudo: False
- tpu_env: []
- Datasets version: 3.6.0
- HF Hub version: 0.32.2
- bitsandbytes version: not installed
- DeepSpeed version: 0.17.1
- Diffusers version: not installed
- Liger-Kernel version: 0.5.10
- LLM-Blender version: not installed
- OpenAI version: 1.82.0
- PEFT version: 0.15.2
- vLLM version: 0.9.0
Thanks @shirinyamani ! This is my first PR I tried to run |
@kswhitecross yes do |
Have you installed |
@kswhitecross but anyways, thanks for the catch and for now i ran it and CI failure is not relevant to this PR. So we are good on this PR for now! |
Could you please do the same for assistant_masks? Thanks! |
…ggingface#3674) Co-authored-by: kwhitecross <kwhitecross@cs.umass.edu> Co-authored-by: shirinyamani <75791599+shirinyamani@users.noreply.github.com>
What does this PR do?
Fixes #3484, where the
'completion_mask'
column will be stripped fromtrainer.train_dataset
andtrainer.eval_dataset
ifargs.use_liger_kernel == True
. This issue makes it impossible to use the SFTTrainer to train on prompt-completion style datasets with the memory-efficient Liger kernel, without preprocessing the dataset manually.This issue can be minimally reproduced with the following example:
which prints:
With this PR, the output will instead be
enabling the masking out of prompt tokens from the loss.
Before submitting
Pull Request section?
to it if that's the case.
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.