-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Implement efficient packing without cross-contamination attention #4224
base: main
Are you sure you want to change the base?
Conversation
是否应该考虑使用 varlen_flash_atten 实现? |
@@ -33,6 +33,9 @@ def run_sft( | |||
dataset = get_dataset(model_args, data_args, training_args, stage="sft", **tokenizer_module) | |||
model = load_model(tokenizer, model_args, finetuning_args, training_args.do_train) | |||
|
|||
if data_args.efficient_packing: | |||
configure_packing(model.config, model_args) |
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.
could we do configure_packing
in llamafactory.model.patcher
?
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.
Sure, I just edited it
src/llamafactory/extras/constants.py
Outdated
@@ -66,6 +66,21 @@ | |||
|
|||
SUPPORTED_CLASS_FOR_S2ATTN = {"llama"} | |||
|
|||
SUPPORTED_CLASS_FOR_MULTIPACK = [ |
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 it "efficient_packing" rather than "multipack"?
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.
yes, I just fixed.
Hi @AlongWY , The models in transformers have used flash_attn_varlen_func by default when passing attention_mask. I just made a slight change to the attention_mask when packing sequences and returned indices, cu_seqlens, and max_seqlen_in_batch corresponding to the modified attention_mask. |
What does this PR do?
Update 15/6/2024: Add support packing for eager and sdpa
Fixes #2289
Implement efficient packing without cross-contamination attention
Taking inspiration from some repository as axolotl and functionary, I applied packing sequences more effectively, enabling the model to learn samples more efficiently without attending to other samples within the same pack. Now I only support this implement for sft with flash_attention_2.
Example training config:
Before submitting