Shift Computation of PaddingFree Variable CuSeqLen
from Flash Attention Forward to DataCollatorWithFlattening
#65
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.
Description
To save on repeated computation of the same input across all the flash attention forward layers, this PR shifts the computation of arguments
cu_seq_len
andmax_length
to the data collator.Running the same benchmark on ORCA Math from Transformers Padding Free, there is approx 2% improvement in train runtime from this implementation change.
Transformers < 4.43
) - Computation of Arguments at FA ForwardTransformers < 4.43
) - Computation of Arguments at Data CollatorReproduce
NOTE: The top level model's forward method had to be patched with a wrapper function to accept the additional kwargs from the data collator. Due to the change in method signature, HFTrainer will remove unused columns not detected from the model's forward method signature, causing it To avoid the removal, additional arg,
remove_unused_columns=False
needs to be passed to the Trainer.TODO: