Repository navigation
[Model] Refactor modernbert with the attention interface - #43030
Conversation
|
Hey @vasqu , could you please review it again? Thank you very much! |
|
Nice thx a lot @YangKai0616, I'll take a look tomorrow, just coming back from the holidays 🤗 |
There was a problem hiding this comment.
Much needed! I left some comments, especially the masking can be further improved along possibly adding check_model_inputs decorator with the usage of **kwargs.
Lmk if I can help out there, the masking is pretty core so it might be a bit too much
|
Hey @vasqu, I've updated the code based on your comments and removed the unrelated UT changes. Please take another look. Thanks! |
vasqu
left a comment
There was a problem hiding this comment.
We are getting there :D another round, these are less critical IMO - the general direction is already pretty good
|
I’ve modified the code according to your suggestions. I’ll find some time tomorrow to test the related unit tests. If everything looks good, we can continue with the review. Thank you for your patience! |
|
@YangKai0616 just ping me again when you think it's ready for another review 🫡 |
|
The CI error seems unrelated to this PR. I was able to test it successfully on my local CUDA and XPU. @vasqu let's review it again, thank you ! |
|
View the CircleCI Test Summary for this PR: |
|
Hello! This is an extremely impressive PR, wow. The structure of the modeling/modular files look very strong as a result of all of this. I ran some downstream tests using Sentence Transformers with https://huggingface.co/nomic-ai/modernbert-embed-base, and there are some very slight differences in scores: When I implemented this architecture, these forms of slight differences also existed between e.g. eager/sdpa/fa2, and it's extremely hard to narrow down the source (and from experience: often enough even with the source known, it's not possible to do anything about it). The old implementation automatically 'unpadded' and 'repadded' during inference. I take it this variant doesn't do that? You write about a Also, this might be an issue on my side, but I wasn't able to get In short: you've done some real magic here, and it's (at the least) very similar in accuracy, albeit likely quite a bit slower due to not forcing the unpadding/repadding (iiuc). However, that was never very
|
Pretty much any model that supports attention backend should be able to do this. I refactored Bert for exactly the same reason for example (vLLM needs this as well). Transformers was never meant to manually pad/unpad during the forward, that's what the collator is for and is recommended for causal models like llama for quite a while now - this enables complete compile compatibility with FA. Some side note: we manually pad/unpad ourselves already in FA (given a non all true attention mask)
Should be fast when properly preparing the data :D
Can you share a script and env? The example works on my end (FA), also check SDPA with non fullgraph. Note
|
I see, I might've gone wrong there. I'll run more tests later. I was testing with Sentence Transformers, which doesn't use the collator.
|
|
Hi everyone, any updates? 😀 |
ArthurZucker
left a comment
There was a problem hiding this comment.
@YangKai0616 great great PR! 🤗
Really aligned with the philosophy and is a clear simplification! Kudos
Thanks @vasqu for the thorough review.
Only 1 nit on sliding window settings based off layer_types if possible but otherwise LGTM
There was a problem hiding this comment.
great new integration test, I don't think we still need the other custom tests as now the code is quite standard (like disk offload)
|
[For maintainers] Suggested jobs to run (before merge) run-slow: modernbert, modernbert_decoder, pe_video |
Co-authored-by: Arthur <[email protected]>
|
[For maintainers] Suggested jobs to run (before merge) run-slow: modernbert, modernbert_decoder, pe_video |
|
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. |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: modernbert, modernbert_decoder, pe_video |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: modernbert, modernbert_decoder, pe_video |
|
run-slow: modernbert, modernbert_decoder |
|
This comment contains models: ["models/modernbert", "models/modernbert_decoder"] |
CI Results✅ No failing test specific to this PR 🎉 ! |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: modernbert, modernbert_decoder, pe_video |
|
Green CI, no regression, huge work @YangKai0616! Thanks a lot for this PR and iterating time and time again ❤️ it will be merged after the docs are built |
What does this PR do?
This PR:
ModernBERT's Flash Attentionimplementation using the built-in interfaces fromTransformers.tests/models/modernbert/test_modeling_modernbert.pyandtests/models/pe_video/test_modeling_pe_video.pytest files.Background PR: #42952.