Skip to content

Commit eadc0a2

Browse files
Make the tiny LFM2.5-VL model Flash Attention compatible with an explicit head_dim and fewer vision heads (#8489)
1 parent 7aa106a commit eadc0a2

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎scripts/generate_tiny_models/for_conditional_generation/lfm2_vl_for_conditional_generation.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"hidden_size": 8,
4444
"num_attention_heads": 4,
4545
"num_key_value_heads": 2,
46+
"head_dim": 8, # a multiple of 8, as Flash Attention requires
4647
"intermediate_size": 32,
4748
# LFM2 interleaves short convolution layers with full attention layers. The reference spells the pattern out with
4849
# `layer_types` rather than `full_attn_idxs`; keep one of each so both layer types are exercised.
@@ -51,7 +52,7 @@
5152
vision_config = {
5253
"num_hidden_layers": 2,
5354
"hidden_size": 16,
54-
"num_attention_heads": 4,
55+
"num_attention_heads": 2, # head size 16 // 2 = 8, as Flash Attention requires
5556
"intermediate_size": 32,
5657
}
5758

‎tests/test_sft_trainer.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,14 @@ def test_train_vlm(self, model_id):
24082408
Version(transformers.__version__) < Version("5.0.0"),
24092409
reason="LFM2.5-VL requires transformers>=5.0.0",
24102410
),
2411-
_HEAD_SIZE_NOT_MULTIPLE_OF_8,
2411+
# transformers main has the SigLIP2 fix (#8504), but no release has it yet: strict, so a release with the
2412+
# fix fails loudly
2413+
pytest.mark.xfail(
2414+
Version("5.24.0") <= Version(transformers.__version__) < Version("5.25.0")
2415+
and not Version(transformers.__version__).is_devrelease,
2416+
reason="transformers 5.24 refuses Flash Attention kernels for the SigLIP2 vision tower (see #8504)",
2417+
strict=True,
2418+
),
24122419
],
24132420
),
24142421
pytest.param(

‎tests/testing_utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"trl-internal-testing/tiny-Lfm2ForCausalLM": "a8b729ddf80657a21272c71d36a7edc2be1bf6b4",
9292
"trl-internal-testing/tiny-Lfm2ForCausalLM-2.5": "1e9ac722a12cea565443504973060b960a328c37",
9393
"trl-internal-testing/tiny-Lfm2MoeForCausalLM-2.5": "af6b0e20385279de1530104e215a3a2f5155d182",
94-
"trl-internal-testing/tiny-Lfm2VlForConditionalGeneration-2.5": "754269127308ed7bdaa584630abc702e368337ad",
94+
"trl-internal-testing/tiny-Lfm2VlForConditionalGeneration-2.5": "8fc8355b6992a35fdfdfde474e12023469624292",
9595
"trl-internal-testing/tiny-LlamaForCausalLM-3": "fed7bca1617c3a3835860260e81aa387e7afe07d",
9696
"trl-internal-testing/tiny-LlamaForCausalLM-3.1": "c234f265b635252535f848a9609c50852614ac84",
9797
"trl-internal-testing/tiny-LlamaForCausalLM-3.2": "ca56c655e3da5ec96243a4b470faf767a3085783",

0 commit comments

Comments
 (0)