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.
What does this PR do?
Adds padding-free training to the
BambaModel
, enabling more efficient training with causal masking between disjoint sequences.Performance: approximately 2x throughput improvements over naive padding for supervised finetuning on the Tulu v3 dataset with open-instruct. Tokens/sec/gpu plots for
batch_size_per_gpu = 4
:8 A100s: 600 --> 1200 Tok/s/gpu
32 A100s: 450 --> 750 Tok/s/gpu
CC @fabianlim
CC reviewers of #34982: @ArthurZucker @molbap
Notes on Code
BambaMixer
).BambaAttention
layers are untouched.cuda
and requires the mamba kernels.position_ids
andFlashAttentionKwargs
padding-free code paths.Notes on Tests
On both latest
main
and this PR branch the followingtests/models/bamba/test_modeling_bamba.py
tests are failing (withRUN_SLOW=1
):test_eager_matches_fa2_generate
test seems flaky: sometimes it passes, other times it fails.test_flash_attention_2_padding_matches_padding_free_with_position_ids
:main
, this test fails because padding-free is not implemented.position_ids
whenmodel.training = True
and this test explicitly callseval()
on the model. I have checked that this test passes whenmodel.training = True
. Edit: seeBambaModelTest::test_attn_mask_position_ids_flash_attn_equality
, also.test_simple_generate
appears to just need a simple edit for its expected text. It consistently fails with:where the generated and expected text differs at the very end.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.