-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Remove graph breaks for torch.compile() in padding free branch in DataCollatorForCompletionOnlyLM #2158
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
6cfa171
to
a27b3a2
Compare
a27b3a2
to
4b34ec3
Compare
CC: @kashif @qgallouedec |
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. |
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
f0afdb2
to
fb669b6
Compare
Hi, thanks for the PR. |
Could you provide a simple test to:
It might also be helpful to add a few comments, as these lines are unclear without context. |
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Thank you @qgallouedec for the review. This is the related transformers PR which is approved and merged. I added 2 test cases. One where Tuning fails |
@kashif @qgallouedec Could you possibly review this PR ? Thank you! |
Hi @kashif @qgallouedec, could you please take another look at this PR when you get the chance? The changes in this PR are urgent for making |
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
Signed-off-by: Abhishek <[email protected]>
tests/test_sft_trainer.py
Outdated
formatted_dataset = lambda example: { | ||
"output": f"### prompt:\n{example['prompt'].strip()}\n\n### completion:\n{example['completion'].strip()}{tokenizer.eos_token}" | ||
} |
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.
is dataset formatting required here, or can we drop it?
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.
dataset formatting is required because the SFTTrainer
and DataCollatorForCompletionOnlyLM
expect the dataset to have a specific format—a single text field that combines both the prompt and the completion in a way the model can understand. This function includes both the prompt and completion, ensuring the data collator can correctly identify where the completion starts using the response_template
.
tests/test_sft_trainer.py
Outdated
@@ -654,6 +654,50 @@ def test_data_collator_completion_lm_with_multiple_text(self): | |||
result_text = tokenizer.decode(batch["input_ids"][i, last_pad_idx + 1 :]) | |||
self.assertEqual(result_text, "I have not been masked correctly.") | |||
|
|||
def test_data_collator_completion_lm_without_padding(self): | |||
os.environ["CUDA_VISIBLE_DEVICES"]="0" |
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.
Does the issue only occur with cuda device? In other words can we reproduce on cpu?
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.
Due to usage of flash_attention_2
it would work only on GPU.
Hey @Abhishek-TAMU, to keep you posted with the current status of the PR, I am struggling reproducing the initial error. Do you have a MRE by any chance? The code from the unittest gives
and it doesn't seem related |
Thank you @qgallouedec for looking into this. Sharing you the code which would produce graph break. If this change huggingface/transformers#33932 is used in transformers then Graph break could be avoided.
|
Hi @qgallouedec, were you able to reproduce the initial error with this MRE ? |
What does this PR do?
This PR adds
cu_seq_lens_q
,cu_seq_lens_k
,max_length_k
,max_length_q
to the batch inDataCollatorForCompletionOnlyLM
. This, together with a PR in transformers (link to be added), removes graph breaks in padding-free tuning, allowing for maximum performance to be obtained.Specifically, these parameters should be generated here (this PR change), outside of the transformers loop, as they incur a cpu-gpu sync that is unavoidable. Otherwise, this cpu-gpu sync happens here, inside the attention call which causes graph breaks and hence the transformers PR removes this call to remove all graph breaks when
torch_compile
flag is turned on in Training arguments to use in SFTTrainer.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.