Repository navigation
🚨 Modify ModernBERT's default attention implementation to stop using FA - #43764
Conversation
| logits_audio_text = logits_audio_text * self.text_audio_logit_scale.to( | ||
| logits_audio_text.device | ||
| ) + self.text_audio_logit_bias.to(logits_audio_text.device) | ||
|
|
There was a problem hiding this comment.
Fix this because the test tests/models/pe_audio/test_modeling_pe_audio.py::PeAudioModelTest::test_model_parallelism will report error RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0!.
vasqu
left a comment
There was a problem hiding this comment.
Much better, can you add 🚨 to the title since it is breaking (in a good way)
|
Also check modern_bert decoder, it inherited from modernbert (should be a simple removal of the function there in modular) + should we add a small note in the docs / update them for the padding free example |
| with torch.no_grad(): | ||
| output = model(**inputs)[0] | ||
| expected_shape = torch.Size((1, 6, model.config.vocab_size)) | ||
| expected_shape = torch.Size((1, 7, model.config.vocab_size)) |
There was a problem hiding this comment.
The current version of the tokens output template has add_eos_token=True, and the actual output here is: ['[CLS]', 'Paris', ' is', ' the', ' capital', ' of', '[SEP]']. Therefore, expected_shape needs to be modified.
|
[For maintainers] Suggested jobs to run (before merge) run-slow: modernbert, modernbert_decoder, pe_audio, pe_video |
Done. |
It seems I don’t have permission to edit the title. The |
vasqu
left a comment
There was a problem hiding this comment.
Perfect, it's an important step imo. It already started to grow on a few models so this was going to be a nightmare (maintenance-wise)
No idea why you can't modify the title 😭 I just did, no worries
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
…FA (huggingface#43764) * Modify ModernBERT's default attention implementation to stop using FA * Style * Revised based on comments * Update doc
…the rebuild Skipping `update_post_processor()` whenever `tokenizer.json` ships a post-processor makes the call added by #47988 dead code -- the base class already updates the post-processor in exactly those cases (`_should_update_post_processor`, `tokenization_utils_tokenizers.py`) -- so it reintroduces the OLMo bug. Verified on `allenai/OLMo-7B-hf`: with that patch every input gets `<|endoftext|>` appended again. The actual root cause is that `_from_pretrained` drops `add_bos_token`/`add_eos_token` from the init kwargs when a `tokenizer.json` is present, so #47988 rebuilds the post-processor from flags that have just been erased. The result is "no bos, no eos" for every GPTNeoX checkpoint: correct for OLMo (which saves `false`/`false`), wrong for any checkpoint whose post-processor adds special tokens -- `blab-jhu/test-32m-dec` went from `[CLS] Paris is the capital of` to `Paris is the capital of`. Keep the flags for the tokenizers whose class opts in, and let the base class rebuild the post-processor from them. This restores the pre-#42563 behaviour on both checkpoints (verified locally): - `allenai/OLMo-7B-hf` (`add_bos_token=false`, `add_eos_token=false`): no EOS appended. - `blab-jhu/test-32m-dec` (`add_bos_token=true`): `[CLS] Paris is the capital of`, i.e. 6 tokens. The trailing `[SEP]` its `tokenizer.json` adds is the same pathology as OLMo's EOS on a causal LM, and 6 was the expected value from #38967 until #43764 bumped it to 7 as collateral of the tokenizer refactor. The expected logit slices are unchanged, as only the trailing token disappears. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Background: PR #43672
This PR modifies the default attention implementation in
modernbert, switching away fromFlashAttention. It also restores the related tests that were previously overridden.@vasqu , please help review again, thank you very much!