-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Auto-enable padding-free SFT #3672
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
Merged
danielhanchen
merged 68 commits into
unslothai:main
from
djsaunde:padding-free-seqlen-metadata-v2
Dec 10, 2025
Merged
Auto-enable padding-free SFT #3672
danielhanchen
merged 68 commits into
unslothai:main
from
djsaunde:padding-free-seqlen-metadata-v2
Dec 10, 2025
+281
−20
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
d5b342f to
a69f35b
Compare
Collaborator
Author
|
Closing in favor of #3702. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is built on top of #3566, and should be merged after it.
This PR auto-sets
padding_free=Truewhen applicable (text-only SFT training) and does some work behind the scenes to compute sequence length metadata, so we can use the varlen flash attention kernels / block-diagonal SDPA / xformers kernels.This gives us throughput gains with sufficiently large models / batch sizes; e.g., a super small model like
unsloth/qwen2.5-0.5brequiresper_device_train_batch_size = 16or higher in order to see (significant) throughput gains, whileunsloth/llama-3-8brequires onlyper_device_train_batch_size = 4or higher. For example, withunsloth/llama-3-8bwithper_device_train_batch_size = 8, we observe much faster training (52s padding-free vs 96s not; about 1.85x speedup).There are very slight loss and gradient norm differences in the padding-free vs. not settings; I think these can be chalked up to the different kernels being used (FA2 varlen vs. dense, block-diagonal vs. causal kernels for xformers / SDPA).